Skip to content

Commit

Permalink
Added bool flag to Browser.ScrollIntoView method to be able to contro…
Browse files Browse the repository at this point in the history
…l its behavior ScrollIntoView vs ScrollIntoViewIfNeeded
  • Loading branch information
CosminSontu committed Nov 17, 2023
1 parent f951be4 commit 101975c
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 87 deletions.
2 changes: 1 addition & 1 deletion SpecDrill.Infrastructure/SpecDrill.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>specdrill.png</PackageIcon>
<BuildNumber>537</BuildNumber>
<BuildNumber>551</BuildNumber>
<Version>1.3.0.$(BuildNumber)</Version>
<Description>SpecDrill.Infrastructure</Description>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Expand Down
4 changes: 2 additions & 2 deletions SpecDrill.MsTest/SpecDrill.MsTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>specdrill.png</PackageIcon>
<BuildNumber>1135</BuildNumber>
<BuildNumber>1157</BuildNumber>
<Version>1.3.0.$(BuildNumber)</Version>
<Description>SpecDrill.MsTest - SpecDrill integration with MsTest </Description>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Expand All @@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="SpecDrill" Version="1.3.0.1231" />
<PackageReference Include="SpecDrill" Version="1.3.0.1279" />
<PackageReference Include="SpecDrill.Secondary.Adapters.WebDriver" Version="[1.3.*,)" />
<None Include="..\LICENSE" Pack="true" PackagePath=".\" />
<None Include="..\specdrill.png" Pack="true" PackagePath=".\" />
Expand Down
4 changes: 2 additions & 2 deletions SpecDrill.NUnit3/SpecDrill.NUnit3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>specdrill.png</PackageIcon>
<BuildNumber>863</BuildNumber>
<BuildNumber>876</BuildNumber>
<Version>1.3.0.$(BuildNumber)</Version>
<Description>SpecDrill.NUnit - SpecDrill integration with NUnit 3</Description>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Expand All @@ -16,7 +16,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="SpecDrill" Version="1.3.0.1231" />
<PackageReference Include="SpecDrill" Version="1.3.0.1279" />
<PackageReference Include="SpecDrill.Secondary.Adapters.WebDriver" Version="[1.3.*,)" />
<None Include="..\LICENSE" Pack="true" PackagePath=".\" />
<None Include="..\specdrill.png" Pack="true" PackagePath=".\" />
Expand Down
4 changes: 2 additions & 2 deletions SpecDrill.Samples.MsTest/SpecDrill.Samples.MsTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="117.0.5938.8800" />
<PackageReference Include="SpecDrill" Version="1.3.0.1231" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="119.0.6045.10500" />
<PackageReference Include="SpecDrill" Version="1.3.0.1279" />
<PackageReference Include="SpecDrill.MsTest" Version="[1.3.*,)" />
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions SpecDrill.Samples.NUnit/SpecDrill.Samples.NUnit3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Allure.NUnit" Version="2.9.5-preview.1" />
<PackageReference Include="Allure.NUnit" Version="2.10.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="117.0.5938.8800" />
<PackageReference Include="SpecDrill" Version="1.3.0.1231" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="119.0.6045.10500" />
<PackageReference Include="SpecDrill" Version="1.3.0.1279" />
<PackageReference Include="SpecDrill.NUnit3" Version="1.3.0.852" />
<PackageReference Include="SpecDrill.SpecFlow" Version="1.3.0.947" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ public void ClickJs(IElement element)

}

public void ScrollIntoView(IElement element)
public void ScrollIntoView(IElement element, bool ifNeeded = true)
{
this.ExecuteJavaScript($"arguments[0].scrollIntoViewIfNeeded();", element.ToWebElement());
this.ExecuteJavaScript(ifNeeded ?
$"arguments[0].scrollIntoViewIfNeeded();" :
$"arguments[0].scrollIntoView();", element.ToWebElement());
}

