Skip to content

Commit

Permalink
Merge pull request #19 from riganti/bugfix-issue-17
Browse files Browse the repository at this point in the history
Fix of issue #17 - BrowserWrapper.CurrentUrlPart returns only part af…
  • Loading branch information
quigamdev authored Sep 7, 2024
2 parents 1f8bd36 + 1be2593 commit 680fa34
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
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 @@ public void SetCssSelector()
/// <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, UriFormat.UriEscaped);



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

0 comments on commit 680fa34

Please sign in to comment.