Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of issue #17 - BrowserWrapper.CurrentUrlPart returns only part af… #19

Merged
merged 2 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/Riganti.Selenium.Core/BrowserWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
/// <summary>
/// Gives path of url of active browser tab.
/// </summary>
public string CurrentUrlPath => new Uri(CurrentUrl).GetLeftPart(UriPartial.Path);
public string CurrentUrlPath => new Uri(CurrentUrl).GetComponents(UriComponents.PathAndQuery | UriComponents.Fragment & ~UriComponents.HostAndPort, UriFormat.UriEscaped);
quigamdev marked this conversation as resolved.
Show resolved Hide resolved



Expand Down Expand Up @@ -592,7 +592,7 @@
var now = DateTime.UtcNow;

bool isConditionMet = false;
Exception ex = null;

Check warning on line 595 in src/Core/Riganti.Selenium.Core/BrowserWrapper.cs

View workflow job for this annotation

GitHub Actions / UI tests (firefox, ubuntu-latest)

The variable 'ex' is assigned but its value is never used

Check warning on line 595 in src/Core/Riganti.Selenium.Core/BrowserWrapper.cs

View workflow job for this annotation

GitHub Actions / UI tests (chrome, ubuntu-latest)

The variable 'ex' is assigned but its value is never used

Check warning on line 595 in src/Core/Riganti.Selenium.Core/BrowserWrapper.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The variable 'ex' is assigned but its value is never used
do
{
try
Expand Down
37 changes: 37 additions & 0 deletions src/Tests/Riganti.Selenium.Core.UnitTests/BrowserWrapperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using Riganti.Selenium.Core.UnitTests.Mock;
using Selenium.Core.UnitTests;

namespace Riganti.Selenium.Core.UnitTests;

[TestClass]
public class BrowserWrapperTests : MockingTest
{
public TestContext TestContext { get; set; }

[TestMethod]
public void CurrentUrlPath_NoEscapedCharactersTest()
{
var driverMock = new MockIWebDriver
{
FindElementsAction = () => new List<IWebElement>() { new MockIWebElement() { TagName = "a" } },
Url = "https://localhost:12345/path1/path2?query=1#fragment"
};
var browser = CreateMockedIBrowserWrapper(driverMock);
Assert.AreEqual("/path1/path2?query=1#fragment", browser.CurrentUrlPath);
}

[TestMethod]
public void CurrentUrlPath_WithEscapedCharatersTest()
{
var driverMock = new MockIWebDriver
{
FindElementsAction = () => new List<IWebElement>() { new MockIWebElement() { TagName = "a" } },
Url = "https://localhost:12345/path1/path2%20second%20part?query=1#fragment"
};
var browser = CreateMockedIBrowserWrapper(driverMock);
Assert.AreEqual("/path1/path2%20second%20part?query=1#fragment", browser.CurrentUrlPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
namespace Riganti.Selenium.Core.UnitTests;

[TestClass]
public class SeleniumManagerTests
Expand Down
Loading