public double? ScrollDivVertically(IElement divElement, int deltaPixels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>specdrill.png</PackageIcon>
<BuildNumber>1302</BuildNumber>
<BuildNumber>1327</BuildNumber>
<Version>1.3.0.$(BuildNumber)</Version>
<Deterministic>true</Deterministic>
<Description>SpecDrill.SecondaryPorts.Adapters.WebDriver - WebDriver adapter for SpecDrill</Description>
Expand All @@ -22,7 +22,7 @@
<PackageReference Include="Appium.WebDriver" Version="4.4.5" />
<PackageReference Include="Selenium.Support" Version="4.12.4" />
<PackageReference Include="Selenium.WebDriver" Version="4.12.4" />
<PackageReference Include="SpecDrill" Version="1.3.0.1231" />
<PackageReference Include="SpecDrill" Version="1.3.0.1279" />
<PackageReference Include="SpecDrill.Infrastructure" Version="1.3.0.526" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageReference Include="itext7" Version="8.0.1" />
Expand Down
4 changes: 2 additions & 2 deletions SpecDrill.SpecFlow/SpecDrill.SpecFlow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>specdrill.png</PackageIcon>
<BuildNumber>958</BuildNumber>
<BuildNumber>971</BuildNumber>
<Version>1.3.0.$(BuildNumber)</Version>
<Description>SpecDrill.SpecFlow - SpecDrill integration with SpecFlow </Description>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Expand All @@ -15,7 +15,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="SpecDrill" Version="1.3.0.1231" />
<PackageReference Include="SpecDrill" Version="1.3.0.1279" />
<PackageReference Include="SpecDrill.Secondary.Adapters.WebDriver" Version="[1.3.*,)" />
<PackageReference Include="SpecFlow" Version="3.9.74" IncludeAssets="All" />
<None Include="..\LICENSE" Pack="true" PackagePath=".\" />
Expand Down
30 changes: 15 additions & 15 deletions SpecDrill.Tests/CreatingPomClassesAtRuntimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public void ShouldHaveWikipediaAmongResultsOnGoogleSearch()
Page("GoogleSearch", null,
Element("button", "BtnAccept", new PomLocator("id", "L2AGLb")),
Element("input", "TxtSearch", new PomLocator("xpath", "//input[@name='q'] | //*[@id=\"APjFqb\"]")),
Element("button", "BtnSearch", new PomLocator("xpath", "//div[contains(@class,'FPdoLc')]//input[@name='btnK']"), new PomTarget("page", "GoogleSearchResults", "click")
))
Element("button", "BtnSearch", new PomLocator("xpath", "//div[contains(@class,'FPdoLc')]//input[@name='btnK']"), "GoogleSearchResults")
)
);
// write json in random form
//var jsonInput = File.ReadAllText("C:\\_apps\\sitemap.json");
Expand Down Expand Up @@ -99,11 +99,11 @@ public void ShouldHaveWikipediaAmongResultsOnGoogleSearch()

Assert.IsNotNull(results);

foreach (var r in results)
{
var lnk = ((IElement?)searchResultItemType.GetProperty("Link")?.GetValue(r))?.Text;
//var descr = ((IElement?)searchResultItemType.GetProperty("Description")?.GetValue(r))?.Text;
}
//foreach (var r in results)
//{
// var lnk = ((IElement?)searchResultItemType.GetProperty("Link")?.GetValue(r))?.Text;
// //var descr = ((IElement?)searchResultItemType.GetProperty("Description")?.GetValue(r))?.Text;
//}
var found = results?
.FirstOrDefault(r => r.Property<Element>(searchResultItemType, "Link")?.Text.Contains("Drill") ?? false) != default;

