From 650fc55f8590739fd16577216a6a2a3a6d124d53 Mon Sep 17 00:00:00 2001 From: Cosmin Sontu Date: Wed, 13 Mar 2024 21:23:01 +0200 Subject: [PATCH] Fixed Issue #23: Speedup Search in List Element --- .../SpecDrill.Infrastructure.csproj | 12 ++++++------ SpecDrill.MsTest/SpecDrill.MsTest.csproj | 14 +++++++------- SpecDrill.NUnit3/SpecDrill.NUnit3.csproj | 14 +++++++------- .../SpecDrill.Samples.MsTest.csproj | 16 ++++++++-------- .../Features/GoogleSearch.feature | 2 +- .../Features/GoogleSearch.feature.cs | 2 +- .../SpecDrill.Samples.NUnit3.csproj | 16 ++++++++-------- SpecDrill.Samples.NUnit/specDrillConfig.json | 2 +- ...cDrill.Secondary.Adapters.WebDriver.csproj | 18 +++++++++--------- SpecDrill.SpecFlow/SpecDrill.SpecFlow.csproj | 12 ++++++------ SpecDrill.Tests/SpecDrill.Tests.csproj | 18 +++++++++--------- SpecDrill/SpecDrill.csproj | 10 +++++----- SpecDrill/WebControls/ListElement.cs | 19 ++++++++++++++----- 13 files changed, 82 insertions(+), 73 deletions(-) diff --git a/SpecDrill.Infrastructure/SpecDrill.Infrastructure.csproj b/SpecDrill.Infrastructure/SpecDrill.Infrastructure.csproj index 0f41a77..cafe72e 100644 --- a/SpecDrill.Infrastructure/SpecDrill.Infrastructure.csproj +++ b/SpecDrill.Infrastructure/SpecDrill.Infrastructure.csproj @@ -1,11 +1,11 @@ - + - net7.0 + net8.0 enable LICENSE specdrill.png - 554 - 1.3.0.$(BuildNumber) + 4 + 1.4.0.$(BuildNumber) SpecDrill.Infrastructure PackageReference @@ -20,8 +20,8 @@ - - + + diff --git a/SpecDrill.MsTest/SpecDrill.MsTest.csproj b/SpecDrill.MsTest/SpecDrill.MsTest.csproj index ea2edc2..3cce58b 100644 --- a/SpecDrill.MsTest/SpecDrill.MsTest.csproj +++ b/SpecDrill.MsTest/SpecDrill.MsTest.csproj @@ -1,12 +1,12 @@ - + $(RestoreSources) - net7.0 + net8.0 enable LICENSE specdrill.png - 1160 - 1.3.0.$(BuildNumber) + 4 + 1.4.0.$(BuildNumber) SpecDrill.MsTest - SpecDrill integration with MsTest PackageReference @@ -15,9 +15,9 @@ - - - + + + diff --git a/SpecDrill.NUnit3/SpecDrill.NUnit3.csproj b/SpecDrill.NUnit3/SpecDrill.NUnit3.csproj index 133045b..5cc1060 100644 --- a/SpecDrill.NUnit3/SpecDrill.NUnit3.csproj +++ b/SpecDrill.NUnit3/SpecDrill.NUnit3.csproj @@ -1,12 +1,12 @@ - + $(RestoreSources) - net7.0 + net8.0 enable LICENSE specdrill.png - 879 - 1.3.0.$(BuildNumber) + 4 + 1.4.0.$(BuildNumber) SpecDrill.NUnit - SpecDrill integration with NUnit 3 PackageReference Library @@ -15,9 +15,9 @@ - - - + + + diff --git a/SpecDrill.Samples.MsTest/SpecDrill.Samples.MsTest.csproj b/SpecDrill.Samples.MsTest/SpecDrill.Samples.MsTest.csproj index a96f933..a65a8ed 100644 --- a/SpecDrill.Samples.MsTest/SpecDrill.Samples.MsTest.csproj +++ b/SpecDrill.Samples.MsTest/SpecDrill.Samples.MsTest.csproj @@ -2,23 +2,23 @@ $(RestoreSources) - net7.0 + net8.0 false - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/SpecDrill.Samples.NUnit/Features/GoogleSearch.feature b/SpecDrill.Samples.NUnit/Features/GoogleSearch.feature index 3e5b2c7..6248584 100644 --- a/SpecDrill.Samples.NUnit/Features/GoogleSearch.feature +++ b/SpecDrill.Samples.NUnit/Features/GoogleSearch.feature @@ -13,4 +13,4 @@ Scenario: 1.Find wiki entry for searched keyword Scenario: 2.Find wiki entry for searched keyword Given I have entered "drill wiki" into Google search When I press Search button - Then You should get a "Drill" entry in search results + Then You should get a "Fandom" entry in search results diff --git a/SpecDrill.Samples.NUnit/Features/GoogleSearch.feature.cs b/SpecDrill.Samples.NUnit/Features/GoogleSearch.feature.cs index 4718483..9536759 100644 --- a/SpecDrill.Samples.NUnit/Features/GoogleSearch.feature.cs +++ b/SpecDrill.Samples.NUnit/Features/GoogleSearch.feature.cs @@ -132,7 +132,7 @@ public void _2_FindWikiEntryForSearchedKeyword() testRunner.When("I press Search button", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); #line hidden #line 16 - testRunner.Then("You should get a \"Drill\" entry in search results", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); + testRunner.Then("You should get a \"Fandom\" entry in search results", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden } this.ScenarioCleanup(); diff --git a/SpecDrill.Samples.NUnit/SpecDrill.Samples.NUnit3.csproj b/SpecDrill.Samples.NUnit/SpecDrill.Samples.NUnit3.csproj index d4627c1..9c826d5 100644 --- a/SpecDrill.Samples.NUnit/SpecDrill.Samples.NUnit3.csproj +++ b/SpecDrill.Samples.NUnit/SpecDrill.Samples.NUnit3.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 false @@ -11,15 +11,15 @@ - + - - + + - - - - + + + + diff --git a/SpecDrill.Samples.NUnit/specDrillConfig.json b/SpecDrill.Samples.NUnit/specDrillConfig.json index 7edff29..062dd2f 100644 --- a/SpecDrill.Samples.NUnit/specDrillConfig.json +++ b/SpecDrill.Samples.NUnit/specDrillConfig.json @@ -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", //"C:\\Your Browser Drivers Path"// + "path": "%USERPROFILE%\\.nuget\\packages\\selenium.webdriver.chromedriver\\122.0.6261.11100\\driver\\win32", //"C:\\Your Browser Drivers Path"// "arguments": [ "--incognito" ] //add , "headless" for headless test run }, "ie": { "path": "" }, diff --git a/SpecDrill.Secondary.Adapters.WebDriver/SpecDrill.Secondary.Adapters.WebDriver.csproj b/SpecDrill.Secondary.Adapters.WebDriver/SpecDrill.Secondary.Adapters.WebDriver.csproj index 38ac122..04b8bfa 100644 --- a/SpecDrill.Secondary.Adapters.WebDriver/SpecDrill.Secondary.Adapters.WebDriver.csproj +++ b/SpecDrill.Secondary.Adapters.WebDriver/SpecDrill.Secondary.Adapters.WebDriver.csproj @@ -1,12 +1,12 @@ - + $(RestoreSources) - net7.0 + net8.0 enable LICENSE specdrill.png - 1330 - 1.3.0.$(BuildNumber) + 4 + 1.4.0.$(BuildNumber) true SpecDrill.SecondaryPorts.Adapters.WebDriver - WebDriver adapter for SpecDrill PackageReference @@ -20,12 +20,12 @@ - - - - + + + + - + 2 diff --git a/SpecDrill.SpecFlow/SpecDrill.SpecFlow.csproj b/SpecDrill.SpecFlow/SpecDrill.SpecFlow.csproj index 7e92970..82fe11f 100644 --- a/SpecDrill.SpecFlow/SpecDrill.SpecFlow.csproj +++ b/SpecDrill.SpecFlow/SpecDrill.SpecFlow.csproj @@ -1,12 +1,12 @@ - + $(RestoreSources) - net7.0 + net8.0 enable LICENSE specdrill.png - 974 - 1.3.0.$(BuildNumber) + 4 + 1.4.0.$(BuildNumber) SpecDrill.SpecFlow - SpecDrill integration with SpecFlow PackageReference @@ -15,8 +15,8 @@ - - + + diff --git a/SpecDrill.Tests/SpecDrill.Tests.csproj b/SpecDrill.Tests/SpecDrill.Tests.csproj index 3618add..1da29d7 100644 --- a/SpecDrill.Tests/SpecDrill.Tests.csproj +++ b/SpecDrill.Tests/SpecDrill.Tests.csproj @@ -2,7 +2,7 @@ $(RestoreSources) - net7.0 + net8.0 false enable @@ -34,29 +34,29 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - + - + diff --git a/SpecDrill/SpecDrill.csproj b/SpecDrill/SpecDrill.csproj index fa0fc06..2403afc 100644 --- a/SpecDrill/SpecDrill.csproj +++ b/SpecDrill/SpecDrill.csproj @@ -1,13 +1,13 @@ - + $(RestoreSources) bin\$(Configuration)\Package - net7.0 + net8.0 enable LICENSE specdrill.png - 1291 - 1.3.0.$(BuildNumber) + 4 + 1.4.0.$(BuildNumber) SpecDrill - An opinionated automated testing framework based on Selenium WebDriver PackageReference @@ -24,7 +24,7 @@ - + diff --git a/SpecDrill/WebControls/ListElement.cs b/SpecDrill/WebControls/ListElement.cs index 0eb0163..7186a1d 100644 --- a/SpecDrill/WebControls/ListElement.cs +++ b/SpecDrill/WebControls/ListElement.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text.RegularExpressions; namespace SpecDrill @@ -50,11 +51,19 @@ public T GetElementByIndex(int index) public T GetElementByText(string regex) { - var elements = this.ToArray(); - var match = elements.FirstOrDefault( - item => - Regex.IsMatch(item.Text, regex, RegexOptions.None, TimeSpan.FromSeconds(30)) - ); + T? match; + if (this.locator.LocatorType == By.XPath) + { + match = ElementFactory.CreateControl(parent, ElementLocatorFactory.Create(By.XPath, locator.LocatorValue + $"[.//text()[contains(.,'{regex}')]]")); + } + else + { + var elements = this.ToArray(); + match = elements.FirstOrDefault( + item => + Regex.IsMatch(item.Text, regex, RegexOptions.None, TimeSpan.FromSeconds(30)) + ); + } if (match == default(T)) throw new Exception($"SpecDrill: No element matching '{regex}' was found!");