Expand Down Expand Up @@ -150,7 +150,7 @@ public void GetDeclarationOrderBasedOnDependencies()
Page("GoogleSearch", null,
Element("button", "BtnAccept", new PomLocator("id", "L2AGLb")),
Element("input", "TxtSearch", new PomLocator("xpath", "//input[@name='q'] | //*[@id=\"APjFqb\"]")),
Element("button", "BtnSearch", new PomLocator("xpath", "//div[contains(@class,'FPdoLc')]//input[@name='btnK']"), new PomTarget("page", "GoogleSearchResults", "click")
Element("button", "BtnSearch", new PomLocator("xpath", "//div[contains(@class,'FPdoLc')]//input[@name='btnK']"), "GoogleSearchResults"
))
);
// process sitemap elements
Expand All @@ -170,7 +170,7 @@ public void MoreComplexSitemapDefinition_DeclarationOrderTest_ShouldPass()
.AddComponents(
Component("PersonResultItem", null,
Element("label", "PersonLabel", new PomLocator("xpath", "./span/div[1]//label")),
Element("button", "PersonItem", new PomLocator("xpath", "."), new PomTarget("page", "PersonDetailsPage", "click"))
Element("button", "PersonItem", new PomLocator("xpath", "."), "PersonDetailsPage")
)
)
.AddPages(
Expand All @@ -184,23 +184,23 @@ public void MoreComplexSitemapDefinition_DeclarationOrderTest_ShouldPass()
),
Page("PortalSelectionPage", null,
Element("label", "Header", new PomLocator("xpath", "//*[@id=\"app-section-header_1\"]")),
Element("button", "TileEwa", new PomLocator("xpath", """//*[@id="AppModuleTileSec_1_Item_2"]"""), new PomTarget(type: "page", "EwaHomePage", "click"))
Element("button", "TileEwa", new PomLocator("xpath", """//*[@id="AppModuleTileSec_1_Item_2"]"""), "EwaHomePage")
),
Page("CrmLandingPage", null,
Element("label", "TopBar", new PomLocator("xpath", "//*[@id=\"topBar\"]")),
Element("frame", "PortalSelectionFrame", new PomLocator("xpath", """//*[@id="AppLandingPage"]"""), new PomTarget("page", "PortalSelectionPage","click"))
Element("frame", "PortalSelectionFrame", new PomLocator("xpath", """//*[@id="AppLandingPage"]"""), "PortalSelectionPage")
),
Page("StaySignedInPage", null,
Element("input", "LblStaySignedIn", new PomLocator("xpath", "/html//div[@id='lightbox']/div[@role='main']//div[@role='heading']")),
Element("button", "BtnYes", new PomLocator("xpath", "/html//input[@id='idSIButton9']"), new PomTarget("page", "CrmLandingPage", "click"))
Element("button", "BtnYes", new PomLocator("xpath", "/html//input[@id='idSIButton9']"), "CrmLandingPage")
),
Page("Login2Page", null,
Element("input", "TxtPassword", new PomLocator("xpath", "/html//div[@id='lightbox']/div[@role='main']/div/div[2]/div//input[@name='passwd']")),
Element("button", "BtnSignIn", new PomLocator("xpath", "/html//input[@id='idSIButton9']"), new PomTarget("page", "StaySignedInPage", "click"))
Element("button", "BtnSignIn", new PomLocator("xpath", "/html//input[@id='idSIButton9']"), "StaySignedInPage")
),
Page("Login1Page", null,
Element("button", "BtnAccept", new PomLocator("id", "L2AGLb")), Element("input", "TxtUsername", new PomLocator("xpath", "/html//div[@id='lightbox']/div[@role='main']/div/div/div//input[@name='loginfmt']")),
Element("button", "BtnNext", new PomLocator("xpath", "/html//input[@id='idSIButton9']"), new PomTarget("page", "Login2Page", "click"))
Element("button", "BtnNext", new PomLocator("xpath", "/html//input[@id='idSIButton9']"), "Login2Page")
)
);

Expand All @@ -210,7 +210,7 @@ public void MoreComplexSitemapDefinition_DeclarationOrderTest_ShouldPass()
pomSiteMap.components.Count.Should().Be(1);
pomSiteMap.pages.Count.Should().Be(7);
}
private (string type, string? itemType, PomTarget? target) ToSpecDrillType(string type, string? itemType, PomTarget? target)
private (string type, string? itemType, string? target) ToSpecDrillType(string type, string? itemType, string? target)
=> (type.ToLowerInvariant(), itemType, target) switch
{
("button", null, null) => ("element", null, null),
Expand Down
2 changes: 1 addition & 1 deletion SpecDrill.Tests/SpecDrill.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<PackageReference Include="NReco.Logging.File" Version="1.1.6" />
<!--<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />-->
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="117.0.5938.8800" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="119.0.6045.10500" />
<!--<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="109.0.1518.61" />-->
<!--<PackageReference Include="SpecDrill.MsTest" Version="[1.1.15.*,)" />
<PackageReference Include="SpecDrill.SpecFlow" Version="[1.1.14.*,)" />-->
Expand Down
2 changes: 1 addition & 1 deletion SpecDrill.Tests/specDrillConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"seleniumServerUri": "http://localhost:5555/wd/hub",
"drivers": {
"chrome": {
"path": "%USERPROFILE%\\.nuget\\packages\\selenium.webdriver.chromedriver\\117.0.5938.8800\\driver\\win32",
"path": "%USERPROFILE%\\.nuget\\packages\\selenium.webdriver.chromedriver\\119.0.6045.10500\\driver\\win32",
"arguments": [
//"headless",
"--disable-extensions",
Expand Down
2 changes: 1 addition & 1 deletion SpecDrill/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void IBrowser.SwitchToWindow<T>(IWindowElement<T> seleniumWindowElement)
browserDriver.SwitchToWindow(seleniumWindowElement);
}

public void ScrollIntoView(IElement element) => browserDriver.ScrollIntoView(element);
public void ScrollIntoView(IElement element, bool ifNeeded = true) => browserDriver.ScrollIntoView(element, ifNeeded);

public void CloseLastWindow()
{
Expand Down
Loading

0 comments on commit 101975c

Please sign in to comment.