From e22cf55dd35b1fa0a31c9059a993ba23c59773b9 Mon Sep 17 00:00:00 2001 From: Andrei Pavar Date: Sat, 2 Jul 2022 13:42:48 +0300 Subject: [PATCH 01/12] Add RelativeBy class --- .../Aquality.Selenium/Locators/RelativeBy.cs | 55 +++++++++++ .../Integration/RelativeLocatorsTests.cs | 93 +++++++++++++++++++ .../TheInternet/Forms/ChallengingDomForm.cs | 39 ++++++++ 3 files changed, 187 insertions(+) create mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs new file mode 100644 index 00000000..84386a25 --- /dev/null +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs @@ -0,0 +1,55 @@ +using OpenQA.Selenium; +using RelativeSeleniumBy = OpenQA.Selenium.RelativeBy; +using CoreElement = Aquality.Selenium.Core.Elements.Element; +using Aquality.Selenium.Core.Elements.Interfaces; +using System.Collections.ObjectModel; +using System; + +namespace Aquality.Selenium.Locators +{ + public class RelativeBy : By + { + private By by; + + private RelativeBy(By by) + { + this.by = by; + } + + public static RelativeBy WithLocator(By by) + { + return new RelativeBy(by); + } + + public RelativeBy Above(By by) + { + this.by = RelativeSeleniumBy.WithLocator(this.by).Above(by); + return new RelativeBy(this.by); + } + + public RelativeBy Above(WebElement webElement) + { + by = RelativeSeleniumBy.WithLocator(by).Above(webElement); + return new RelativeBy(by); + } + + public RelativeBy Above(IElement element) + { + by = RelativeSeleniumBy.WithLocator(by).Above(element.Locator); + return new RelativeBy(by); + } + + public override IWebElement FindElement(ISearchContext context) + { + Console.WriteLine(by.ToString()); + return ((RelativeSeleniumBy)by).FindElement(context); + } + + public override ReadOnlyCollection FindElements(ISearchContext context) + { + return ((RelativeSeleniumBy)by).FindElements(context); + } + + + } +} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs new file mode 100644 index 00000000..429d4f05 --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs @@ -0,0 +1,93 @@ +using Aquality.Selenium.Browsers; +using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms; +using NUnit.Framework; +using Aquality.Selenium.Elements.Interfaces; +using RelativeSeleniumBy = OpenQA.Selenium.RelativeBy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +using Aquality.Selenium.Locators; +using By = OpenQA.Selenium.By; + +using Aquality.Selenium.Core.Elements; + +namespace Aquality.Selenium.Tests.Integration +{ + internal class RelativeLocatorsTests : UITest + { + private readonly ChallengingDomForm challengingDomForm = new ChallengingDomForm(); + private const string labelLocatorCell = "//td"; + private static IElementFactory ElementFactory => AqualityServices.Get(); + + [SetUp] + public void Before() + { + challengingDomForm.Open(); + //AqualityServices.Browser.GoTo(WelcomeForm.Url); + } + + [Test] + public void Should_BePossibleTo_AboveWithDifferentParametersType() + { + var url = new WelcomeForm().Url; + var browser = AqualityServices.Browser; + + var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; + var cellInRow3Column5 = challengingDomForm.CellInRow3Column5; + + + var actualWebElementCellRaw3Column5GotBySeleniumRelative1 = + AqualityServices.Browser.Driver.FindElement(RelativeBy + .WithLocator(By.XPath(labelLocatorCell)) + .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + var text35 = actualWebElementCellRaw3Column5GotBySeleniumRelative1.Text; + + + + + var actualCellRaw3Column5GotWithByXpath = + ElementFactory.GetLabel(RelativeBy + .WithLocator(By.XPath(labelLocatorCell)) + .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), + ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN5); + + ILabel actualCellRaw3Column5GotWithWebElement = + ElementFactory.GetLabel(RelativeBy + .WithLocator(By.XPath(labelLocatorCell)) + .Above(cellInRow5Column5.GetElement()), + ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + + ILabel actualCellRaw3Column5GotWithAqualityElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)).Above(cellInRow5Column5), + ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + + var actualWebElementCellRaw3Column5GotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + .WithLocator(By.XPath(labelLocatorCell)) + .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + + var expectedText = cellInRow3Column5.Text; + + string text1 = actualWebElementCellRaw3Column5GotBySeleniumRelative.Text; + // string text2 = actualCellRaw3Column5GotWithByXpath.Text; + // string text3 = actualCellRaw3Column5GotWithWebElement.Text; + // string text4 = actualCellRaw3Column5GotWithAqualityElement.Text; + string text5 = actualWebElementCellRaw3Column5GotBySeleniumRelative.Text; + + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, "Text got with above by relative selenium is not expected"); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, "Text got with above by xpath is not expected"); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, "Text got with above by webelement is not expected"); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, "Text got with above by aqualityElement is not expected"); + }); + + + + } + } +} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs new file mode 100644 index 00000000..e4545f07 --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs @@ -0,0 +1,39 @@ +using Aquality.Selenium.Elements.Interfaces; +using OpenQA.Selenium; + +namespace Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms +{ + internal class ChallengingDomForm : TheInternetForm + { + public ChallengingDomForm() : base(By.XPath("//h3[contains(text(),'Challenging DOM')]"), "Challenging dom form") + { + } + + protected override string UrlPart => "challenging_dom"; + + public static readonly string ELEMENT_NAME_ROW3_COLUMN5 = "Cell in row 3 column 5"; + public static string ELEMENT_NAME_ROW5_COLUMN5 = "Cell in row 5 column 5"; + public static string ELEMENT_NAME_ROW7_COLUMN5 = "Cell in row 7 column 5"; + public static string ELEMENT_NAME_ROW5_COLUMN7 = "Cell in row 5 column 7"; + public static string ELEMENT_NAME_ROW5_COLUMN3 = "Cell in row 5 column 3"; + public static string ELEMENT_NAME_ROW1_COLUMN1 = "Cell in row 1 column 1"; + public static string ELEMENT_NAME_ROW2_COLUMN1 = "Cell in row 2 column 1"; + + public static readonly string locatorCellRow5Column5 = "//tr[5]/td[5]"; + private const string locatorCellRow3Column5 = "//tr[3]/td[5]"; + private const string locatorCellRow7Column5 = "//tr[7]/td[5]"; + private const string locatorCellRow5Column3 = "//tr[5]/td[3]"; + private const string locatorCellRow5Column7 = "//tr[5]/td[7]"; + private const string locatorCellRow1Column1 = "//tr[1]/td[1]"; + private const string locatorCellRow2Column1 = "//tr[2]/td[1]"; + + + public ILabel CellInRow3Column5 => ElementFactory.GetLabel(By.XPath(locatorCellRow3Column5), ELEMENT_NAME_ROW3_COLUMN5); + public ILabel CellInRow5Column5 => ElementFactory.GetLabel(By.XPath(locatorCellRow5Column5), ELEMENT_NAME_ROW5_COLUMN5); + public ILabel CellInRow7Column5 => ElementFactory.GetLabel(By.XPath(locatorCellRow7Column5), ELEMENT_NAME_ROW7_COLUMN5); + public ILabel CellInRow5Column7 => ElementFactory.GetLabel(By.XPath(locatorCellRow5Column7), ELEMENT_NAME_ROW5_COLUMN7); + public ILabel CellInRow5Column3 => ElementFactory.GetLabel(By.XPath(locatorCellRow5Column3), ELEMENT_NAME_ROW5_COLUMN3); + public ILabel CellInRow1Column1 => ElementFactory.GetLabel(By.XPath(locatorCellRow1Column1), ELEMENT_NAME_ROW1_COLUMN1); + public ILabel CellInRow2Column1 => ElementFactory.GetLabel(By.XPath(locatorCellRow2Column1), ELEMENT_NAME_ROW2_COLUMN1); + } +} From 983c144059ec5ba7096c055704df782ab60f8caf Mon Sep 17 00:00:00 2001 From: Andrei Pavar Date: Mon, 4 Jul 2022 15:13:23 +0300 Subject: [PATCH 02/12] [feature/Relative_locators] Add left, right, below tests --- .../Aquality.Selenium/Locators/RelativeBy.cs | 57 +++++++ .../Integration/RelativeLocatorsTests.cs | 143 ++++++++++++++---- .../TheInternet/Forms/ChallengingDomForm.cs | 12 +- 3 files changed, 180 insertions(+), 32 deletions(-) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs index 84386a25..08fe2e2b 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs @@ -39,6 +39,63 @@ public RelativeBy Above(IElement element) return new RelativeBy(by); } + public RelativeBy Below(By by) + { + this.by = RelativeSeleniumBy.WithLocator(this.by).Below(by); + return new RelativeBy(this.by); + } + + public RelativeBy Below(WebElement webElement) + { + by = RelativeSeleniumBy.WithLocator(by).Below(webElement); + return new RelativeBy(by); + } + + public RelativeBy Below(IElement element) + { + by = RelativeSeleniumBy.WithLocator(by).Below(element.Locator); + return new RelativeBy(by); + } + + public RelativeBy Left(By by) + { + this.by = RelativeSeleniumBy.WithLocator(this.by).LeftOf(by); + return new RelativeBy(this.by); + } + + public RelativeBy Left(WebElement webElement) + { + by = RelativeSeleniumBy.WithLocator(by).LeftOf(webElement); + return new RelativeBy(by); + } + + public RelativeBy Left(IElement element) + { + by = RelativeSeleniumBy.WithLocator(by).LeftOf(element.Locator); + return new RelativeBy(by); + } + + public RelativeBy Right(By by) + { + this.by = RelativeSeleniumBy.WithLocator(this.by).RightOf(by); + return new RelativeBy(this.by); + } + + public RelativeBy Right(WebElement webElement) + { + by = RelativeSeleniumBy.WithLocator(by).RightOf(webElement); + return new RelativeBy(by); + } + + public RelativeBy Right(IElement element) + { + by = RelativeSeleniumBy.WithLocator(by).RightOf(element.Locator); + return new RelativeBy(by); + } + + + + public override IWebElement FindElement(ISearchContext context) { Console.WriteLine(by.ToString()); diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs index 429d4f05..296a13e1 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs @@ -22,72 +22,163 @@ internal class RelativeLocatorsTests : UITest private readonly ChallengingDomForm challengingDomForm = new ChallengingDomForm(); private const string labelLocatorCell = "//td"; private static IElementFactory ElementFactory => AqualityServices.Get(); + private const string ABOVE = "above"; + private const string BELOW = "below"; + private const string LEFT = "left"; + private const string RIGHT = "right"; + private const string SELENIUM_RELATIVE = "selenium relative"; + private const string XPATH = "xpath"; + private const string WEB_ELEMENT = "web element"; + private const string AQUALITY_ELEMENT = "aquality element"; + + private static string GetMessageError(string gotWith, string gotBy) => $"Text of element got with [{ gotWith }] by [{ gotBy }] is not expected"; [SetUp] public void Before() { challengingDomForm.Open(); - //AqualityServices.Browser.GoTo(WelcomeForm.Url); } [Test] public void Should_BePossibleTo_AboveWithDifferentParametersType() { - var url = new WelcomeForm().Url; - var browser = AqualityServices.Browser; - var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; var cellInRow3Column5 = challengingDomForm.CellInRow3Column5; - - var actualWebElementCellRaw3Column5GotBySeleniumRelative1 = - AqualityServices.Browser.Driver.FindElement(RelativeBy - .WithLocator(By.XPath(labelLocatorCell)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); - var text35 = actualWebElementCellRaw3Column5GotBySeleniumRelative1.Text; - - - - var actualCellRaw3Column5GotWithByXpath = ElementFactory.GetLabel(RelativeBy .WithLocator(By.XPath(labelLocatorCell)) .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN5); - ILabel actualCellRaw3Column5GotWithWebElement = + var actualCellRaw3Column5GotWithWebElement = ElementFactory.GetLabel(RelativeBy .WithLocator(By.XPath(labelLocatorCell)) .Above(cellInRow5Column5.GetElement()), ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); - ILabel actualCellRaw3Column5GotWithAqualityElement = + var actualCellRaw3Column5GotWithAqualityElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)).Above(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); var actualWebElementCellRaw3Column5GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy .WithLocator(By.XPath(labelLocatorCell)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + .Above(By.XPath(ChallengingDomForm.locatorCellRow3Column5))); var expectedText = cellInRow3Column5.Text; - string text1 = actualWebElementCellRaw3Column5GotBySeleniumRelative.Text; - // string text2 = actualCellRaw3Column5GotWithByXpath.Text; - // string text3 = actualCellRaw3Column5GotWithWebElement.Text; - // string text4 = actualCellRaw3Column5GotWithAqualityElement.Text; - string text5 = actualWebElementCellRaw3Column5GotBySeleniumRelative.Text; + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, GetMessageError(ABOVE, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, GetMessageError(ABOVE, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, GetMessageError(ABOVE, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, GetMessageError(ABOVE, AQUALITY_ELEMENT)); + }); + } + + [Test] + public void Should_BePossibleTo_BelowWithDifferentParametersType() + { + var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; + var cellInRow7Column5 = challengingDomForm.CellInRow7Column5; + + var actualCellRaw7Column5GotWithByXpath = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Below(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + + var actualCellRaw7Column5GotWithWebElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Below(cellInRow5Column5.GetElement()), ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + + var actualCellRaw7Column5GotWithAqualityElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Below(cellInRow5Column5),ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + + var actualWebElementCellRaw7Column5GotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + .WithLocator(By.XPath(labelLocatorCell)) + .Below(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + + var expectedText = cellInRow7Column5.Text; + + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualWebElementCellRaw7Column5GotBySeleniumRelative.Text, GetMessageError(BELOW, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithByXpath.Text, GetMessageError(BELOW, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithWebElement.Text, GetMessageError(BELOW, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithAqualityElement.Text, GetMessageError(BELOW, AQUALITY_ELEMENT)); + }); + } + + [Test] + public void Should_BePossibleTo_LeftWithDifferentParametersType() + { + var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; + var cellInRow5Column3 = challengingDomForm.CellInRow5Column7; + + var actualCellRaw5Column3GotWithByXpath = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Left(By.XPath(ChallengingDomForm.locatorCellRow5Column7)), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + + var actualCellRaw5Column3GotWithWebElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Left(cellInRow5Column5.GetElement()), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + + var actualCellRaw5Column3GotWithAqualityElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Left(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + + var actualWebElementCellRaw5Column3GotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + .WithLocator(By.XPath(labelLocatorCell)) + .LeftOf(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + + var expectedText = cellInRow5Column3.Text; Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, "Text got with above by relative selenium is not expected"); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, "Text got with above by xpath is not expected"); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, "Text got with above by webelement is not expected"); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, "Text got with above by aqualityElement is not expected"); + Assert.AreEqual(expectedText, actualWebElementCellRaw5Column3GotBySeleniumRelative.Text, GetMessageError(LEFT, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithByXpath.Text, GetMessageError(LEFT, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithWebElement.Text, GetMessageError(LEFT, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithAqualityElement.Text, GetMessageError(LEFT, AQUALITY_ELEMENT)); }); + } + public void Should_BePossibleTo_RightWithDifferentParametersType() + { + var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; + var cellInRow5Column7 = challengingDomForm.CellInRow5Column7; + + var actualCellRaw5Column7GotWithByXpath = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Right(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN7); + + var actualCellRaw5Column7GotWithWebElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Right(cellInRow5Column5.GetElement()), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN7); + + var actualCellRaw5Column7GotWithAqualityElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Right(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN7); + + var actualWebElementCellRaw5Column7GotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + .WithLocator(By.XPath(labelLocatorCell)) + .RightOf(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + var expectedText = cellInRow5Column7.Text; + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualWebElementCellRaw5Column7GotBySeleniumRelative.Text, GetMessageError(RIGHT, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithByXpath.Text, GetMessageError(RIGHT, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithWebElement.Text, GetMessageError(RIGHT, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithAqualityElement.Text, GetMessageError(RIGHT, AQUALITY_ELEMENT)); + }); } + + + } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs index e4545f07..3b5b64d9 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs @@ -20,12 +20,12 @@ public ChallengingDomForm() : base(By.XPath("//h3[contains(text(),'Challenging D public static string ELEMENT_NAME_ROW2_COLUMN1 = "Cell in row 2 column 1"; public static readonly string locatorCellRow5Column5 = "//tr[5]/td[5]"; - private const string locatorCellRow3Column5 = "//tr[3]/td[5]"; - private const string locatorCellRow7Column5 = "//tr[7]/td[5]"; - private const string locatorCellRow5Column3 = "//tr[5]/td[3]"; - private const string locatorCellRow5Column7 = "//tr[5]/td[7]"; - private const string locatorCellRow1Column1 = "//tr[1]/td[1]"; - private const string locatorCellRow2Column1 = "//tr[2]/td[1]"; + public const string locatorCellRow3Column5 = "//tr[3]/td[5]"; + public const string locatorCellRow7Column5 = "//tr[7]/td[5]"; + public const string locatorCellRow5Column3 = "//tr[5]/td[3]"; + public const string locatorCellRow5Column7 = "//tr[5]/td[7]"; + public const string locatorCellRow1Column1 = "//tr[1]/td[1]"; + public const string locatorCellRow2Column1 = "//tr[2]/td[1]"; public ILabel CellInRow3Column5 => ElementFactory.GetLabel(By.XPath(locatorCellRow3Column5), ELEMENT_NAME_ROW3_COLUMN5); From b334b9d254cd6edbb102132709ef1cca0ef8febd Mon Sep 17 00:00:00 2001 From: Andrei Pavar Date: Mon, 4 Jul 2022 18:25:33 +0300 Subject: [PATCH 03/12] [feature/Relative_locators] debug code with relative selenium inside [with] method --- .../Aquality.Selenium/Locators/RelativeBy.cs | 3 +- .../Integration/RelativeLocatorsTests.cs | 78 ++++++++++++++++++- .../TheInternet/Forms/ChallengingDomForm.cs | 1 + 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs index 08fe2e2b..193597d9 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs @@ -104,7 +104,8 @@ public override IWebElement FindElement(ISearchContext context) public override ReadOnlyCollection FindElements(ISearchContext context) { - return ((RelativeSeleniumBy)by).FindElements(context); + return context.FindElements(by); + // return ((RelativeSeleniumBy)by).FindElements(context); } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs index 296a13e1..33aeebe3 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs @@ -64,7 +64,7 @@ public void Should_BePossibleTo_AboveWithDifferentParametersType() var actualWebElementCellRaw3Column5GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy .WithLocator(By.XPath(labelLocatorCell)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow3Column5))); + .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); var expectedText = cellInRow3Column5.Text; @@ -115,11 +115,11 @@ public void Should_BePossibleTo_BelowWithDifferentParametersType() public void Should_BePossibleTo_LeftWithDifferentParametersType() { var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; - var cellInRow5Column3 = challengingDomForm.CellInRow5Column7; + var cellInRow5Column3 = challengingDomForm.CellInRow5Column3; var actualCellRaw5Column3GotWithByXpath = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Left(By.XPath(ChallengingDomForm.locatorCellRow5Column7)), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + .Left(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); var actualCellRaw5Column3GotWithWebElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) @@ -145,6 +145,7 @@ public void Should_BePossibleTo_LeftWithDifferentParametersType() }); } + [Test] public void Should_BePossibleTo_RightWithDifferentParametersType() { var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; @@ -178,6 +179,77 @@ public void Should_BePossibleTo_RightWithDifferentParametersType() }); } + [Test] + public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParametersType() + { + var cellInRow5Column3 = challengingDomForm.CellInRow5Column3; + var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; + var cellInRow5Column7 = challengingDomForm.CellInRow5Column7; + var cellInRow3Column5 = challengingDomForm.CellInRow3Column5; + var cellInRow7Column5 = challengingDomForm.CellInRow7Column5; + + var actualCellRaw3Column5GotWithByXpath = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5)) + .Below(By.XPath(ChallengingDomForm.locatorCellRow3Column5)) + .Left(By.XPath(ChallengingDomForm.locatorCellRow5Column7)) + .Right(By.XPath(ChallengingDomForm.locatorCellRow5Column3)) + .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5)) + , ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + + var actualCellRaw3Column5GotWithWebElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Above(cellInRow7Column5.GetElement()) + .Below(cellInRow3Column5.GetElement()) + .Left(cellInRow5Column7.GetElement()) + .Right(cellInRow5Column3.GetElement()) + .Above(cellInRow7Column5.GetElement()) + , ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + + var actualCellRaw3Column5GotWithAqualityElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Above(cellInRow7Column5) + .Below(cellInRow3Column5) + .Left(cellInRow5Column7) + .Right(cellInRow5Column3) + .Above(cellInRow7Column5) + , ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + + /*var actualWebElementCellRaw3Column5GotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + .WithLocator(By.XPath(labelLocatorCell)) + .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5)) + .Below(By.XPath(ChallengingDomForm.locatorCellRow3Column5)) + .LeftOf(By.XPath(ChallengingDomForm.locatorCellRow5Column7)) + .RightOf(By.XPath(ChallengingDomForm.locatorCellRow5Column3)) + .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5)));*/ + + + + + var actualWebElementCellRaw3Column5GotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + .WithLocator(RelativeSeleniumBy.WithLocator(By.XPath(labelLocatorCell)).Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5))) + + .Below(By.XPath(ChallengingDomForm.locatorCellRow3Column5))); + + + + + + var expectedText = cellInRow5Column5.Text; + + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, GetMessageError(RIGHT, SELENIUM_RELATIVE)); + // Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, GetMessageError(RIGHT, XPATH)); + // Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, GetMessageError(RIGHT, WEB_ELEMENT)); + // Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, GetMessageError(RIGHT, AQUALITY_ELEMENT)); + }); + } + + + } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs index 3b5b64d9..2dea9c68 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs @@ -20,6 +20,7 @@ public ChallengingDomForm() : base(By.XPath("//h3[contains(text(),'Challenging D public static string ELEMENT_NAME_ROW2_COLUMN1 = "Cell in row 2 column 1"; public static readonly string locatorCellRow5Column5 = "//tr[5]/td[5]"; + public const string locatorCellRow1Column5 = "//tr[1]/td[5]"; public const string locatorCellRow3Column5 = "//tr[3]/td[5]"; public const string locatorCellRow7Column5 = "//tr[7]/td[5]"; public const string locatorCellRow5Column3 = "//tr[5]/td[3]"; From 37673d8fbe5d117c8a8a52cd18e23130aa8336b5 Mon Sep 17 00:00:00 2001 From: Andrei Pavar Date: Wed, 6 Jul 2022 13:10:18 +0300 Subject: [PATCH 04/12] [feature/Relative_locators2] resolve issuew with relative in relative --- .../Aquality.Selenium/Locators/Function.cs | 24 +++ .../Aquality.Selenium/Locators/RelativeBy.cs | 191 +++++++++++++++--- .../Integration/RelativeLocatorsTests.cs | 22 +- 3 files changed, 195 insertions(+), 42 deletions(-) create mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs new file mode 100644 index 00000000..fd0fec20 --- /dev/null +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Aquality.Selenium.Locators +{ + internal class Function + { + public string Name { get; } + public Object[] Arguments { get; } + + private Function() + { + + } + + public Function(string name, Object[] arguments) + { + Name = name; + Arguments = arguments; + } + + } +} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs index 193597d9..574ce561 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs @@ -4,12 +4,21 @@ using Aquality.Selenium.Core.Elements.Interfaces; using System.Collections.ObjectModel; using System; +using System.Collections.Generic; +using System.Linq; namespace Aquality.Selenium.Locators { public class RelativeBy : By { private By by; + private List functions = new List(); + + private const string ABOVE = "Above"; + private const string BELOW = "Below"; + private const string LEFT = "LeftOf"; + private const string RIGHT = "RightOf"; + private const string NEAR = "Near"; private RelativeBy(By by) { @@ -22,90 +31,210 @@ public static RelativeBy WithLocator(By by) } public RelativeBy Above(By by) - { - this.by = RelativeSeleniumBy.WithLocator(this.by).Above(by); - return new RelativeBy(this.by); + { + functions.Add(new Function(ABOVE, new[] { by })); + return this; + //this.by = RelativeSeleniumBy.WithLocator(this.by).Above(by); + //return new RelativeBy(this.by); } public RelativeBy Above(WebElement webElement) { - by = RelativeSeleniumBy.WithLocator(by).Above(webElement); - return new RelativeBy(by); + functions.Add(new Function(ABOVE, new[] { webElement })); + return this; + // by = RelativeSeleniumBy.WithLocator(by).Above(webElement); + // return new RelativeBy(by); } public RelativeBy Above(IElement element) { - by = RelativeSeleniumBy.WithLocator(by).Above(element.Locator); - return new RelativeBy(by); + functions.Add(new Function(ABOVE, new[] { element.Locator })); + return this; + // by = RelativeSeleniumBy.WithLocator(by).Above(element.Locator); + // return new RelativeBy(by); } public RelativeBy Below(By by) { - this.by = RelativeSeleniumBy.WithLocator(this.by).Below(by); - return new RelativeBy(this.by); + functions.Add(new Function(BELOW, new[] { by })); + return this; + // this.by = RelativeSeleniumBy.WithLocator(this.by).Below(by); + // return new RelativeBy(this.by); } public RelativeBy Below(WebElement webElement) { - by = RelativeSeleniumBy.WithLocator(by).Below(webElement); - return new RelativeBy(by); + functions.Add(new Function(BELOW, new[] { webElement })); + return this; + // by = RelativeSeleniumBy.WithLocator(by).Below(webElement); + // return new RelativeBy(by); } public RelativeBy Below(IElement element) { - by = RelativeSeleniumBy.WithLocator(by).Below(element.Locator); - return new RelativeBy(by); + functions.Add(new Function(BELOW, new[] { element.Locator })); + return this; + // by = RelativeSeleniumBy.WithLocator(by).Below(element.Locator); + // return new RelativeBy(by); } public RelativeBy Left(By by) { - this.by = RelativeSeleniumBy.WithLocator(this.by).LeftOf(by); - return new RelativeBy(this.by); + functions.Add(new Function(LEFT, new[] { by })); + return this; + // this.by = RelativeSeleniumBy.WithLocator(this.by).LeftOf(by); + // return new RelativeBy(this.by); } public RelativeBy Left(WebElement webElement) { - by = RelativeSeleniumBy.WithLocator(by).LeftOf(webElement); - return new RelativeBy(by); + functions.Add(new Function(LEFT, new[] { webElement })); + return this; + // by = RelativeSeleniumBy.WithLocator(by).LeftOf(webElement); + // return new RelativeBy(by); } public RelativeBy Left(IElement element) { - by = RelativeSeleniumBy.WithLocator(by).LeftOf(element.Locator); - return new RelativeBy(by); + functions.Add(new Function(LEFT, new[] { element.Locator })); + return this; + // by = RelativeSeleniumBy.WithLocator(by).LeftOf(element.Locator); + // return new RelativeBy(by); } public RelativeBy Right(By by) { - this.by = RelativeSeleniumBy.WithLocator(this.by).RightOf(by); - return new RelativeBy(this.by); + functions.Add(new Function(RIGHT, new[] { by })); + return this; + // this.by = RelativeSeleniumBy.WithLocator(this.by).RightOf(by); + // return new RelativeBy(this.by); } public RelativeBy Right(WebElement webElement) { - by = RelativeSeleniumBy.WithLocator(by).RightOf(webElement); - return new RelativeBy(by); + functions.Add(new Function(RIGHT, new[] { webElement })); + return this; + // by = RelativeSeleniumBy.WithLocator(by).RightOf(webElement); + // return new RelativeBy(by); } public RelativeBy Right(IElement element) { - by = RelativeSeleniumBy.WithLocator(by).RightOf(element.Locator); - return new RelativeBy(by); + functions.Add(new Function(RIGHT, new[] { element.Locator })); + return this; + // by = RelativeSeleniumBy.WithLocator(by).RightOf(element.Locator); + // return new RelativeBy(by); } - - public override IWebElement FindElement(ISearchContext context) { - Console.WriteLine(by.ToString()); - return ((RelativeSeleniumBy)by).FindElement(context); + return FindElements(context).First(); + // Console.WriteLine(by.ToString()); + // return ((RelativeSeleniumBy)by).FindElement(context); } public override ReadOnlyCollection FindElements(ISearchContext context) { - return context.FindElements(by); - // return ((RelativeSeleniumBy)by).FindElements(context); + + RelativeSeleniumBy formedBy = RelativeSeleniumBy.WithLocator(by); + functions.ForEach(x => + { + var firstArgumentType = x.Arguments.First().GetType(); + switch (x.Name) + { + + case ABOVE: + if (firstArgumentType == typeof(WebElement)) + { + formedBy = formedBy.Above((WebElement)x.Arguments.First()); + } + + if (firstArgumentType == typeof(By)) + { + formedBy = formedBy.Above((By)x.Arguments.First()); + } + + if (firstArgumentType == typeof(IElement)) + { + formedBy = formedBy.Above(((IElement)x.Arguments.First()).Locator); + } + + break; + + case BELOW: + + if (firstArgumentType == typeof(WebElement)) + { + formedBy = formedBy.Below((WebElement)x.Arguments.First()); + } + + if (firstArgumentType == typeof(By)) + { + formedBy = formedBy.Below((By)x.Arguments.First()); + } + + if (firstArgumentType == typeof(IElement)) + { + formedBy = formedBy.Below(((IElement)x.Arguments.First()).Locator); + } + break; + + case LEFT: + + if (firstArgumentType == typeof(WebElement)) + { + formedBy = formedBy.LeftOf((WebElement)x.Arguments.First()); + } + + if (firstArgumentType == typeof(By)) + { + formedBy = formedBy.LeftOf((By)x.Arguments.First()); + } + + if (firstArgumentType == typeof(IElement)) + { + formedBy = formedBy.LeftOf(((IElement)x.Arguments.First()).Locator); + } + + break; + + case RIGHT: + + if (firstArgumentType == typeof(WebElement)) + { + formedBy = formedBy.RightOf((WebElement)x.Arguments.First()); + } + + if (firstArgumentType == typeof(By)) + { + formedBy = formedBy.RightOf((By)x.Arguments.First()); + } + + if (firstArgumentType == typeof(IElement)) + { + formedBy = formedBy.RightOf(((IElement)x.Arguments.First()).Locator); + } + + break; + + } + // Console.WriteLine(typeof(RelativeSeleniumBy).GetMethods().Where(y=>y.Name==x.Name).First().GetParameters().First().ParameterType.Name); + // formedBy = (RelativeSeleniumBy)typeof(RelativeSeleniumBy).GetMethod(x.Name).Invoke(formedBy, x.Arguments); + // (RelativeSeleniumBy)typeof(RelativeSeleniumBy).GetMethods().Where(x=>x.Attributes.) + + // Console.WriteLine("Parameters"); + // typeof(RelativeSeleniumBy).GetMethods().Where(y => (y.Name == x.Name)).ToList()[2].GetParameters().Select(z => z.ParameterType).ToList().ForEach(c => Console.WriteLine(c)); + // Console.WriteLine("Arguments"); + // x.Arguments.Select(t => t.GetType()).ToList().ForEach(z => Console.WriteLine(z)); + + + // Console.WriteLine(typeof(RelativeSeleniumBy).GetMethods().Where(y => (y.Name == x.Name) && (y.GetParameters().Select(z => z.ParameterType).SequenceEqual(x.Arguments.Select(t => t.GetType())))).First().Name); + + }); + return context.FindElements(formedBy); + // return context.FindElements(by); + // return ((RelativeSeleniumBy)by).FindElements(context); } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs index 33aeebe3..ae36ace4 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs @@ -215,36 +215,36 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters .Above(cellInRow7Column5) , ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); - /*var actualWebElementCellRaw3Column5GotBySeleniumRelative = + var actualWebElementCellRaw3Column5GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy .WithLocator(By.XPath(labelLocatorCell)) .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5)) .Below(By.XPath(ChallengingDomForm.locatorCellRow3Column5)) .LeftOf(By.XPath(ChallengingDomForm.locatorCellRow5Column7)) .RightOf(By.XPath(ChallengingDomForm.locatorCellRow5Column3)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5)));*/ + .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5))); - var actualWebElementCellRaw3Column5GotBySeleniumRelative = - AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy - .WithLocator(RelativeSeleniumBy.WithLocator(By.XPath(labelLocatorCell)).Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5))) + // var actualWebElementCellRaw3Column5GotBySeleniumRelative = + // AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + // .WithLocator(RelativeSeleniumBy.WithLocator(By.XPath(labelLocatorCell)).Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5))) - .Below(By.XPath(ChallengingDomForm.locatorCellRow3Column5))); - + // .Below(By.XPath(ChallengingDomForm.locatorCellRow3Column5))); + - var expectedText = cellInRow5Column5.Text; + var expectedText = cellInRow5Column5.Text; Assert.Multiple(() => { Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, GetMessageError(RIGHT, SELENIUM_RELATIVE)); - // Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, GetMessageError(RIGHT, XPATH)); - // Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, GetMessageError(RIGHT, WEB_ELEMENT)); - // Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, GetMessageError(RIGHT, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, GetMessageError(RIGHT, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, GetMessageError(RIGHT, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, GetMessageError(RIGHT, AQUALITY_ELEMENT)); }); } From b2380a2570536b5e0616672a6fe7ac87a6d1b5c5 Mon Sep 17 00:00:00 2001 From: Andrei Pavar Date: Wed, 6 Jul 2022 22:58:59 +0300 Subject: [PATCH 05/12] [feature/Relative_locators2] Realization with near --- .../Aquality.Selenium/Locators/RelativeBy.cs | 135 +++++++++++------- .../Integration/RelativeLocatorsTests.cs | 79 ++++++---- 2 files changed, 142 insertions(+), 72 deletions(-) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs index 574ce561..82682379 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs @@ -31,133 +31,127 @@ public static RelativeBy WithLocator(By by) } public RelativeBy Above(By by) - { + { functions.Add(new Function(ABOVE, new[] { by })); return this; - //this.by = RelativeSeleniumBy.WithLocator(this.by).Above(by); - //return new RelativeBy(this.by); } public RelativeBy Above(WebElement webElement) { functions.Add(new Function(ABOVE, new[] { webElement })); return this; - // by = RelativeSeleniumBy.WithLocator(by).Above(webElement); - // return new RelativeBy(by); } public RelativeBy Above(IElement element) { functions.Add(new Function(ABOVE, new[] { element.Locator })); return this; - // by = RelativeSeleniumBy.WithLocator(by).Above(element.Locator); - // return new RelativeBy(by); } public RelativeBy Below(By by) { functions.Add(new Function(BELOW, new[] { by })); return this; - // this.by = RelativeSeleniumBy.WithLocator(this.by).Below(by); - // return new RelativeBy(this.by); } public RelativeBy Below(WebElement webElement) { functions.Add(new Function(BELOW, new[] { webElement })); return this; - // by = RelativeSeleniumBy.WithLocator(by).Below(webElement); - // return new RelativeBy(by); } public RelativeBy Below(IElement element) { functions.Add(new Function(BELOW, new[] { element.Locator })); return this; - // by = RelativeSeleniumBy.WithLocator(by).Below(element.Locator); - // return new RelativeBy(by); } public RelativeBy Left(By by) { functions.Add(new Function(LEFT, new[] { by })); return this; - // this.by = RelativeSeleniumBy.WithLocator(this.by).LeftOf(by); - // return new RelativeBy(this.by); } public RelativeBy Left(WebElement webElement) { functions.Add(new Function(LEFT, new[] { webElement })); return this; - // by = RelativeSeleniumBy.WithLocator(by).LeftOf(webElement); - // return new RelativeBy(by); } public RelativeBy Left(IElement element) { functions.Add(new Function(LEFT, new[] { element.Locator })); return this; - // by = RelativeSeleniumBy.WithLocator(by).LeftOf(element.Locator); - // return new RelativeBy(by); } public RelativeBy Right(By by) { functions.Add(new Function(RIGHT, new[] { by })); return this; - // this.by = RelativeSeleniumBy.WithLocator(this.by).RightOf(by); - // return new RelativeBy(this.by); } public RelativeBy Right(WebElement webElement) { functions.Add(new Function(RIGHT, new[] { webElement })); return this; - // by = RelativeSeleniumBy.WithLocator(by).RightOf(webElement); - // return new RelativeBy(by); } public RelativeBy Right(IElement element) { functions.Add(new Function(RIGHT, new[] { element.Locator })); return this; - // by = RelativeSeleniumBy.WithLocator(by).RightOf(element.Locator); - // return new RelativeBy(by); + } + + public RelativeBy Near(By by) + { + functions.Add(new Function(NEAR, new[] { by })); + return this; + } + + public RelativeBy Near(WebElement webElement) + { + functions.Add(new Function(NEAR, new[] { webElement })); + return this; + } + + public RelativeBy Near(IElement element) + { + functions.Add(new Function(NEAR, new[] { element.Locator })); + return this; } public override IWebElement FindElement(ISearchContext context) { return FindElements(context).First(); - // Console.WriteLine(by.ToString()); - // return ((RelativeSeleniumBy)by).FindElement(context); } public override ReadOnlyCollection FindElements(ISearchContext context) { - + RelativeSeleniumBy formedBy = RelativeSeleniumBy.WithLocator(by); - functions.ForEach(x => + functions.ForEach(function => { - var firstArgumentType = x.Arguments.First().GetType(); - switch (x.Name) + var firstArgumentType = function.Arguments.First().GetType(); + var countArguments = function.Arguments.Length; + + switch (function.Name) { case ABOVE: if (firstArgumentType == typeof(WebElement)) { - formedBy = formedBy.Above((WebElement)x.Arguments.First()); + formedBy = formedBy.Above((WebElement)function.Arguments.First()); } if (firstArgumentType == typeof(By)) { - formedBy = formedBy.Above((By)x.Arguments.First()); + formedBy = formedBy.Above((By)function.Arguments.First()); } if (firstArgumentType == typeof(IElement)) { - formedBy = formedBy.Above(((IElement)x.Arguments.First()).Locator); + formedBy = formedBy.Above(((IElement)function.Arguments.First()).Locator); } break; @@ -166,17 +160,17 @@ public override ReadOnlyCollection FindElements(ISearchContext cont if (firstArgumentType == typeof(WebElement)) { - formedBy = formedBy.Below((WebElement)x.Arguments.First()); + formedBy = formedBy.Below((WebElement)function.Arguments.First()); } if (firstArgumentType == typeof(By)) { - formedBy = formedBy.Below((By)x.Arguments.First()); + formedBy = formedBy.Below((By)function.Arguments.First()); } if (firstArgumentType == typeof(IElement)) { - formedBy = formedBy.Below(((IElement)x.Arguments.First()).Locator); + formedBy = formedBy.Below(((IElement)function.Arguments.First()).Locator); } break; @@ -184,17 +178,17 @@ public override ReadOnlyCollection FindElements(ISearchContext cont if (firstArgumentType == typeof(WebElement)) { - formedBy = formedBy.LeftOf((WebElement)x.Arguments.First()); + formedBy = formedBy.LeftOf((WebElement)function.Arguments.First()); } if (firstArgumentType == typeof(By)) { - formedBy = formedBy.LeftOf((By)x.Arguments.First()); + formedBy = formedBy.LeftOf((By)function.Arguments.First()); } if (firstArgumentType == typeof(IElement)) { - formedBy = formedBy.LeftOf(((IElement)x.Arguments.First()).Locator); + formedBy = formedBy.LeftOf(((IElement)function.Arguments.First()).Locator); } break; @@ -203,33 +197,78 @@ public override ReadOnlyCollection FindElements(ISearchContext cont if (firstArgumentType == typeof(WebElement)) { - formedBy = formedBy.RightOf((WebElement)x.Arguments.First()); + formedBy = formedBy.RightOf((WebElement)function.Arguments.First()); } if (firstArgumentType == typeof(By)) { - formedBy = formedBy.RightOf((By)x.Arguments.First()); + formedBy = formedBy.RightOf((By)function.Arguments.First()); } if (firstArgumentType == typeof(IElement)) { - formedBy = formedBy.RightOf(((IElement)x.Arguments.First()).Locator); + formedBy = formedBy.RightOf(((IElement)function.Arguments.First()).Locator); } break; + case NEAR: + if (countArguments == 1) + { + if (firstArgumentType == typeof(WebElement)) + { + formedBy = formedBy.Near((WebElement)function.Arguments.First()); + } + + if (firstArgumentType == typeof(By)) + { + formedBy = formedBy.Near((By)function.Arguments.First()); + } + + if (firstArgumentType == typeof(IElement)) + { + formedBy = formedBy.Near(((IElement)function.Arguments.First()).Locator); + } + } + else + { + if (firstArgumentType == typeof(WebElement)) + { + formedBy = formedBy.Near((WebElement)function.Arguments.First(), (int)function.Arguments[1]); + } + + if (firstArgumentType == typeof(By)) + { + formedBy = formedBy.Near((By)function.Arguments.First(), (int)function.Arguments[1]); + } + + if (firstArgumentType == typeof(IElement)) + { + formedBy = formedBy.Near(((IElement)function.Arguments.First()).Locator, (int)function.Arguments[1]); + } + } + break; + + default: + throw new ArgumentException($"There is no realisation for {function.Name} function"); + + + + + + } // Console.WriteLine(typeof(RelativeSeleniumBy).GetMethods().Where(y=>y.Name==x.Name).First().GetParameters().First().ParameterType.Name); // formedBy = (RelativeSeleniumBy)typeof(RelativeSeleniumBy).GetMethod(x.Name).Invoke(formedBy, x.Arguments); // (RelativeSeleniumBy)typeof(RelativeSeleniumBy).GetMethods().Where(x=>x.Attributes.) - // Console.WriteLine("Parameters"); - // typeof(RelativeSeleniumBy).GetMethods().Where(y => (y.Name == x.Name)).ToList()[2].GetParameters().Select(z => z.ParameterType).ToList().ForEach(c => Console.WriteLine(c)); - // Console.WriteLine("Arguments"); - // x.Arguments.Select(t => t.GetType()).ToList().ForEach(z => Console.WriteLine(z)); + // Console.WriteLine("Parameters"); + // typeof(RelativeSeleniumBy).GetMethods().Where(y => (y.Name == x.Name)).ToList()[2].GetParameters().Select(z => z.ParameterType).ToList().ForEach(c => Console.WriteLine(c)); + // Console.WriteLine("Arguments"); + // x.Arguments.Select(t => t.GetType()).ToList().ForEach(z => Console.WriteLine(z)); - // Console.WriteLine(typeof(RelativeSeleniumBy).GetMethods().Where(y => (y.Name == x.Name) && (y.GetParameters().Select(z => z.ParameterType).SequenceEqual(x.Arguments.Select(t => t.GetType())))).First().Name); + // Console.WriteLine(typeof(RelativeSeleniumBy).GetMethods().Where(y => (y.Name == x.Name) && (y.GetParameters().Select(z => z.ParameterType).SequenceEqual(x.Arguments.Select(t => t.GetType())))).First().Name); }); return context.FindElements(formedBy); diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs index ae36ace4..de554f40 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs @@ -26,12 +26,14 @@ internal class RelativeLocatorsTests : UITest private const string BELOW = "below"; private const string LEFT = "left"; private const string RIGHT = "right"; + private const string NEAR = "near"; + private const string NEAR_DISTANCE = "near with distance"; private const string SELENIUM_RELATIVE = "selenium relative"; private const string XPATH = "xpath"; private const string WEB_ELEMENT = "web element"; private const string AQUALITY_ELEMENT = "aquality element"; - private static string GetMessageError(string gotWith, string gotBy) => $"Text of element got with [{ gotWith }] by [{ gotBy }] is not expected"; + private static string GetMessageError(string gotWith, string gotBy) => $"Text of element got with [{gotWith}] by [{gotBy}] is not expected"; [SetUp] public void Before() @@ -51,20 +53,20 @@ public void Should_BePossibleTo_AboveWithDifferentParametersType() .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN5); - var actualCellRaw3Column5GotWithWebElement = - ElementFactory.GetLabel(RelativeBy - .WithLocator(By.XPath(labelLocatorCell)) - .Above(cellInRow5Column5.GetElement()), - ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + var actualCellRaw3Column5GotWithWebElement = + ElementFactory.GetLabel(RelativeBy + .WithLocator(By.XPath(labelLocatorCell)) + .Above(cellInRow5Column5.GetElement()), + ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); - var actualCellRaw3Column5GotWithAqualityElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)).Above(cellInRow5Column5), - ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + var actualCellRaw3Column5GotWithAqualityElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)).Above(cellInRow5Column5), + ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); - var actualWebElementCellRaw3Column5GotBySeleniumRelative = - AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy - .WithLocator(By.XPath(labelLocatorCell)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + var actualWebElementCellRaw3Column5GotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + .WithLocator(By.XPath(labelLocatorCell)) + .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); var expectedText = cellInRow3Column5.Text; @@ -93,7 +95,7 @@ public void Should_BePossibleTo_BelowWithDifferentParametersType() var actualCellRaw7Column5GotWithAqualityElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Below(cellInRow5Column5),ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + .Below(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); var actualWebElementCellRaw7Column5GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy @@ -224,27 +226,56 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters .RightOf(By.XPath(ChallengingDomForm.locatorCellRow5Column3)) .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5))); + var expectedText = cellInRow5Column5.Text; + var gotWith = $"{ABOVE} {BELOW} {LEFT} {RIGHT} {ABOVE}"; + + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, GetMessageError(gotWith, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, GetMessageError(gotWith, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, GetMessageError(gotWith, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, GetMessageError(gotWith, AQUALITY_ELEMENT)); + }); + } + [Test] + public void Should_BePossibleTo_NearWithDifferentParametersType() + { + var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; + var cellInRow1Column1 = challengingDomForm.CellInRow1Column1; + /* var actualCellRaw2Column1GotWithByXpath = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Near(By.XPath(ChallengingDomForm.locatorCellRow1Column1)), ChallengingDomForm.ELEMENT_NAME_ROW1_COLUMN1); - // var actualWebElementCellRaw3Column5GotBySeleniumRelative = - // AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy - // .WithLocator(RelativeSeleniumBy.WithLocator(By.XPath(labelLocatorCell)).Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5))) + var actualCellRaw2Column1GotWithWebElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Near(cellInRow5Column5.GetElement()), ChallengingDomForm.ELEMENT_NAME_ROW1_COLUMN1); - // .Below(By.XPath(ChallengingDomForm.locatorCellRow3Column5))); + var actualCellRaw2Column1GotWithAqualityElement = + ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + .Near(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW1_COLUMN1);*/ - + var actualWebElementCellRaw2Column1GotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + .WithLocator(By.XPath("//a[contains(@class,'button')]")) + .Near(By.XPath("//a[contains(@class,'button')]"),400)); + /*var actualWebElementCellRaw2Column1GotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + .WithLocator(By.XPath(labelLocatorCell)) + .Near(By.XPath(ChallengingDomForm.locatorCellRow1Column1)));*/ - var expectedText = cellInRow5Column5.Text; + var expectedText = cellInRow1Column1.Text; + var text = actualWebElementCellRaw2Column1GotBySeleniumRelative.Text; Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, GetMessageError(RIGHT, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, GetMessageError(RIGHT, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, GetMessageError(RIGHT, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, GetMessageError(RIGHT, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw2Column1GotBySeleniumRelative.Text, GetMessageError(NEAR, SELENIUM_RELATIVE)); + // Assert.AreEqual(expectedText, actualCellRaw2Column1GotWithByXpath.Text, GetMessageError(NEAR, XPATH)); + // Assert.AreEqual(expectedText, actualCellRaw2Column1GotWithWebElement.Text, GetMessageError(NEAR, WEB_ELEMENT)); + // Assert.AreEqual(expectedText, actualCellRaw2Column1GotWithAqualityElement.Text, GetMessageError(NEAR, AQUALITY_ELEMENT)); }); } From 6ac469503576c0730d2653cde5599cdaeb7d7e08 Mon Sep 17 00:00:00 2001 From: Andrei Pavar Date: Thu, 7 Jul 2022 00:26:15 +0300 Subject: [PATCH 06/12] [feature/Relative_locators2] Split switch case with types of parameters --- .../Aquality.Selenium/Locators/RelativeBy.cs | 218 +++++++----------- 1 file changed, 86 insertions(+), 132 deletions(-) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs index 82682379..90eac566 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs @@ -1,6 +1,5 @@ using OpenQA.Selenium; using RelativeSeleniumBy = OpenQA.Selenium.RelativeBy; -using CoreElement = Aquality.Selenium.Core.Elements.Element; using Aquality.Selenium.Core.Elements.Interfaces; using System.Collections.ObjectModel; using System; @@ -11,14 +10,13 @@ namespace Aquality.Selenium.Locators { public class RelativeBy : By { - private By by; - private List functions = new List(); + private readonly By by; + private readonly List functions = new List(); private const string ABOVE = "Above"; private const string BELOW = "Below"; private const string LEFT = "LeftOf"; private const string RIGHT = "RightOf"; - private const string NEAR = "Near"; private RelativeBy(By by) { @@ -102,25 +100,6 @@ public RelativeBy Right(IElement element) return this; } - public RelativeBy Near(By by) - { - functions.Add(new Function(NEAR, new[] { by })); - return this; - } - - public RelativeBy Near(WebElement webElement) - { - functions.Add(new Function(NEAR, new[] { webElement })); - return this; - } - - public RelativeBy Near(IElement element) - { - functions.Add(new Function(NEAR, new[] { element.Locator })); - return this; - } - - public override IWebElement FindElement(ISearchContext context) { return FindElements(context).First(); @@ -128,154 +107,129 @@ public override IWebElement FindElement(ISearchContext context) public override ReadOnlyCollection FindElements(ISearchContext context) { - RelativeSeleniumBy formedBy = RelativeSeleniumBy.WithLocator(by); + functions.ForEach(function => { + var firstArgument = function.Arguments.First(); var firstArgumentType = function.Arguments.First().GetType(); - var countArguments = function.Arguments.Length; switch (function.Name) { - case ABOVE: - if (firstArgumentType == typeof(WebElement)) - { - formedBy = formedBy.Above((WebElement)function.Arguments.First()); - } - - if (firstArgumentType == typeof(By)) - { - formedBy = formedBy.Above((By)function.Arguments.First()); - } - - if (firstArgumentType == typeof(IElement)) - { - formedBy = formedBy.Above(((IElement)function.Arguments.First()).Locator); - } + formedBy = GetRelativeWithAbove(formedBy, firstArgument); break; case BELOW: - if (firstArgumentType == typeof(WebElement)) - { - formedBy = formedBy.Below((WebElement)function.Arguments.First()); - } + formedBy = GetRelativeWithBelow(formedBy, firstArgument); + break; - if (firstArgumentType == typeof(By)) - { - formedBy = formedBy.Below((By)function.Arguments.First()); - } + case LEFT: - if (firstArgumentType == typeof(IElement)) - { - formedBy = formedBy.Below(((IElement)function.Arguments.First()).Locator); - } + formedBy = GetRelativeWithLeft(formedBy, firstArgument); break; - case LEFT: + case RIGHT: - if (firstArgumentType == typeof(WebElement)) - { - formedBy = formedBy.LeftOf((WebElement)function.Arguments.First()); - } + formedBy = GetRelativeWithRight(formedBy, firstArgument); + break; - if (firstArgumentType == typeof(By)) - { - formedBy = formedBy.LeftOf((By)function.Arguments.First()); - } + default: + throw new ArgumentException($"There is no realisation for {function.Name} function"); - if (firstArgumentType == typeof(IElement)) - { - formedBy = formedBy.LeftOf(((IElement)function.Arguments.First()).Locator); - } + } + }); + return context.FindElements(formedBy); + } + private RelativeSeleniumBy GetRelativeWithAbove(RelativeSeleniumBy formedBy, object savedArgument) + { + var typeArgument = savedArgument.GetType(); - break; + if (typeArgument == typeof(WebElement)) + { + return formedBy.Above((WebElement)savedArgument); + } - case RIGHT: + if (typeArgument == typeof(By)) + { + return formedBy.Above((By)savedArgument); + } - if (firstArgumentType == typeof(WebElement)) - { - formedBy = formedBy.RightOf((WebElement)function.Arguments.First()); - } + if (typeArgument == typeof(IElement)) + { + return formedBy.Above(((IElement)savedArgument).Locator); + } - if (firstArgumentType == typeof(By)) - { - formedBy = formedBy.RightOf((By)function.Arguments.First()); - } + throw new ArgumentException($"There is no realisation for {typeArgument} type"); + } - if (firstArgumentType == typeof(IElement)) - { - formedBy = formedBy.RightOf(((IElement)function.Arguments.First()).Locator); - } + private RelativeSeleniumBy GetRelativeWithBelow(RelativeSeleniumBy formedBy, object savedArgument) + { + var typeArgument = savedArgument.GetType(); - break; + if (typeArgument == typeof(WebElement)) + { + return formedBy.Below((WebElement)savedArgument); + } - case NEAR: - if (countArguments == 1) - { - if (firstArgumentType == typeof(WebElement)) - { - formedBy = formedBy.Near((WebElement)function.Arguments.First()); - } - - if (firstArgumentType == typeof(By)) - { - formedBy = formedBy.Near((By)function.Arguments.First()); - } - - if (firstArgumentType == typeof(IElement)) - { - formedBy = formedBy.Near(((IElement)function.Arguments.First()).Locator); - } - } - else - { - if (firstArgumentType == typeof(WebElement)) - { - formedBy = formedBy.Near((WebElement)function.Arguments.First(), (int)function.Arguments[1]); - } - - if (firstArgumentType == typeof(By)) - { - formedBy = formedBy.Near((By)function.Arguments.First(), (int)function.Arguments[1]); - } - - if (firstArgumentType == typeof(IElement)) - { - formedBy = formedBy.Near(((IElement)function.Arguments.First()).Locator, (int)function.Arguments[1]); - } - } - break; + if (typeArgument == typeof(By)) + { + return formedBy.Below((By)savedArgument); + } - default: - throw new ArgumentException($"There is no realisation for {function.Name} function"); + if (typeArgument == typeof(IElement)) + { + return formedBy.Below(((IElement)savedArgument).Locator); + } + throw new ArgumentException($"There is no realisation for {typeArgument} type"); + } + private RelativeSeleniumBy GetRelativeWithRight(RelativeSeleniumBy formedBy, object savedArgument) + { + var typeArgument = savedArgument.GetType(); + if (typeArgument == typeof(WebElement)) + { + return formedBy.RightOf((WebElement)savedArgument); + } + if (typeArgument == typeof(By)) + { + return formedBy.RightOf((By)savedArgument); + } + if (typeArgument == typeof(IElement)) + { + return formedBy.RightOf(((IElement)savedArgument).Locator); + } - } - // Console.WriteLine(typeof(RelativeSeleniumBy).GetMethods().Where(y=>y.Name==x.Name).First().GetParameters().First().ParameterType.Name); - // formedBy = (RelativeSeleniumBy)typeof(RelativeSeleniumBy).GetMethod(x.Name).Invoke(formedBy, x.Arguments); - // (RelativeSeleniumBy)typeof(RelativeSeleniumBy).GetMethods().Where(x=>x.Attributes.) + throw new ArgumentException($"There is no realisation for {typeArgument} type"); + } + + private RelativeSeleniumBy GetRelativeWithLeft(RelativeSeleniumBy formedBy, object savedArgument) + { + var typeArgument = savedArgument.GetType(); - // Console.WriteLine("Parameters"); - // typeof(RelativeSeleniumBy).GetMethods().Where(y => (y.Name == x.Name)).ToList()[2].GetParameters().Select(z => z.ParameterType).ToList().ForEach(c => Console.WriteLine(c)); - // Console.WriteLine("Arguments"); - // x.Arguments.Select(t => t.GetType()).ToList().ForEach(z => Console.WriteLine(z)); + if (typeArgument == typeof(WebElement)) + { + return formedBy.LeftOf((WebElement)savedArgument); + } + if (typeArgument == typeof(By)) + { + return formedBy.LeftOf((By)savedArgument); + } - // Console.WriteLine(typeof(RelativeSeleniumBy).GetMethods().Where(y => (y.Name == x.Name) && (y.GetParameters().Select(z => z.ParameterType).SequenceEqual(x.Arguments.Select(t => t.GetType())))).First().Name); + if (typeArgument == typeof(IElement)) + { + return formedBy.LeftOf(((IElement)savedArgument).Locator); + } - }); - return context.FindElements(formedBy); - // return context.FindElements(by); - // return ((RelativeSeleniumBy)by).FindElements(context); + throw new ArgumentException($"There is no realisation for {typeArgument} type"); } - } } From 29c60109f60df7fa71b6698e1b5c881a034ee21b Mon Sep 17 00:00:00 2001 From: Andrei Pavar Date: Thu, 7 Jul 2022 13:07:21 +0300 Subject: [PATCH 07/12] [feature/Relative_locators2] Add interfaces for RelativeBy --- .../Aquality.Selenium/Locators/Function.cs | 16 ++--- .../Locators/IRelativeAqualityElement.cs | 12 ++++ .../Aquality.Selenium/Locators/IRelativeBy.cs | 12 ++++ .../Locators/IRelativeWebElement.cs | 12 ++++ .../Aquality.Selenium/Locators/RelativeBy.cs | 13 ++-- .../Integration/RelativeLocatorsTests.cs | 67 ++++++++----------- 6 files changed, 76 insertions(+), 56 deletions(-) create mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAqualityElement.cs create mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeBy.cs create mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeWebElement.cs diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs index fd0fec20..311132af 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs @@ -1,24 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Aquality.Selenium.Locators +namespace Aquality.Selenium.Locators { internal class Function { public string Name { get; } - public Object[] Arguments { get; } + public object[] Arguments { get; } - private Function() - { + private Function() { } - } - - public Function(string name, Object[] arguments) + public Function(string name, object[] arguments) { Name = name; Arguments = arguments; } - } } diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAqualityElement.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAqualityElement.cs new file mode 100644 index 00000000..c895d66d --- /dev/null +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAqualityElement.cs @@ -0,0 +1,12 @@ +using Aquality.Selenium.Core.Elements.Interfaces; + +namespace Aquality.Selenium.Locators +{ + internal interface IRelativeAqualityElement + { + RelativeBy Above(IElement by); + RelativeBy Below(IElement by); + RelativeBy Left(IElement by); + RelativeBy Right(IElement by); + } +} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeBy.cs new file mode 100644 index 00000000..ee69558b --- /dev/null +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeBy.cs @@ -0,0 +1,12 @@ +using OpenQA.Selenium; + +namespace Aquality.Selenium.Locators +{ + internal interface IRelativeBy + { + RelativeBy Above(By by); + RelativeBy Below(By by); + RelativeBy Left(By by); + RelativeBy Right(By by); + } +} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeWebElement.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeWebElement.cs new file mode 100644 index 00000000..c42a0187 --- /dev/null +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeWebElement.cs @@ -0,0 +1,12 @@ +using OpenQA.Selenium; + +namespace Aquality.Selenium.Locators +{ + internal interface IRelativeWebElement + { + RelativeBy Above(WebElement by); + RelativeBy Below(WebElement by); + RelativeBy Left(WebElement by); + RelativeBy Right(WebElement by); + } +} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs index 90eac566..7e9622ce 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs @@ -8,7 +8,7 @@ namespace Aquality.Selenium.Locators { - public class RelativeBy : By + public class RelativeBy : By, IRelativeBy, IRelativeWebElement, IRelativeAqualityElement { private readonly By by; private readonly List functions = new List(); @@ -18,6 +18,8 @@ public class RelativeBy : By private const string LEFT = "LeftOf"; private const string RIGHT = "RightOf"; + private RelativeBy() { } + private RelativeBy(By by) { this.by = by; @@ -162,7 +164,7 @@ private RelativeSeleniumBy GetRelativeWithAbove(RelativeSeleniumBy formedBy, obj return formedBy.Above(((IElement)savedArgument).Locator); } - throw new ArgumentException($"There is no realisation for {typeArgument} type"); + throw new ArgumentException(ErrorMessageForType(typeArgument)); } private RelativeSeleniumBy GetRelativeWithBelow(RelativeSeleniumBy formedBy, object savedArgument) @@ -184,7 +186,7 @@ private RelativeSeleniumBy GetRelativeWithBelow(RelativeSeleniumBy formedBy, obj return formedBy.Below(((IElement)savedArgument).Locator); } - throw new ArgumentException($"There is no realisation for {typeArgument} type"); + throw new ArgumentException(ErrorMessageForType(typeArgument)); } private RelativeSeleniumBy GetRelativeWithRight(RelativeSeleniumBy formedBy, object savedArgument) @@ -206,7 +208,7 @@ private RelativeSeleniumBy GetRelativeWithRight(RelativeSeleniumBy formedBy, obj return formedBy.RightOf(((IElement)savedArgument).Locator); } - throw new ArgumentException($"There is no realisation for {typeArgument} type"); + throw new ArgumentException(ErrorMessageForType(typeArgument)); } private RelativeSeleniumBy GetRelativeWithLeft(RelativeSeleniumBy formedBy, object savedArgument) @@ -228,8 +230,9 @@ private RelativeSeleniumBy GetRelativeWithLeft(RelativeSeleniumBy formedBy, obje return formedBy.LeftOf(((IElement)savedArgument).Locator); } - throw new ArgumentException($"There is no realisation for {typeArgument} type"); + throw new ArgumentException(ErrorMessageForType(typeArgument)); } + private string ErrorMessageForType(Type typeArgument) => $"There is no realisation for {typeArgument} type"; } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs index de554f40..c97b4aa2 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs @@ -3,18 +3,9 @@ using NUnit.Framework; using Aquality.Selenium.Elements.Interfaces; using RelativeSeleniumBy = OpenQA.Selenium.RelativeBy; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - - using Aquality.Selenium.Locators; using By = OpenQA.Selenium.By; -using Aquality.Selenium.Core.Elements; - namespace Aquality.Selenium.Tests.Integration { internal class RelativeLocatorsTests : UITest @@ -26,14 +17,12 @@ internal class RelativeLocatorsTests : UITest private const string BELOW = "below"; private const string LEFT = "left"; private const string RIGHT = "right"; - private const string NEAR = "near"; - private const string NEAR_DISTANCE = "near with distance"; private const string SELENIUM_RELATIVE = "selenium relative"; private const string XPATH = "xpath"; private const string WEB_ELEMENT = "web element"; private const string AQUALITY_ELEMENT = "aquality element"; - private static string GetMessageError(string gotWith, string gotBy) => $"Text of element got with [{gotWith}] by [{gotBy}] is not expected"; + private static string MessageError(string gotWith, string gotBy) => $"Text of element got with [{gotWith}] by [{gotBy}] is not expected"; [SetUp] public void Before() @@ -72,10 +61,10 @@ public void Should_BePossibleTo_AboveWithDifferentParametersType() Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, GetMessageError(ABOVE, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, GetMessageError(ABOVE, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, GetMessageError(ABOVE, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, GetMessageError(ABOVE, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, MessageError(ABOVE, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, MessageError(ABOVE, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, MessageError(ABOVE, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, MessageError(ABOVE, AQUALITY_ELEMENT)); }); } @@ -106,10 +95,10 @@ public void Should_BePossibleTo_BelowWithDifferentParametersType() Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw7Column5GotBySeleniumRelative.Text, GetMessageError(BELOW, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithByXpath.Text, GetMessageError(BELOW, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithWebElement.Text, GetMessageError(BELOW, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithAqualityElement.Text, GetMessageError(BELOW, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw7Column5GotBySeleniumRelative.Text, MessageError(BELOW, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithByXpath.Text, MessageError(BELOW, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithWebElement.Text, MessageError(BELOW, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithAqualityElement.Text, MessageError(BELOW, AQUALITY_ELEMENT)); }); } @@ -140,10 +129,10 @@ public void Should_BePossibleTo_LeftWithDifferentParametersType() Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw5Column3GotBySeleniumRelative.Text, GetMessageError(LEFT, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithByXpath.Text, GetMessageError(LEFT, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithWebElement.Text, GetMessageError(LEFT, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithAqualityElement.Text, GetMessageError(LEFT, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw5Column3GotBySeleniumRelative.Text, MessageError(LEFT, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithByXpath.Text, MessageError(LEFT, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithWebElement.Text, MessageError(LEFT, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithAqualityElement.Text, MessageError(LEFT, AQUALITY_ELEMENT)); }); } @@ -174,10 +163,10 @@ public void Should_BePossibleTo_RightWithDifferentParametersType() Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw5Column7GotBySeleniumRelative.Text, GetMessageError(RIGHT, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithByXpath.Text, GetMessageError(RIGHT, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithWebElement.Text, GetMessageError(RIGHT, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithAqualityElement.Text, GetMessageError(RIGHT, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw5Column7GotBySeleniumRelative.Text, MessageError(RIGHT, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithByXpath.Text, MessageError(RIGHT, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithWebElement.Text, MessageError(RIGHT, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithAqualityElement.Text, MessageError(RIGHT, AQUALITY_ELEMENT)); }); } @@ -231,20 +220,20 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, GetMessageError(gotWith, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, GetMessageError(gotWith, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, GetMessageError(gotWith, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, GetMessageError(gotWith, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, MessageError(gotWith, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, MessageError(gotWith, XPATH)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, MessageError(gotWith, WEB_ELEMENT)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, MessageError(gotWith, AQUALITY_ELEMENT)); }); } - +/* [Test] public void Should_BePossibleTo_NearWithDifferentParametersType() { var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; var cellInRow1Column1 = challengingDomForm.CellInRow1Column1; - /* var actualCellRaw2Column1GotWithByXpath = + *//* var actualCellRaw2Column1GotWithByXpath = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) .Near(By.XPath(ChallengingDomForm.locatorCellRow1Column1)), ChallengingDomForm.ELEMENT_NAME_ROW1_COLUMN1); @@ -254,7 +243,7 @@ public void Should_BePossibleTo_NearWithDifferentParametersType() var actualCellRaw2Column1GotWithAqualityElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Near(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW1_COLUMN1);*/ + .Near(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW1_COLUMN1);*//* var actualWebElementCellRaw2Column1GotBySeleniumRelative = @@ -262,22 +251,22 @@ public void Should_BePossibleTo_NearWithDifferentParametersType() .WithLocator(By.XPath("//a[contains(@class,'button')]")) .Near(By.XPath("//a[contains(@class,'button')]"),400)); - /*var actualWebElementCellRaw2Column1GotBySeleniumRelative = + *//*var actualWebElementCellRaw2Column1GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy .WithLocator(By.XPath(labelLocatorCell)) - .Near(By.XPath(ChallengingDomForm.locatorCellRow1Column1)));*/ + .Near(By.XPath(ChallengingDomForm.locatorCellRow1Column1)));*//* var expectedText = cellInRow1Column1.Text; var text = actualWebElementCellRaw2Column1GotBySeleniumRelative.Text; Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw2Column1GotBySeleniumRelative.Text, GetMessageError(NEAR, SELENIUM_RELATIVE)); + Assert.AreEqual(expectedText, actualWebElementCellRaw2Column1GotBySeleniumRelative.Text, MessageError(NEAR, SELENIUM_RELATIVE)); // Assert.AreEqual(expectedText, actualCellRaw2Column1GotWithByXpath.Text, GetMessageError(NEAR, XPATH)); // Assert.AreEqual(expectedText, actualCellRaw2Column1GotWithWebElement.Text, GetMessageError(NEAR, WEB_ELEMENT)); // Assert.AreEqual(expectedText, actualCellRaw2Column1GotWithAqualityElement.Text, GetMessageError(NEAR, AQUALITY_ELEMENT)); }); - } + }*/ From c2e5963b1bd8dc6e722f19dd210ed4131270ef16 Mon Sep 17 00:00:00 2001 From: Andrei Pavar Date: Thu, 7 Jul 2022 14:12:09 +0300 Subject: [PATCH 08/12] [fetature/Relative_locators2] Prepare tests for relative --- .../Integration/RelativeLocatorsTests.cs | 46 ------------------- 1 file changed, 46 deletions(-) diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs index c97b4aa2..429cde36 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs @@ -226,51 +226,5 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, MessageError(gotWith, AQUALITY_ELEMENT)); }); } -/* - [Test] - public void Should_BePossibleTo_NearWithDifferentParametersType() - { - var cellInRow5Column5 = challengingDomForm.CellInRow5Column5; - var cellInRow1Column1 = challengingDomForm.CellInRow1Column1; - - *//* var actualCellRaw2Column1GotWithByXpath = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Near(By.XPath(ChallengingDomForm.locatorCellRow1Column1)), ChallengingDomForm.ELEMENT_NAME_ROW1_COLUMN1); - - var actualCellRaw2Column1GotWithWebElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Near(cellInRow5Column5.GetElement()), ChallengingDomForm.ELEMENT_NAME_ROW1_COLUMN1); - - var actualCellRaw2Column1GotWithAqualityElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Near(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW1_COLUMN1);*//* - - - var actualWebElementCellRaw2Column1GotBySeleniumRelative = - AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy - .WithLocator(By.XPath("//a[contains(@class,'button')]")) - .Near(By.XPath("//a[contains(@class,'button')]"),400)); - - *//*var actualWebElementCellRaw2Column1GotBySeleniumRelative = - AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy - .WithLocator(By.XPath(labelLocatorCell)) - .Near(By.XPath(ChallengingDomForm.locatorCellRow1Column1)));*//* - - var expectedText = cellInRow1Column1.Text; - var text = actualWebElementCellRaw2Column1GotBySeleniumRelative.Text; - - Assert.Multiple(() => - { - Assert.AreEqual(expectedText, actualWebElementCellRaw2Column1GotBySeleniumRelative.Text, MessageError(NEAR, SELENIUM_RELATIVE)); - // Assert.AreEqual(expectedText, actualCellRaw2Column1GotWithByXpath.Text, GetMessageError(NEAR, XPATH)); - // Assert.AreEqual(expectedText, actualCellRaw2Column1GotWithWebElement.Text, GetMessageError(NEAR, WEB_ELEMENT)); - // Assert.AreEqual(expectedText, actualCellRaw2Column1GotWithAqualityElement.Text, GetMessageError(NEAR, AQUALITY_ELEMENT)); - }); - }*/ - - - - - } } From 43f9b800bb3377c0a4a63e8af63d7a4cf146c6b6 Mon Sep 17 00:00:00 2001 From: Andrei Pavar Date: Thu, 7 Jul 2022 15:25:57 +0300 Subject: [PATCH 09/12] [feature/Relative_locators2] Refactor code --- .../Aquality.Selenium/Locators/RelativeBy.cs | 4 +- .../Integration/RelativeLocatorsTests.cs | 118 +++++++++--------- .../TheInternet/Forms/ChallengingDomForm.cs | 44 +++---- 3 files changed, 83 insertions(+), 83 deletions(-) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs index 7e9622ce..a4dfa06b 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs @@ -139,7 +139,7 @@ public override ReadOnlyCollection FindElements(ISearchContext cont break; default: - throw new ArgumentException($"There is no realisation for {function.Name} function"); + throw new ArgumentException($"There is no realisation for [{function.Name}] function"); } }); @@ -233,6 +233,6 @@ private RelativeSeleniumBy GetRelativeWithLeft(RelativeSeleniumBy formedBy, obje throw new ArgumentException(ErrorMessageForType(typeArgument)); } - private string ErrorMessageForType(Type typeArgument) => $"There is no realisation for {typeArgument} type"; + private string ErrorMessageForType(Type typeArgument) => $"There is no realisation for [{typeArgument}] type"; } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs index 429cde36..4fcba6b1 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs @@ -13,14 +13,14 @@ internal class RelativeLocatorsTests : UITest private readonly ChallengingDomForm challengingDomForm = new ChallengingDomForm(); private const string labelLocatorCell = "//td"; private static IElementFactory ElementFactory => AqualityServices.Get(); - private const string ABOVE = "above"; - private const string BELOW = "below"; - private const string LEFT = "left"; - private const string RIGHT = "right"; - private const string SELENIUM_RELATIVE = "selenium relative"; - private const string XPATH = "xpath"; - private const string WEB_ELEMENT = "web element"; - private const string AQUALITY_ELEMENT = "aquality element"; + private const string Above = "above"; + private const string Below = "below"; + private const string Left = "left"; + private const string Right = "right"; + private const string SeleniumRelative = "selenium relative"; + private const string Xpath = "xpath"; + private const string WebElement = "web element"; + private const string AqualityElement = "aquality element"; private static string MessageError(string gotWith, string gotBy) => $"Text of element got with [{gotWith}] by [{gotBy}] is not expected"; @@ -39,32 +39,32 @@ public void Should_BePossibleTo_AboveWithDifferentParametersType() var actualCellRaw3Column5GotWithByXpath = ElementFactory.GetLabel(RelativeBy .WithLocator(By.XPath(labelLocatorCell)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), - ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN5); + .Above(By.XPath(ChallengingDomForm.LocatorCellRow5Column5)), + ChallengingDomForm.ElementNameRow5Column5); var actualCellRaw3Column5GotWithWebElement = ElementFactory.GetLabel(RelativeBy .WithLocator(By.XPath(labelLocatorCell)) .Above(cellInRow5Column5.GetElement()), - ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + ChallengingDomForm.ElementNameRow3Column5); var actualCellRaw3Column5GotWithAqualityElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)).Above(cellInRow5Column5), - ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + ChallengingDomForm.ElementNameRow3Column5); var actualWebElementCellRaw3Column5GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy .WithLocator(By.XPath(labelLocatorCell)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + .Above(By.XPath(ChallengingDomForm.LocatorCellRow5Column5))); var expectedText = cellInRow3Column5.Text; Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, MessageError(ABOVE, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, MessageError(ABOVE, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, MessageError(ABOVE, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, MessageError(ABOVE, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, MessageError(Above, SeleniumRelative)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, MessageError(Above, Xpath)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, MessageError(Above, WebElement)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, MessageError(Above, AqualityElement)); }); } @@ -76,29 +76,29 @@ public void Should_BePossibleTo_BelowWithDifferentParametersType() var actualCellRaw7Column5GotWithByXpath = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Below(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + .Below(By.XPath(ChallengingDomForm.LocatorCellRow5Column5)), ChallengingDomForm.ElementNameRow7Column5); var actualCellRaw7Column5GotWithWebElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Below(cellInRow5Column5.GetElement()), ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + .Below(cellInRow5Column5.GetElement()), ChallengingDomForm.ElementNameRow7Column5); var actualCellRaw7Column5GotWithAqualityElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Below(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + .Below(cellInRow5Column5), ChallengingDomForm.ElementNameRow7Column5); var actualWebElementCellRaw7Column5GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy .WithLocator(By.XPath(labelLocatorCell)) - .Below(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + .Below(By.XPath(ChallengingDomForm.LocatorCellRow5Column5))); var expectedText = cellInRow7Column5.Text; Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw7Column5GotBySeleniumRelative.Text, MessageError(BELOW, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithByXpath.Text, MessageError(BELOW, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithWebElement.Text, MessageError(BELOW, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithAqualityElement.Text, MessageError(BELOW, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw7Column5GotBySeleniumRelative.Text, MessageError(Below, SeleniumRelative)); + Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithByXpath.Text, MessageError(Below, Xpath)); + Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithWebElement.Text, MessageError(Below, WebElement)); + Assert.AreEqual(expectedText, actualCellRaw7Column5GotWithAqualityElement.Text, MessageError(Below, AqualityElement)); }); } @@ -110,29 +110,29 @@ public void Should_BePossibleTo_LeftWithDifferentParametersType() var actualCellRaw5Column3GotWithByXpath = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Left(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + .Left(By.XPath(ChallengingDomForm.LocatorCellRow5Column5)), ChallengingDomForm.ElementNameRow5Column3); var actualCellRaw5Column3GotWithWebElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Left(cellInRow5Column5.GetElement()), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + .Left(cellInRow5Column5.GetElement()), ChallengingDomForm.ElementNameRow5Column3); var actualCellRaw5Column3GotWithAqualityElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Left(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + .Left(cellInRow5Column5), ChallengingDomForm.ElementNameRow5Column3); var actualWebElementCellRaw5Column3GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy .WithLocator(By.XPath(labelLocatorCell)) - .LeftOf(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + .LeftOf(By.XPath(ChallengingDomForm.LocatorCellRow5Column5))); var expectedText = cellInRow5Column3.Text; Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw5Column3GotBySeleniumRelative.Text, MessageError(LEFT, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithByXpath.Text, MessageError(LEFT, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithWebElement.Text, MessageError(LEFT, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithAqualityElement.Text, MessageError(LEFT, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw5Column3GotBySeleniumRelative.Text, MessageError(Left, SeleniumRelative)); + Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithByXpath.Text, MessageError(Left, Xpath)); + Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithWebElement.Text, MessageError(Left, WebElement)); + Assert.AreEqual(expectedText, actualCellRaw5Column3GotWithAqualityElement.Text, MessageError(Left, AqualityElement)); }); } @@ -144,29 +144,29 @@ public void Should_BePossibleTo_RightWithDifferentParametersType() var actualCellRaw5Column7GotWithByXpath = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Right(By.XPath(ChallengingDomForm.locatorCellRow5Column5)), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN7); + .Right(By.XPath(ChallengingDomForm.LocatorCellRow5Column5)), ChallengingDomForm.ElementNameRow5Column7); var actualCellRaw5Column7GotWithWebElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Right(cellInRow5Column5.GetElement()), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN7); + .Right(cellInRow5Column5.GetElement()), ChallengingDomForm.ElementNameRow5Column7); var actualCellRaw5Column7GotWithAqualityElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Right(cellInRow5Column5), ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN7); + .Right(cellInRow5Column5), ChallengingDomForm.ElementNameRow5Column7); var actualWebElementCellRaw5Column7GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy .WithLocator(By.XPath(labelLocatorCell)) - .RightOf(By.XPath(ChallengingDomForm.locatorCellRow5Column5))); + .RightOf(By.XPath(ChallengingDomForm.LocatorCellRow5Column5))); var expectedText = cellInRow5Column7.Text; Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw5Column7GotBySeleniumRelative.Text, MessageError(RIGHT, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithByXpath.Text, MessageError(RIGHT, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithWebElement.Text, MessageError(RIGHT, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithAqualityElement.Text, MessageError(RIGHT, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw5Column7GotBySeleniumRelative.Text, MessageError(Right, SeleniumRelative)); + Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithByXpath.Text, MessageError(Right, Xpath)); + Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithWebElement.Text, MessageError(Right, WebElement)); + Assert.AreEqual(expectedText, actualCellRaw5Column7GotWithAqualityElement.Text, MessageError(Right, AqualityElement)); }); } @@ -181,12 +181,12 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters var actualCellRaw3Column5GotWithByXpath = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5)) - .Below(By.XPath(ChallengingDomForm.locatorCellRow3Column5)) - .Left(By.XPath(ChallengingDomForm.locatorCellRow5Column7)) - .Right(By.XPath(ChallengingDomForm.locatorCellRow5Column3)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5)) - , ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + .Above(By.XPath(ChallengingDomForm.LocatorCellRow7Column5)) + .Below(By.XPath(ChallengingDomForm.LocatorCellRow3Column5)) + .Left(By.XPath(ChallengingDomForm.LocatorCellRow5Column7)) + .Right(By.XPath(ChallengingDomForm.LocatorCellRow5Column3)) + .Above(By.XPath(ChallengingDomForm.LocatorCellRow7Column5)) + , ChallengingDomForm.ElementNameRow3Column5); var actualCellRaw3Column5GotWithWebElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) @@ -195,7 +195,7 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters .Left(cellInRow5Column7.GetElement()) .Right(cellInRow5Column3.GetElement()) .Above(cellInRow7Column5.GetElement()) - , ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + , ChallengingDomForm.ElementNameRow3Column5); var actualCellRaw3Column5GotWithAqualityElement = ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) @@ -204,26 +204,26 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters .Left(cellInRow5Column7) .Right(cellInRow5Column3) .Above(cellInRow7Column5) - , ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + , ChallengingDomForm.ElementNameRow3Column5); var actualWebElementCellRaw3Column5GotBySeleniumRelative = AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy .WithLocator(By.XPath(labelLocatorCell)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5)) - .Below(By.XPath(ChallengingDomForm.locatorCellRow3Column5)) - .LeftOf(By.XPath(ChallengingDomForm.locatorCellRow5Column7)) - .RightOf(By.XPath(ChallengingDomForm.locatorCellRow5Column3)) - .Above(By.XPath(ChallengingDomForm.locatorCellRow7Column5))); + .Above(By.XPath(ChallengingDomForm.LocatorCellRow7Column5)) + .Below(By.XPath(ChallengingDomForm.LocatorCellRow3Column5)) + .LeftOf(By.XPath(ChallengingDomForm.LocatorCellRow5Column7)) + .RightOf(By.XPath(ChallengingDomForm.LocatorCellRow5Column3)) + .Above(By.XPath(ChallengingDomForm.LocatorCellRow7Column5))); var expectedText = cellInRow5Column5.Text; - var gotWith = $"{ABOVE} {BELOW} {LEFT} {RIGHT} {ABOVE}"; + var gotWith = $"{Above} {Below} {Left} {Right} {Above}"; Assert.Multiple(() => { - Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, MessageError(gotWith, SELENIUM_RELATIVE)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, MessageError(gotWith, XPATH)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, MessageError(gotWith, WEB_ELEMENT)); - Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, MessageError(gotWith, AQUALITY_ELEMENT)); + Assert.AreEqual(expectedText, actualWebElementCellRaw3Column5GotBySeleniumRelative.Text, MessageError(gotWith, SeleniumRelative)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithByXpath.Text, MessageError(gotWith, Xpath)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithWebElement.Text, MessageError(gotWith, WebElement)); + Assert.AreEqual(expectedText, actualCellRaw3Column5GotWithAqualityElement.Text, MessageError(gotWith, AqualityElement)); }); } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs index 2dea9c68..4b71fbde 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs @@ -11,30 +11,30 @@ public ChallengingDomForm() : base(By.XPath("//h3[contains(text(),'Challenging D protected override string UrlPart => "challenging_dom"; - public static readonly string ELEMENT_NAME_ROW3_COLUMN5 = "Cell in row 3 column 5"; - public static string ELEMENT_NAME_ROW5_COLUMN5 = "Cell in row 5 column 5"; - public static string ELEMENT_NAME_ROW7_COLUMN5 = "Cell in row 7 column 5"; - public static string ELEMENT_NAME_ROW5_COLUMN7 = "Cell in row 5 column 7"; - public static string ELEMENT_NAME_ROW5_COLUMN3 = "Cell in row 5 column 3"; - public static string ELEMENT_NAME_ROW1_COLUMN1 = "Cell in row 1 column 1"; - public static string ELEMENT_NAME_ROW2_COLUMN1 = "Cell in row 2 column 1"; + public static readonly string ElementNameRow3Column5 = "Cell in row 3 column 5"; + public static readonly string ElementNameRow5Column5 = "Cell in row 5 column 5"; + public static readonly string ElementNameRow7Column5 = "Cell in row 7 column 5"; + public static readonly string ElementNameRow5Column7 = "Cell in row 5 column 7"; + public static readonly string ElementNameRow5Column3 = "Cell in row 5 column 3"; + public static readonly string ElementNameRow1Column1 = "Cell in row 1 column 1"; + public static readonly string ElementNameRow2Column1 = "Cell in row 2 column 1"; - public static readonly string locatorCellRow5Column5 = "//tr[5]/td[5]"; - public const string locatorCellRow1Column5 = "//tr[1]/td[5]"; - public const string locatorCellRow3Column5 = "//tr[3]/td[5]"; - public const string locatorCellRow7Column5 = "//tr[7]/td[5]"; - public const string locatorCellRow5Column3 = "//tr[5]/td[3]"; - public const string locatorCellRow5Column7 = "//tr[5]/td[7]"; - public const string locatorCellRow1Column1 = "//tr[1]/td[1]"; - public const string locatorCellRow2Column1 = "//tr[2]/td[1]"; + public static readonly string LocatorCellRow5Column5 = "//tr[5]/td[5]"; + public static readonly string LocatorCellRow1Column5 = "//tr[1]/td[5]"; + public static readonly string LocatorCellRow3Column5 = "//tr[3]/td[5]"; + public static readonly string LocatorCellRow7Column5 = "//tr[7]/td[5]"; + public static readonly string LocatorCellRow5Column3 = "//tr[5]/td[3]"; + public static readonly string LocatorCellRow5Column7 = "//tr[5]/td[7]"; + public static readonly string LocatorCellRow1Column1 = "//tr[1]/td[1]"; + public static readonly string LocatorCellRow2Column1 = "//tr[2]/td[1]"; - public ILabel CellInRow3Column5 => ElementFactory.GetLabel(By.XPath(locatorCellRow3Column5), ELEMENT_NAME_ROW3_COLUMN5); - public ILabel CellInRow5Column5 => ElementFactory.GetLabel(By.XPath(locatorCellRow5Column5), ELEMENT_NAME_ROW5_COLUMN5); - public ILabel CellInRow7Column5 => ElementFactory.GetLabel(By.XPath(locatorCellRow7Column5), ELEMENT_NAME_ROW7_COLUMN5); - public ILabel CellInRow5Column7 => ElementFactory.GetLabel(By.XPath(locatorCellRow5Column7), ELEMENT_NAME_ROW5_COLUMN7); - public ILabel CellInRow5Column3 => ElementFactory.GetLabel(By.XPath(locatorCellRow5Column3), ELEMENT_NAME_ROW5_COLUMN3); - public ILabel CellInRow1Column1 => ElementFactory.GetLabel(By.XPath(locatorCellRow1Column1), ELEMENT_NAME_ROW1_COLUMN1); - public ILabel CellInRow2Column1 => ElementFactory.GetLabel(By.XPath(locatorCellRow2Column1), ELEMENT_NAME_ROW2_COLUMN1); + public ILabel CellInRow3Column5 => ElementFactory.GetLabel(By.XPath(LocatorCellRow3Column5), ElementNameRow3Column5); + public ILabel CellInRow5Column5 => ElementFactory.GetLabel(By.XPath(LocatorCellRow5Column5), ElementNameRow5Column5); + public ILabel CellInRow7Column5 => ElementFactory.GetLabel(By.XPath(LocatorCellRow7Column5), ElementNameRow7Column5); + public ILabel CellInRow5Column7 => ElementFactory.GetLabel(By.XPath(LocatorCellRow5Column7), ElementNameRow5Column7); + public ILabel CellInRow5Column3 => ElementFactory.GetLabel(By.XPath(LocatorCellRow5Column3), ElementNameRow5Column3); + public ILabel CellInRow1Column1 => ElementFactory.GetLabel(By.XPath(LocatorCellRow1Column1), ElementNameRow1Column1); + public ILabel CellInRow2Column1 => ElementFactory.GetLabel(By.XPath(LocatorCellRow2Column1), ElementNameRow2Column1); } } From 3812911ee030415c73215daacdd85fa33b962394 Mon Sep 17 00:00:00 2001 From: Mikhail Pyshnik Date: Thu, 21 Dec 2023 19:44:40 +0300 Subject: [PATCH 10/12] Code was updated. Added Near for the RelativeBy. DataTablesForm class was added. --- .../Aquality.Selenium/Locators/RelativeBy.cs | 48 ++++++++++++++++++- .../TheInternet/Forms/DataTablesForm.cs | 45 +++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/DataTablesForm.cs diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs index a4dfa06b..32b7960b 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs @@ -17,6 +17,7 @@ public class RelativeBy : By, IRelativeBy, IRelativeWebElement, IRelativeAqualit private const string BELOW = "Below"; private const string LEFT = "LeftOf"; private const string RIGHT = "RightOf"; + private const string NEAR = "Near"; private RelativeBy() { } @@ -102,6 +103,24 @@ public RelativeBy Right(IElement element) return this; } + public RelativeBy Near(By by, int atMostDistanceInPixels = 50) + { + functions.Add(new Function(NEAR, new[] { by })); + return this; + } + + public RelativeBy Near(WebElement webElement, int atMostDistanceInPixels = 50) + { + functions.Add(new Function(NEAR, new[] { webElement })); + return this; + } + + public RelativeBy Near(IElement element, int atMostDistanceInPixels = 50) + { + functions.Add(new Function(NEAR, new[] { element.Locator })); + return this; + } + public override IWebElement FindElement(ISearchContext context) { return FindElements(context).First(); @@ -115,7 +134,6 @@ public override ReadOnlyCollection FindElements(ISearchContext cont { var firstArgument = function.Arguments.First(); var firstArgumentType = function.Arguments.First().GetType(); - switch (function.Name) { case ABOVE: @@ -138,9 +156,13 @@ public override ReadOnlyCollection FindElements(ISearchContext cont formedBy = GetRelativeWithRight(formedBy, firstArgument); break; + case NEAR: + + formedBy = GetRelativeWitNear(formedBy, firstArgument); + break; + default: throw new ArgumentException($"There is no realisation for [{function.Name}] function"); - } }); return context.FindElements(formedBy); @@ -233,6 +255,28 @@ private RelativeSeleniumBy GetRelativeWithLeft(RelativeSeleniumBy formedBy, obje throw new ArgumentException(ErrorMessageForType(typeArgument)); } + private RelativeSeleniumBy GetRelativeWitNear(RelativeSeleniumBy formedBy, object savedArgument) + { + var typeArgument = savedArgument.GetType(); + + if (typeArgument == typeof(WebElement)) + { + return formedBy.Near((WebElement)savedArgument); + } + + if (typeArgument == typeof(By)) + { + return formedBy.Near((By)savedArgument); + } + + if (typeArgument == typeof(IElement)) + { + return formedBy.Near(((IElement)savedArgument).Locator); + } + + throw new ArgumentException(ErrorMessageForType(typeArgument)); + } + private string ErrorMessageForType(Type typeArgument) => $"There is no realisation for [{typeArgument}] type"; } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/DataTablesForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/DataTablesForm.cs new file mode 100644 index 00000000..a5c83e21 --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/DataTablesForm.cs @@ -0,0 +1,45 @@ +using Aquality.Selenium.Elements.Interfaces; +using OpenQA.Selenium; + +namespace Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms +{ + internal class DataTablesForm : TheInternetForm + { + const string TABLE1_BODY = "//table[@id='table1']//tbody"; + + public DataTablesForm() : base(By.XPath("//h3[contains(text(),'Data Tables')]"), "Data Tables form") + { + } + protected override string UrlPart => "tables"; + + public static readonly string ElementNameRow4Column5 = "Cell in row 4 column 5"; + public static readonly string ElementNameRow4Column4 = "Cell in row 4 column 4"; + public static readonly string ElementNameRow4Column3 = "Cell in row 4 column 3"; + public static readonly string ElementNameRow4Column2 = "Cell in row 4 column 2"; + public static readonly string ElementNameRow3Column5 = "Cell in row 3 column 5"; + public static readonly string ElementNameRow2Column5 = "Cell in row 2 column 5"; + public static readonly string ElementNameRow2Column4 = "Cell in row 2 column 4"; + public static readonly string ElementNameRow2Column3 = "Cell in row 2 column 3"; + + public static readonly string LocatorCellRow4Column5 = $"{TABLE1_BODY}//tr[4]/td[5]"; + public static readonly string LocatorCellRow4Column4 = $"{TABLE1_BODY}//tr[4]/td[4]"; + public static readonly string LocatorCellRow4Column2 = $"{TABLE1_BODY}//tr[4]/td[2]"; + public static readonly string LocatorCellRow3Column5 = $"{TABLE1_BODY}//tr[3]/td[5]"; + public static readonly string LocatorCellRow4Column3 = $"{TABLE1_BODY}//tr[4]/td[3]"; + public static readonly string LocatorCellRow2Column5 = $"{TABLE1_BODY}//tr[2]/td[5]"; + public static readonly string LocatorCellRow2Column4 = $"{TABLE1_BODY}//tr[2]/td[4]"; + public static readonly string LocatorCellRow2Column3 = $"{TABLE1_BODY}//tr[2]/td[3]"; + + public static readonly string LocatorCellRow2Column2 = $"{TABLE1_BODY}//tr[2]/td[2]"; + public static readonly string LocatorCellRow2Column1 = $"{TABLE1_BODY}//tr[2]/td[1]"; + + public ILabel CellInRow4Column5 => ElementFactory.GetLabel(By.XPath(LocatorCellRow4Column5), ElementNameRow4Column5); + public ILabel CellInRow4Column4 => ElementFactory.GetLabel(By.XPath(LocatorCellRow4Column4), ElementNameRow4Column4); + public ILabel CellInRow4Column3 => ElementFactory.GetLabel(By.XPath(LocatorCellRow4Column3), ElementNameRow4Column3); + public ILabel CellInRow4Column2 => ElementFactory.GetLabel(By.XPath(LocatorCellRow4Column2), ElementNameRow4Column2); + public ILabel CellInRow3Column5 => ElementFactory.GetLabel(By.XPath(LocatorCellRow3Column5), ElementNameRow3Column5); + public ILabel CellInRow2Column5 => ElementFactory.GetLabel(By.XPath(LocatorCellRow2Column5), ElementNameRow2Column5); + public ILabel CellInRow2Column4 => ElementFactory.GetLabel(By.XPath(LocatorCellRow2Column4), ElementNameRow2Column4); + public ILabel CellInRow2Column3 => ElementFactory.GetLabel(By.XPath(LocatorCellRow2Column3), ElementNameRow2Column3); + } +} From a96c1967b40baa45c41a51b26baeffb1f576855c Mon Sep 17 00:00:00 2001 From: Mikhail Pyshnik Date: Fri, 26 Jan 2024 15:59:07 +0300 Subject: [PATCH 11/12] * The old implementation has been removed for relative locators; * A custom page has been added for testing relative locators; * A new interface and implementation class has been created for working with relative locators; --- .../Aquality.Selenium.csproj | 2 +- .../Enums/RelativeAqualityLocators.cs | 11 + .../Aquality.Selenium/Locators/Function.cs | 16 -- .../Locators/IRelativeAquality.cs | 29 +++ .../Locators/IRelativeAqualityElement.cs | 12 -- .../Aquality.Selenium/Locators/IRelativeBy.cs | 12 -- .../Locators/IRelativeWebElement.cs | 12 -- .../{RelativeBy.cs => RelativeAqualityBy.cs} | 140 +++++++------ .../Aquality.Selenium.Tests.csproj | 3 + .../RelativeLocatorsForCustomFormTests.cs | 196 ++++++++++++++++++ .../Integration/RelativeLocatorsTests.cs | 44 ++-- .../Forms/LoginForm - Copy.cs | 128 ++++++++++++ .../Forms/LoginForm.cs | 59 ++++++ .../TheInternet/Forms/ChallengingDomForm.cs | 2 +- .../TestApp/a1qa/Forms/ContactUsForm.cs | 39 ++++ .../TestApp/a1qa/Forms/TheA1qaForm.cs | 26 +++ .../LoginFormForRelativeLocators.html | 120 +++++++++++ 17 files changed, 706 insertions(+), 145 deletions(-) create mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/Enums/RelativeAqualityLocators.cs delete mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs create mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAquality.cs delete mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAqualityElement.cs delete mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeBy.cs delete mode 100644 Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeWebElement.cs rename Aquality.Selenium/src/Aquality.Selenium/Locators/{RelativeBy.cs => RelativeAqualityBy.cs} (52%) create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsForCustomFormTests.cs create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm - Copy.cs create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm.cs create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/ContactUsForm.cs create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/TheA1qaForm.cs create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Resources/LoginFormForRelativeLocators.html diff --git a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj index 4e55943b..e8058276 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj +++ b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj @@ -76,7 +76,7 @@ - + diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/Enums/RelativeAqualityLocators.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/Enums/RelativeAqualityLocators.cs new file mode 100644 index 00000000..e1f1ef35 --- /dev/null +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/Enums/RelativeAqualityLocators.cs @@ -0,0 +1,11 @@ +namespace Aquality.Selenium.Locators.Enums +{ + public enum RelativeAqualityLocators + { + Above, + Below, + Left, + Right, + Near, + } +} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs deleted file mode 100644 index 311132af..00000000 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/Function.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Aquality.Selenium.Locators -{ - internal class Function - { - public string Name { get; } - public object[] Arguments { get; } - - private Function() { } - - public Function(string name, object[] arguments) - { - Name = name; - Arguments = arguments; - } - } -} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAquality.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAquality.cs new file mode 100644 index 00000000..032aaa7f --- /dev/null +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAquality.cs @@ -0,0 +1,29 @@ +using OpenQA.Selenium; +using Aquality.Selenium.Core.Elements.Interfaces; + +namespace Aquality.Selenium.Locators +{ + internal interface IRelativeAquality + { + RelativeAqualityBy Above(By by); + RelativeAqualityBy Below(By by); + RelativeAqualityBy Left(By by); + RelativeAqualityBy Right(By by); + RelativeAqualityBy Near(By by); + RelativeAqualityBy Near(By by, int atMostDistanceInPixels); + + RelativeAqualityBy Above(IElement element); + RelativeAqualityBy Below(IElement element); + RelativeAqualityBy Left(IElement element); + RelativeAqualityBy Right(IElement elementy); + RelativeAqualityBy Near(IElement element); + RelativeAqualityBy Near(IElement element, int atMostDistanceInPixels); + + RelativeAqualityBy Above(WebElement webElement); + RelativeAqualityBy Below(WebElement webElement); + RelativeAqualityBy Left(WebElement webElement); + RelativeAqualityBy Right(WebElement webElement); + RelativeAqualityBy Near(WebElement webElement); + RelativeAqualityBy Near(WebElement webElement, int atMostDistanceInPixels); + } +} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAqualityElement.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAqualityElement.cs deleted file mode 100644 index c895d66d..00000000 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeAqualityElement.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Aquality.Selenium.Core.Elements.Interfaces; - -namespace Aquality.Selenium.Locators -{ - internal interface IRelativeAqualityElement - { - RelativeBy Above(IElement by); - RelativeBy Below(IElement by); - RelativeBy Left(IElement by); - RelativeBy Right(IElement by); - } -} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeBy.cs deleted file mode 100644 index ee69558b..00000000 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeBy.cs +++ /dev/null @@ -1,12 +0,0 @@ -using OpenQA.Selenium; - -namespace Aquality.Selenium.Locators -{ - internal interface IRelativeBy - { - RelativeBy Above(By by); - RelativeBy Below(By by); - RelativeBy Left(By by); - RelativeBy Right(By by); - } -} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeWebElement.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeWebElement.cs deleted file mode 100644 index c42a0187..00000000 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/IRelativeWebElement.cs +++ /dev/null @@ -1,12 +0,0 @@ -using OpenQA.Selenium; - -namespace Aquality.Selenium.Locators -{ - internal interface IRelativeWebElement - { - RelativeBy Above(WebElement by); - RelativeBy Below(WebElement by); - RelativeBy Left(WebElement by); - RelativeBy Right(WebElement by); - } -} diff --git a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeAqualityBy.cs similarity index 52% rename from Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs rename to Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeAqualityBy.cs index 32b7960b..f27f8cb2 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeBy.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Locators/RelativeAqualityBy.cs @@ -5,168 +5,173 @@ using System; using System.Collections.Generic; using System.Linq; +using Aquality.Selenium.Locators.Enums; namespace Aquality.Selenium.Locators { - public class RelativeBy : By, IRelativeBy, IRelativeWebElement, IRelativeAqualityElement + public class RelativeAqualityBy : RelativeSeleniumBy, IRelativeAquality { private readonly By by; - private readonly List functions = new List(); + private readonly List> relativePairs = new List>(); - private const string ABOVE = "Above"; - private const string BELOW = "Below"; - private const string LEFT = "LeftOf"; - private const string RIGHT = "RightOf"; - private const string NEAR = "Near"; + private const int DEFAULT_VALUE_IN_PIXELS_FOR_THE_NEAR_LOCATOR = 50; - private RelativeBy() { } - - private RelativeBy(By by) + private RelativeAqualityBy(By by) { this.by = by; } - public static RelativeBy WithLocator(By by) + public static RelativeAqualityBy WithLocator(By by) { - return new RelativeBy(by); + return new RelativeAqualityBy(by); } - public RelativeBy Above(By by) + public RelativeAqualityBy Above(By by) { - functions.Add(new Function(ABOVE, new[] { by })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Above, new[] { by })); return this; } - public RelativeBy Above(WebElement webElement) + public RelativeAqualityBy Above(WebElement webElement) { - functions.Add(new Function(ABOVE, new[] { webElement })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Above, new[] { webElement })); return this; } - public RelativeBy Above(IElement element) + public RelativeAqualityBy Above(IElement element) { - functions.Add(new Function(ABOVE, new[] { element.Locator })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Above, new[] { element.Locator })); return this; } - public RelativeBy Below(By by) + public RelativeAqualityBy Below(By by) { - functions.Add(new Function(BELOW, new[] { by })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Below, new[] { by })); return this; } - public RelativeBy Below(WebElement webElement) + public RelativeAqualityBy Below(WebElement webElement) { - functions.Add(new Function(BELOW, new[] { webElement })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Below, new[] { webElement })); return this; } - public RelativeBy Below(IElement element) + public RelativeAqualityBy Below(IElement element) { - functions.Add(new Function(BELOW, new[] { element.Locator })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Below, new[] { element.Locator })); return this; } - public RelativeBy Left(By by) + public RelativeAqualityBy Left(By by) { - functions.Add(new Function(LEFT, new[] { by })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Left, new[] { by })); return this; } - public RelativeBy Left(WebElement webElement) + public RelativeAqualityBy Left(WebElement webElement) { - functions.Add(new Function(LEFT, new[] { webElement })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Left, new[] { webElement })); return this; } - public RelativeBy Left(IElement element) + public RelativeAqualityBy Left(IElement element) { - functions.Add(new Function(LEFT, new[] { element.Locator })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Left, new[] { element.Locator })); return this; } - public RelativeBy Right(By by) + public RelativeAqualityBy Right(By by) { - functions.Add(new Function(RIGHT, new[] { by })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Right, new[] { by })); return this; } - public RelativeBy Right(WebElement webElement) + public RelativeAqualityBy Right(WebElement webElement) { - functions.Add(new Function(RIGHT, new[] { webElement })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Right, new[] { webElement })); return this; } - public RelativeBy Right(IElement element) + public RelativeAqualityBy Right(IElement element) { - functions.Add(new Function(RIGHT, new[] { element.Locator })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Right, new[] { element.Locator })); return this; } - public RelativeBy Near(By by, int atMostDistanceInPixels = 50) + public RelativeAqualityBy Near(By by) { - functions.Add(new Function(NEAR, new[] { by })); - return this; + return Near(by, DEFAULT_VALUE_IN_PIXELS_FOR_THE_NEAR_LOCATOR); + } + + public RelativeAqualityBy Near(WebElement webElement) + { + return Near(webElement, DEFAULT_VALUE_IN_PIXELS_FOR_THE_NEAR_LOCATOR); + } + + public RelativeAqualityBy Near(IElement element) + { + return Near(element, DEFAULT_VALUE_IN_PIXELS_FOR_THE_NEAR_LOCATOR); } - public RelativeBy Near(WebElement webElement, int atMostDistanceInPixels = 50) + public RelativeAqualityBy Near(By by, int atMostDistanceInPixels) { - functions.Add(new Function(NEAR, new[] { webElement })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Near, new object[] { by, atMostDistanceInPixels })); return this; } - public RelativeBy Near(IElement element, int atMostDistanceInPixels = 50) + public RelativeAqualityBy Near(WebElement webElement, int atMostDistanceInPixels) { - functions.Add(new Function(NEAR, new[] { element.Locator })); + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Near, new object[] { webElement, atMostDistanceInPixels })); return this; } + public RelativeAqualityBy Near(IElement element, int atMostDistanceInPixels) + { + relativePairs.Add(new KeyValuePair(RelativeAqualityLocators.Near, new object[] { element.Locator, atMostDistanceInPixels })); + return this; + } + //TODO! public override IWebElement FindElement(ISearchContext context) { return FindElements(context).First(); } - + //TODO! public override ReadOnlyCollection FindElements(ISearchContext context) { RelativeSeleniumBy formedBy = RelativeSeleniumBy.WithLocator(by); - functions.ForEach(function => + relativePairs.ForEach(relativePair => { - var firstArgument = function.Arguments.First(); - var firstArgumentType = function.Arguments.First().GetType(); - switch (function.Name) + var firstArgument = relativePair.Value[0]; + switch (relativePair.Key) { - case ABOVE: - + case RelativeAqualityLocators.Above: formedBy = GetRelativeWithAbove(formedBy, firstArgument); break; - case BELOW: - + case RelativeAqualityLocators.Below: formedBy = GetRelativeWithBelow(formedBy, firstArgument); break; - case LEFT: - + case RelativeAqualityLocators.Left: formedBy = GetRelativeWithLeft(formedBy, firstArgument); break; - case RIGHT: - + case RelativeAqualityLocators.Right: formedBy = GetRelativeWithRight(formedBy, firstArgument); break; - case NEAR: - - formedBy = GetRelativeWitNear(formedBy, firstArgument); + case RelativeAqualityLocators.Near: + formedBy = GetRelativeWitNear(formedBy, relativePair.Value[0], (int)relativePair.Value[1]); break; default: - throw new ArgumentException($"There is no realisation for [{function.Name}] function"); + throw new ArgumentException($"There is no realisation for [{relativePair.Key}] function"); } }); return context.FindElements(formedBy); } + private RelativeSeleniumBy GetRelativeWithAbove(RelativeSeleniumBy formedBy, object savedArgument) { var typeArgument = savedArgument.GetType(); @@ -255,23 +260,20 @@ private RelativeSeleniumBy GetRelativeWithLeft(RelativeSeleniumBy formedBy, obje throw new ArgumentException(ErrorMessageForType(typeArgument)); } - private RelativeSeleniumBy GetRelativeWitNear(RelativeSeleniumBy formedBy, object savedArgument) + private RelativeSeleniumBy GetRelativeWitNear(RelativeSeleniumBy formedBy, object locator, int valueInPixelsForTheNearLocator) { - var typeArgument = savedArgument.GetType(); - + var typeArgument = locator.GetType(); if (typeArgument == typeof(WebElement)) - { - return formedBy.Near((WebElement)savedArgument); + { + return formedBy.Near((WebElement)locator, valueInPixelsForTheNearLocator); } - if (typeArgument == typeof(By)) { - return formedBy.Near((By)savedArgument); + return formedBy.Near((By)locator, valueInPixelsForTheNearLocator); } - if (typeArgument == typeof(IElement)) { - return formedBy.Near(((IElement)savedArgument).Locator); + return formedBy.Near(((IElement)locator).Locator, valueInPixelsForTheNearLocator); } throw new ArgumentException(ErrorMessageForType(typeArgument)); diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj index dca650e4..0ff98302 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj @@ -42,6 +42,9 @@ + + Always + Always diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsForCustomFormTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsForCustomFormTests.cs new file mode 100644 index 00000000..a1561c38 --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsForCustomFormTests.cs @@ -0,0 +1,196 @@ +using Aquality.Selenium.Browsers; +using NUnit.Framework; +using Aquality.Selenium.Elements.Interfaces; +using Aquality.Selenium.Locators; +using By = OpenQA.Selenium.By; +using Aquality.Selenium.Tests.Integration.TestApp.LoginFormForRelativeLocators.Forms; +using OpenQA.Selenium; + +namespace Aquality.Selenium.Tests.Integration +{ + internal class RelativeLocatorsForCustomFormTests : UITest + { + private readonly LoginForm loginForm = new(); + private const string buttonLocator = "//button"; + private const string inputLocator = "//input"; + + private static IElementFactory ElementFactory => AqualityServices.Get(); + private const string Above = "above"; + private const string Below = "below"; + private const string Left = "left"; + private const string Right = "right"; + private const string Near = "near"; + private const string SeleniumRelative = "selenium relative"; + private const string Xpath = "xpath"; + private const string WebElement = "web element"; + private const string AqualityElement = "aquality element"; + + private static string MessageError(string gotWith, string gotBy) => $"Text of element got with [{gotWith}] by [{gotBy}] is not expected"; + private static string МessageForInputField(string logicKey) => $"Message text with key - [{logicKey}]"; + + [SetUp] + public void Before() + { + loginForm.Open(); + } + + [Test] + public void Should_BePossibleTo_AboveWithDifferentParametersType() + { + var userNameTextBox = loginForm.UserNameTextBox; + userNameTextBox.SendKeys(МessageForInputField("UserName")); + var universityTextBox = loginForm.UniversityTextBox; + + var actualUniversityTextBoxGotWithByXpath = + ElementFactory.GetTextBox(RelativeAqualityBy + .WithLocator(By.XPath(inputLocator)) + .Above(By.XPath(LoginForm.IdLocatorUniversityTextBox)), + LoginForm.ElementNameUserNameTextBox); + + var actualUniversityTextBoxGotWithWebElement = + ElementFactory.GetTextBox(RelativeAqualityBy + .WithLocator(By.XPath(inputLocator)) + .Above(universityTextBox.GetElement()), + LoginForm.ElementNameUserNameTextBox); + + var actualUniversityTextBoxGotWithAqualityElement = + ElementFactory.GetTextBox(RelativeAqualityBy.WithLocator(By.XPath(inputLocator)).Above(universityTextBox), + LoginForm.ElementNameUserNameTextBox); + + var actualWebElementUniversityTextBoxGotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeBy + .WithLocator(By.XPath(inputLocator)) + .Above(By.XPath(LoginForm.IdLocatorUniversityTextBox))); + + var expectedText = userNameTextBox.Value; + var _expectedText = actualWebElementUniversityTextBoxGotBySeleniumRelative.GetAttribute("value"); + + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualUniversityTextBoxGotWithByXpath.Value, MessageError(Above, SeleniumRelative)); + Assert.AreEqual(expectedText, actualUniversityTextBoxGotWithWebElement.Value, MessageError(Above, Xpath)); + Assert.AreEqual(expectedText, actualUniversityTextBoxGotWithAqualityElement.Value, MessageError(Above, WebElement)); + Assert.AreEqual(expectedText, actualWebElementUniversityTextBoxGotBySeleniumRelative.GetAttribute("value"), MessageError(Above, AqualityElement)); + }); + } + + [Test] + public void Should_BePossibleTo_BelowWithDifferentParametersType() + { + var userNameTextBox = loginForm.UserNameTextBox; + var universityTextBox = loginForm.UniversityTextBox; + universityTextBox.SendKeys(МessageForInputField("University")); + + var actualUniversityTextBoxGotWithByXpath = + ElementFactory.GetTextBox(RelativeAqualityBy + .WithLocator(By.XPath(inputLocator)) + .Below(By.XPath(LoginForm.IdLocatorUserNameTextBox)), + LoginForm.ElementNameUniversityTextBox); + + var actualUniversityTextBoxGotWithWebElement = + ElementFactory.GetTextBox(RelativeAqualityBy + .WithLocator(By.XPath(inputLocator)) + .Below(userNameTextBox.GetElement()), + LoginForm.ElementNameUniversityTextBox); + + var actualUniversityTextBoxGotWithAqualityElement = + ElementFactory.GetTextBox(RelativeAqualityBy.WithLocator(By.XPath(inputLocator)).Below(userNameTextBox), + LoginForm.ElementNameUniversityTextBox); + + var actualWebElementUniversityTextBoxGotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeBy + .WithLocator(By.XPath(inputLocator)) + .Below(By.XPath(LoginForm.IdLocatorUserNameTextBox))); + + var expectedText = universityTextBox.Value; + + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualUniversityTextBoxGotWithByXpath.Value, MessageError(Below, Xpath )); + Assert.AreEqual(expectedText, actualUniversityTextBoxGotWithWebElement.Value, MessageError(Below, WebElement)); + Assert.AreEqual(expectedText, actualUniversityTextBoxGotWithAqualityElement.Value, MessageError(Below, AqualityElement)); + Assert.AreEqual(expectedText, actualWebElementUniversityTextBoxGotBySeleniumRelative.GetAttribute("value"), MessageError(Below, SeleniumRelative)); + }); + } + + [Test] + public void Should_BePossibleTo_LeftWithDifferentParametersType() + { + var loginButton = loginForm.LoginButton; + var cancelButton = loginForm.CancelButton; + + var actualLoginButtonGotWithByXpath = + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(buttonLocator)) + .Left(By.XPath(LoginForm.IdLocatorCancelButton)), "actualLoginButtonGotWithByXpath"); + + var actualLoginButtonGotWithWebElement = + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(buttonLocator)) + .Left(cancelButton.GetElement()), "actualLoginButtonGotWithWebElemen"); + + var actualLoginButtonGotWithAqualityElement = + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(buttonLocator)) + .Left(cancelButton), "actualLoginButtonGotWithAqualityElement"); + + var actualWebElementLoginButtonGotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeBy + .WithLocator(By.XPath(buttonLocator)) + .LeftOf(By.XPath(LoginForm.IdLocatorCancelButton))); + + var expectedText = loginButton.Text; + + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualLoginButtonGotWithByXpath.Text, MessageError(Left, SeleniumRelative)); + Assert.AreEqual(expectedText, actualLoginButtonGotWithWebElement.Text, MessageError(Left, Xpath)); + Assert.AreEqual(expectedText, actualLoginButtonGotWithAqualityElement.Text, MessageError(Left, WebElement)); + Assert.AreEqual(expectedText, actualWebElementLoginButtonGotBySeleniumRelative.Text, MessageError(Left, AqualityElement)); + }); + } + + [Test] + public void Should_BePossibleTo_RightWithDifferentParametersType() + { + var loginButton = loginForm.LoginButton; + var cancelButton = loginForm.CancelButton; + + var actualLoginButtonGotWithByXpath = + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(buttonLocator)) + .Right(By.XPath(LoginForm.IdLocatorLoginButton)), "actualCancelButtonGotWithByXpath"); + + var actualLoginButtonGotWithWebElement = + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(buttonLocator)) + .Right(loginButton.GetElement()), "actualCancelButtonGotWithWebElemen"); + + var actualLoginButtonGotWithAqualityElement = + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(buttonLocator)) + .Right(loginButton), "actualCancelButtonGotWithAqualityElement"); + + var actualWebElementLoginButtonGotBySeleniumRelative = + AqualityServices.Browser.Driver.FindElement(RelativeBy + .WithLocator(By.XPath(buttonLocator)) + .RightOf(By.XPath(LoginForm.IdLocatorLoginButton))); + + var expectedText = cancelButton.Text; + + Assert.Multiple(() => + { + Assert.AreEqual(expectedText, actualLoginButtonGotWithByXpath.Text, MessageError(Right, SeleniumRelative)); + Assert.AreEqual(expectedText, actualLoginButtonGotWithWebElement.Text, MessageError(Right, Xpath)); + Assert.AreEqual(expectedText, actualLoginButtonGotWithAqualityElement.Text, MessageError(Right, WebElement)); + Assert.AreEqual(expectedText, actualWebElementLoginButtonGotBySeleniumRelative.Text, MessageError(Right, AqualityElement)); + }); + } + + [Test] + public void Should_BePossibleTo_NearWithDifferentParametersType() + { + //TODO! + } + + [Test] + public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParametersType() + { + //TODO! + } + } +} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs index 4fcba6b1..8339e367 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/RelativeLocatorsTests.cs @@ -2,13 +2,13 @@ using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms; using NUnit.Framework; using Aquality.Selenium.Elements.Interfaces; -using RelativeSeleniumBy = OpenQA.Selenium.RelativeBy; using Aquality.Selenium.Locators; using By = OpenQA.Selenium.By; +using OpenQA.Selenium; namespace Aquality.Selenium.Tests.Integration { - internal class RelativeLocatorsTests : UITest + internal class RelativeLocatorsTests : UITest //TODO! This code should be removed during refactoring { private readonly ChallengingDomForm challengingDomForm = new ChallengingDomForm(); private const string labelLocatorCell = "//td"; @@ -37,23 +37,23 @@ public void Should_BePossibleTo_AboveWithDifferentParametersType() var cellInRow3Column5 = challengingDomForm.CellInRow3Column5; var actualCellRaw3Column5GotWithByXpath = - ElementFactory.GetLabel(RelativeBy + ElementFactory.GetLabel(RelativeAqualityBy .WithLocator(By.XPath(labelLocatorCell)) .Above(By.XPath(ChallengingDomForm.LocatorCellRow5Column5)), ChallengingDomForm.ElementNameRow5Column5); var actualCellRaw3Column5GotWithWebElement = - ElementFactory.GetLabel(RelativeBy + ElementFactory.GetLabel(RelativeAqualityBy .WithLocator(By.XPath(labelLocatorCell)) .Above(cellInRow5Column5.GetElement()), ChallengingDomForm.ElementNameRow3Column5); var actualCellRaw3Column5GotWithAqualityElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)).Above(cellInRow5Column5), + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)).Above(cellInRow5Column5), ChallengingDomForm.ElementNameRow3Column5); var actualWebElementCellRaw3Column5GotBySeleniumRelative = - AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + AqualityServices.Browser.Driver.FindElement(RelativeBy .WithLocator(By.XPath(labelLocatorCell)) .Above(By.XPath(ChallengingDomForm.LocatorCellRow5Column5))); @@ -75,19 +75,19 @@ public void Should_BePossibleTo_BelowWithDifferentParametersType() var cellInRow7Column5 = challengingDomForm.CellInRow7Column5; var actualCellRaw7Column5GotWithByXpath = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Below(By.XPath(ChallengingDomForm.LocatorCellRow5Column5)), ChallengingDomForm.ElementNameRow7Column5); var actualCellRaw7Column5GotWithWebElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Below(cellInRow5Column5.GetElement()), ChallengingDomForm.ElementNameRow7Column5); var actualCellRaw7Column5GotWithAqualityElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Below(cellInRow5Column5), ChallengingDomForm.ElementNameRow7Column5); var actualWebElementCellRaw7Column5GotBySeleniumRelative = - AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + AqualityServices.Browser.Driver.FindElement(RelativeBy .WithLocator(By.XPath(labelLocatorCell)) .Below(By.XPath(ChallengingDomForm.LocatorCellRow5Column5))); @@ -109,19 +109,19 @@ public void Should_BePossibleTo_LeftWithDifferentParametersType() var cellInRow5Column3 = challengingDomForm.CellInRow5Column3; var actualCellRaw5Column3GotWithByXpath = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Left(By.XPath(ChallengingDomForm.LocatorCellRow5Column5)), ChallengingDomForm.ElementNameRow5Column3); var actualCellRaw5Column3GotWithWebElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Left(cellInRow5Column5.GetElement()), ChallengingDomForm.ElementNameRow5Column3); var actualCellRaw5Column3GotWithAqualityElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Left(cellInRow5Column5), ChallengingDomForm.ElementNameRow5Column3); var actualWebElementCellRaw5Column3GotBySeleniumRelative = - AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + AqualityServices.Browser.Driver.FindElement(RelativeBy .WithLocator(By.XPath(labelLocatorCell)) .LeftOf(By.XPath(ChallengingDomForm.LocatorCellRow5Column5))); @@ -143,19 +143,19 @@ public void Should_BePossibleTo_RightWithDifferentParametersType() var cellInRow5Column7 = challengingDomForm.CellInRow5Column7; var actualCellRaw5Column7GotWithByXpath = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Right(By.XPath(ChallengingDomForm.LocatorCellRow5Column5)), ChallengingDomForm.ElementNameRow5Column7); var actualCellRaw5Column7GotWithWebElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Right(cellInRow5Column5.GetElement()), ChallengingDomForm.ElementNameRow5Column7); var actualCellRaw5Column7GotWithAqualityElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Right(cellInRow5Column5), ChallengingDomForm.ElementNameRow5Column7); var actualWebElementCellRaw5Column7GotBySeleniumRelative = - AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + AqualityServices.Browser.Driver.FindElement(RelativeBy .WithLocator(By.XPath(labelLocatorCell)) .RightOf(By.XPath(ChallengingDomForm.LocatorCellRow5Column5))); @@ -180,7 +180,7 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters var cellInRow7Column5 = challengingDomForm.CellInRow7Column5; var actualCellRaw3Column5GotWithByXpath = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Above(By.XPath(ChallengingDomForm.LocatorCellRow7Column5)) .Below(By.XPath(ChallengingDomForm.LocatorCellRow3Column5)) .Left(By.XPath(ChallengingDomForm.LocatorCellRow5Column7)) @@ -189,7 +189,7 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters , ChallengingDomForm.ElementNameRow3Column5); var actualCellRaw3Column5GotWithWebElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Above(cellInRow7Column5.GetElement()) .Below(cellInRow3Column5.GetElement()) .Left(cellInRow5Column7.GetElement()) @@ -198,7 +198,7 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters , ChallengingDomForm.ElementNameRow3Column5); var actualCellRaw3Column5GotWithAqualityElement = - ElementFactory.GetLabel(RelativeBy.WithLocator(By.XPath(labelLocatorCell)) + ElementFactory.GetLabel(RelativeAqualityBy.WithLocator(By.XPath(labelLocatorCell)) .Above(cellInRow7Column5) .Below(cellInRow3Column5) .Left(cellInRow5Column7) @@ -207,7 +207,7 @@ public void Should_BePossibleTo_AboveBelowLeftWrightAboveWithDifferentParameters , ChallengingDomForm.ElementNameRow3Column5); var actualWebElementCellRaw3Column5GotBySeleniumRelative = - AqualityServices.Browser.Driver.FindElement(RelativeSeleniumBy + AqualityServices.Browser.Driver.FindElement(RelativeBy .WithLocator(By.XPath(labelLocatorCell)) .Above(By.XPath(ChallengingDomForm.LocatorCellRow7Column5)) .Below(By.XPath(ChallengingDomForm.LocatorCellRow3Column5)) diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm - Copy.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm - Copy.cs new file mode 100644 index 00000000..e438cfa4 --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm - Copy.cs @@ -0,0 +1,128 @@ +using AngleSharp.Dom; +using Aquality.Selenium.Browsers; +using Aquality.Selenium.Elements.Interfaces; +using Aquality.Selenium.Forms; +using OpenQA.Selenium; + + +namespace Aquality.Selenium.Tests.Integration.TestApp.LoginFormForRelativeLocators.Forms +{ + internal class LoginForm1 : Form + { + private const string BaseUrl = "C:\\a1qa\\GitHub_repos\\aquality-selenium-dotnet\\Aquality.Selenium\\tests\\Aquality.Selenium.Tests\\bin\\Debug\\net6.0\\Resources\\LoginFormForRelativeLocators.html"; + public LoginForm1() : base(By.XPath("//h1[contains(text(),'Student Login Form')]"), "Login form") + { + } + + public string Url => BaseUrl; + + public void Open() + { + AqualityServices.Browser.GoTo($"file://{BaseUrl}"); + AqualityServices.Browser.WaitForPageToLoad(); + AqualityServices.Browser.Maximize(); + } + // public static readonly string LocatorCommentTextBox = "//textarea[@id='your-message']";

Student Login Form

+ + private static string ElementNameText(string idName, string typeOfElement) => $"[{idName}] {typeOfElement}" ; + + //private readonly string LabelText = "label"; + private readonly string TextBoxText = "text box"; + private readonly string ButtonText = "button"; + + public static readonly string IdLocatorUserNameTextBox = "name"; //"//input[@id='name']"; + public static readonly string IdLocatorStudentSurnameTextBox = "surname"; + public static readonly string IdLocatorPasswordTextBox = "password"; + public static readonly string IdLocatorUniversityTextBox = "university"; + public static readonly string IdLocatorFacultyTextBox = "faculty"; + public static readonly string IdLocatorSpecializationTextBox = "specialization"; + public static readonly string IdLocatorUniversityAddressTextBox = "university-address"; // address of the university + public static readonly string IdLocatorHomeAddressTextBox = "home-address"; + public static readonly string IdLocatorPhoneNumberTextBox = "phone-number"; + + + public static readonly string IdLocatorLoginButton = "submit-btn"; + public static readonly string IdLocatorCancelButton = "cancel-btn"; + + //public ILabel FormHeaderLabel => ElementFactory.GetLabel(By.Id(IdLocatorUserNameTextBox), ElementNameText(IdLocatorUserNameTextBox, LabelText)); + + public ITextBox NameTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorUserNameTextBox), ElementNameText(IdLocatorUserNameTextBox, TextBoxText)); + public ITextBox SurnameTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorStudentSurnameTextBox), ElementNameText(IdLocatorStudentSurnameTextBox, TextBoxText)); + public ITextBox PasswordTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorPasswordTextBox), ElementNameText(IdLocatorPasswordTextBox, TextBoxText)); + public ITextBox UniversityTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorUniversityTextBox), ElementNameText(IdLocatorUniversityTextBox, TextBoxText)); + public ITextBox FacultyTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorFacultyTextBox), ElementNameText(IdLocatorFacultyTextBox, TextBoxText)); + public ITextBox SpecializationTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorSpecializationTextBox), ElementNameText(IdLocatorSpecializationTextBox, TextBoxText)); + public ITextBox UniversityAddressTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorUniversityAddressTextBox), ElementNameText(IdLocatorUniversityAddressTextBox, TextBoxText)); + public ITextBox HomeAddressTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorHomeAddressTextBox), ElementNameText(IdLocatorHomeAddressTextBox, TextBoxText)); + public ITextBox PhoneNumberTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorPhoneNumberTextBox), ElementNameText(IdLocatorPhoneNumberTextBox, TextBoxText)); + + public IButton LoginButton => ElementFactory.GetButton(By.Id(IdLocatorLoginButton), ElementNameText(IdLocatorPhoneNumberTextBox, ButtonText)); + public IButton CancelButton => ElementFactory.GetButton(By.Id(IdLocatorCancelButton), ElementNameText(IdLocatorPhoneNumberTextBox, ButtonText)); + + /* + public ICheckBox PrivacyCheckBox => ElementFactory.GetCheckBox(By.XPath("//input[@name='privacy']/following-sibling::span[1]"), "Privacy"); + public IButton SendButton => ElementFactory.GetButton(By.XPath("//div[contains(@class,'contactsForm__submit')]//button"), "Send a message"); + public ILabel EmailAlertLabel => ElementFactory.GetLabel(By.XPath("//div[contains(@class,'error')]//input[@id='your-email']"), "Email validating message"); + public ILabel TitleLabel => FormElement.FindChildElement(By.XPath("//h2[contains(@class,'blockTitle')]"), "Title"); + public ILabel TermsLabel => FormElement.FindChildElement(By.XPath("//label[contains(@class, 'checkbox')]"), "Terms"); + */ + } + + /* + internal abstract class TheA1qaForm : Form + { + private const string BaseUrl = "https://www.a1qa.com/"; + + protected TheA1qaForm(By locator, string name) : base(locator, name) + { + } + + protected abstract string UrlPart { get; } + + public string Url => BaseUrl + UrlPart; + + public void Open() + { + AqualityServices.Browser.GoTo(Url); + AqualityServices.Browser.WaitForPageToLoad(); + AqualityServices.Browser.Maximize(); + } + } + */ + + /* + internal class ContactUsForm : TheA1qaForm + { + public ContactUsForm() : base(By.XPath("//h3[contains(text(),'Data Tables')]"), "Data Tables form") + { + } + protected override string UrlPart => "contacts/"; + + public static readonly string ElementNameNameTextBox = "Name text box"; + public static readonly string ElementNameCompanyTextBox = "Company text box"; + public static readonly string ElementNameEmailTextBox = "Email text box"; + public static readonly string ElementNamePhoneTextBox = "Phone text box"; + public static readonly string ElementNameCommentTextBox = "Comment text box"; + + public static readonly string LocatorNameTextBox = "//input[@id='your-name']"; + public static readonly string LocatorCompanyTextBox = "//input[@id='your-company']"; + public static readonly string LocatorEmailTextBox = "//input[@id='your-email']"; + public static readonly string LocatorPhoneTextBox = "//input[@id='your-phone']"; + public static readonly string LocatorCommentTextBox = "//textarea[@id='your-message']"; + + public ITextBox NameTextBox => ElementFactory.GetTextBox(By.XPath(LocatorNameTextBox), ElementNameNameTextBox); + public ITextBox CompanyTextBox => ElementFactory.GetTextBox(By.XPath(LocatorCompanyTextBox), ElementNameCompanyTextBox); + public ITextBox EmailTextBox => ElementFactory.GetTextBox(By.XPath(LocatorEmailTextBox), ElementNameEmailTextBox); + public ITextBox PhoneTextBox => ElementFactory.GetTextBox(By.XPath(LocatorPhoneTextBox), ElementNamePhoneTextBox); + public ITextBox CommentTextBox => ElementFactory.GetTextBox(By.XPath(LocatorCommentTextBox), ElementNameCommentTextBox); + + public ICheckBox PrivacyCheckBox => ElementFactory.GetCheckBox(By.XPath("//input[@name='privacy']/following-sibling::span[1]"), "Privacy"); + public IButton SendButton => ElementFactory.GetButton(By.XPath("//div[contains(@class,'contactsForm__submit')]//button"), "Send a message"); + public ILabel EmailAlertLabel => ElementFactory.GetLabel(By.XPath("//div[contains(@class,'error')]//input[@id='your-email']"), "Email validating message"); + public ILabel TitleLabel => FormElement.FindChildElement(By.XPath("//h2[contains(@class,'blockTitle')]"), "Title"); + public ILabel TermsLabel => FormElement.FindChildElement(By.XPath("//label[contains(@class, 'checkbox')]"), "Terms"); + + //private ICheckBox TermsCheckBox => FormElement.FindChildElement(By.XPath("//input[@type='checkbox']"), "Terms", null, ElementState.ExistsInAnyState); + } + */ +} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm.cs new file mode 100644 index 00000000..8afd949a --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm.cs @@ -0,0 +1,59 @@ +using Aquality.Selenium.Browsers; +using Aquality.Selenium.Elements.Interfaces; +using Aquality.Selenium.Forms; +using OpenQA.Selenium; +using System; +using System.IO; + +namespace Aquality.Selenium.Tests.Integration.TestApp.LoginFormForRelativeLocators.Forms +{ + internal class LoginForm : Form + { + private static string BaseUrl => Path.Combine($"{AppDomain.CurrentDomain.BaseDirectory}", "Resources", "LoginFormForRelativeLocators.html"); + + public LoginForm() : base(By.XPath("//h1[contains(text(),'Student Login Form')]"), "Login form") + { + } + + public void Open() + { + AqualityServices.Browser.GoTo($"file://{BaseUrl}"); + AqualityServices.Browser.WaitForPageToLoad(); + AqualityServices.Browser.Maximize(); + } + + public static readonly string IdLocatorUserNameTextBox = "//input[@id='user-name']"; + public static readonly string IdLocatorSurnameTextBox = "//input[@id='user-name']"; + public static readonly string IdLocatorPasswordTextBox = "//input[@id='password']"; + + public static readonly string IdLocatorUniversityTextBox = "//input[@id='university']"; + public static readonly string IdLocatorPhoneTextBox = "//input[@id='phone']"; + public static readonly string IdLocatorAdressTextBox = "//input[@id='adress']"; + + public static readonly string IdLocatorFacultyTextBox = "//input[@id='faculty']"; + public static readonly string IdLocatorLoginButton = "//button[@id='submit-btn']"; + public static readonly string IdLocatorCancelButton = "//button[@id='cancel-btn']"; + + public static readonly string ElementNameUserNameTextBox = "User Name Text Box"; + public static readonly string ElementNameSurnameTextBox = "Surname Name Text Box"; + public static readonly string ElementNamePasswordTextBox = "Password Text Box"; + + public static readonly string ElementNameUniversityTextBox = "University Text Box"; + public static readonly string ElementNamePhoneTextBox = "Phone Text Box"; + public static readonly string ElementNameAdressTextBox = "Adress Text Box"; + + public static readonly string ElementNameFacultyTextBox = "Faculty Text Box"; + public static readonly string ElementNameLoginButton = "Login Button"; + public static readonly string ElementNameCancelButton = "Cancel Button"; + + public ITextBox UserNameTextBox => ElementFactory.GetTextBox(By.XPath(IdLocatorUserNameTextBox), ElementNameUserNameTextBox); + public ITextBox SurnameTextBox => ElementFactory.GetTextBox(By.XPath(IdLocatorSurnameTextBox), ElementNameSurnameTextBox); + public ITextBox PasswordTextBox => ElementFactory.GetTextBox(By.XPath(IdLocatorPasswordTextBox), ElementNamePasswordTextBox); + public ITextBox UniversityTextBox => ElementFactory.GetTextBox(By.XPath(IdLocatorUniversityTextBox), ElementNameUniversityTextBox); + public ITextBox PhoneTextBox => ElementFactory.GetTextBox(By.XPath(IdLocatorPhoneTextBox), ElementNamePhoneTextBox); + public ITextBox AdressTextBox => ElementFactory.GetTextBox(By.XPath(IdLocatorAdressTextBox), ElementNameAdressTextBox); + public ITextBox FacultyTextBox => ElementFactory.GetTextBox(By.XPath(IdLocatorFacultyTextBox), ElementNameFacultyTextBox); + public IButton LoginButton => ElementFactory.GetButton(By.XPath(IdLocatorLoginButton), ElementNameLoginButton); + public IButton CancelButton => ElementFactory.GetButton(By.XPath(IdLocatorCancelButton), ElementNameCancelButton); + } +} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs index 4b71fbde..0e564ce9 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/ChallengingDomForm.cs @@ -3,7 +3,7 @@ namespace Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms { - internal class ChallengingDomForm : TheInternetForm + internal class ChallengingDomForm : TheInternetForm //TODO! This code should be removed during refactoring { public ChallengingDomForm() : base(By.XPath("//h3[contains(text(),'Challenging DOM')]"), "Challenging dom form") { diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/ContactUsForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/ContactUsForm.cs new file mode 100644 index 00000000..2e9f34f8 --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/ContactUsForm.cs @@ -0,0 +1,39 @@ +using Aquality.Selenium.Elements.Interfaces; +using OpenQA.Selenium; + +namespace Aquality.Selenium.Tests.Integration.TestApp.a1qa.Forms +{ + internal class ContactUsForm : TheA1qaForm + { + public ContactUsForm() : base(By.XPath("//h3[contains(text(),'Data Tables')]"), "Data Tables form") + { + } + protected override string UrlPart => "contacts/"; + + public static readonly string ElementNameNameTextBox = "Name text box"; + public static readonly string ElementNameCompanyTextBox = "Company text box"; + public static readonly string ElementNameEmailTextBox = "Email text box"; + public static readonly string ElementNamePhoneTextBox = "Phone text box"; + public static readonly string ElementNameCommentTextBox = "Comment text box"; + + public static readonly string LocatorNameTextBox = "//input[@id='your-name']"; + public static readonly string LocatorCompanyTextBox = "//input[@id='your-company']"; + public static readonly string LocatorEmailTextBox = "//input[@id='your-email']"; + public static readonly string LocatorPhoneTextBox = "//input[@id='your-phone']"; + public static readonly string LocatorCommentTextBox = "//textarea[@id='your-message']"; + + public ITextBox NameTextBox => ElementFactory.GetTextBox(By.XPath(LocatorNameTextBox), ElementNameNameTextBox); + public ITextBox CompanyTextBox => ElementFactory.GetTextBox(By.XPath(LocatorCompanyTextBox), ElementNameCompanyTextBox); + public ITextBox EmailTextBox => ElementFactory.GetTextBox(By.XPath(LocatorEmailTextBox), ElementNameEmailTextBox); + public ITextBox PhoneTextBox => ElementFactory.GetTextBox(By.XPath(LocatorPhoneTextBox), ElementNamePhoneTextBox); + public ITextBox CommentTextBox => ElementFactory.GetTextBox(By.XPath(LocatorCommentTextBox), ElementNameCommentTextBox); + + public ICheckBox PrivacyCheckBox => ElementFactory.GetCheckBox(By.XPath("//input[@name='privacy']/following-sibling::span[1]"), "Privacy"); + public IButton SendButton => ElementFactory.GetButton(By.XPath("//div[contains(@class,'contactsForm__submit')]//button"), "Send a message"); + public ILabel EmailAlertLabel => ElementFactory.GetLabel(By.XPath("//div[contains(@class,'error')]//input[@id='your-email']"), "Email validating message"); + public ILabel TitleLabel => FormElement.FindChildElement(By.XPath("//h2[contains(@class,'blockTitle')]"), "Title"); + public ILabel TermsLabel => FormElement.FindChildElement(By.XPath("//label[contains(@class, 'checkbox')]"), "Terms"); + + //private ICheckBox TermsCheckBox => FormElement.FindChildElement(By.XPath("//input[@type='checkbox']"), "Terms", null, ElementState.ExistsInAnyState); + } +} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/TheA1qaForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/TheA1qaForm.cs new file mode 100644 index 00000000..92e0777a --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/TheA1qaForm.cs @@ -0,0 +1,26 @@ +using Aquality.Selenium.Browsers; +using Aquality.Selenium.Forms; +using OpenQA.Selenium; + +namespace Aquality.Selenium.Tests.Integration.TestApp.a1qa.Forms +{ + internal abstract class TheA1qaForm : Form + { + private const string BaseUrl = "https://www.a1qa.com/"; + + protected TheA1qaForm(By locator, string name) : base(locator, name) + { + } + + protected abstract string UrlPart { get; } + + public string Url => BaseUrl + UrlPart; + + public void Open() + { + AqualityServices.Browser.GoTo(Url); + AqualityServices.Browser.WaitForPageToLoad(); + AqualityServices.Browser.Maximize(); + } + } +} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Resources/LoginFormForRelativeLocators.html b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Resources/LoginFormForRelativeLocators.html new file mode 100644 index 00000000..1d52c86b --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Resources/LoginFormForRelativeLocators.html @@ -0,0 +1,120 @@ + + + + + Login Page + + + +

Student Login Form

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ Remember me +
+ +
+ + \ No newline at end of file From 03b4bc47a0b7073d2edcd2275d6687d3e522b9f7 Mon Sep 17 00:00:00 2001 From: Mikhail Pyshnik Date: Wed, 14 Feb 2024 17:54:09 +0300 Subject: [PATCH 12/12] Unused forms have been deleted --- .../Forms/LoginForm - Copy.cs | 128 ------------------ .../TheInternet/Forms/DataTablesForm.cs | 45 ------ .../TestApp/a1qa/Forms/ContactUsForm.cs | 39 ------ .../TestApp/a1qa/Forms/TheA1qaForm.cs | 26 ---- 4 files changed, 238 deletions(-) delete mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm - Copy.cs delete mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/DataTablesForm.cs delete mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/ContactUsForm.cs delete mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/TheA1qaForm.cs diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm - Copy.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm - Copy.cs deleted file mode 100644 index e438cfa4..00000000 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/LoginFormForRelativeLocators/Forms/LoginForm - Copy.cs +++ /dev/null @@ -1,128 +0,0 @@ -using AngleSharp.Dom; -using Aquality.Selenium.Browsers; -using Aquality.Selenium.Elements.Interfaces; -using Aquality.Selenium.Forms; -using OpenQA.Selenium; - - -namespace Aquality.Selenium.Tests.Integration.TestApp.LoginFormForRelativeLocators.Forms -{ - internal class LoginForm1 : Form - { - private const string BaseUrl = "C:\\a1qa\\GitHub_repos\\aquality-selenium-dotnet\\Aquality.Selenium\\tests\\Aquality.Selenium.Tests\\bin\\Debug\\net6.0\\Resources\\LoginFormForRelativeLocators.html"; - public LoginForm1() : base(By.XPath("//h1[contains(text(),'Student Login Form')]"), "Login form") - { - } - - public string Url => BaseUrl; - - public void Open() - { - AqualityServices.Browser.GoTo($"file://{BaseUrl}"); - AqualityServices.Browser.WaitForPageToLoad(); - AqualityServices.Browser.Maximize(); - } - // public static readonly string LocatorCommentTextBox = "//textarea[@id='your-message']";

Student Login Form

- - private static string ElementNameText(string idName, string typeOfElement) => $"[{idName}] {typeOfElement}" ; - - //private readonly string LabelText = "label"; - private readonly string TextBoxText = "text box"; - private readonly string ButtonText = "button"; - - public static readonly string IdLocatorUserNameTextBox = "name"; //"//input[@id='name']"; - public static readonly string IdLocatorStudentSurnameTextBox = "surname"; - public static readonly string IdLocatorPasswordTextBox = "password"; - public static readonly string IdLocatorUniversityTextBox = "university"; - public static readonly string IdLocatorFacultyTextBox = "faculty"; - public static readonly string IdLocatorSpecializationTextBox = "specialization"; - public static readonly string IdLocatorUniversityAddressTextBox = "university-address"; // address of the university - public static readonly string IdLocatorHomeAddressTextBox = "home-address"; - public static readonly string IdLocatorPhoneNumberTextBox = "phone-number"; - - - public static readonly string IdLocatorLoginButton = "submit-btn"; - public static readonly string IdLocatorCancelButton = "cancel-btn"; - - //public ILabel FormHeaderLabel => ElementFactory.GetLabel(By.Id(IdLocatorUserNameTextBox), ElementNameText(IdLocatorUserNameTextBox, LabelText)); - - public ITextBox NameTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorUserNameTextBox), ElementNameText(IdLocatorUserNameTextBox, TextBoxText)); - public ITextBox SurnameTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorStudentSurnameTextBox), ElementNameText(IdLocatorStudentSurnameTextBox, TextBoxText)); - public ITextBox PasswordTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorPasswordTextBox), ElementNameText(IdLocatorPasswordTextBox, TextBoxText)); - public ITextBox UniversityTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorUniversityTextBox), ElementNameText(IdLocatorUniversityTextBox, TextBoxText)); - public ITextBox FacultyTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorFacultyTextBox), ElementNameText(IdLocatorFacultyTextBox, TextBoxText)); - public ITextBox SpecializationTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorSpecializationTextBox), ElementNameText(IdLocatorSpecializationTextBox, TextBoxText)); - public ITextBox UniversityAddressTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorUniversityAddressTextBox), ElementNameText(IdLocatorUniversityAddressTextBox, TextBoxText)); - public ITextBox HomeAddressTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorHomeAddressTextBox), ElementNameText(IdLocatorHomeAddressTextBox, TextBoxText)); - public ITextBox PhoneNumberTextBox => ElementFactory.GetTextBox(By.Id(IdLocatorPhoneNumberTextBox), ElementNameText(IdLocatorPhoneNumberTextBox, TextBoxText)); - - public IButton LoginButton => ElementFactory.GetButton(By.Id(IdLocatorLoginButton), ElementNameText(IdLocatorPhoneNumberTextBox, ButtonText)); - public IButton CancelButton => ElementFactory.GetButton(By.Id(IdLocatorCancelButton), ElementNameText(IdLocatorPhoneNumberTextBox, ButtonText)); - - /* - public ICheckBox PrivacyCheckBox => ElementFactory.GetCheckBox(By.XPath("//input[@name='privacy']/following-sibling::span[1]"), "Privacy"); - public IButton SendButton => ElementFactory.GetButton(By.XPath("//div[contains(@class,'contactsForm__submit')]//button"), "Send a message"); - public ILabel EmailAlertLabel => ElementFactory.GetLabel(By.XPath("//div[contains(@class,'error')]//input[@id='your-email']"), "Email validating message"); - public ILabel TitleLabel => FormElement.FindChildElement(By.XPath("//h2[contains(@class,'blockTitle')]"), "Title"); - public ILabel TermsLabel => FormElement.FindChildElement(By.XPath("//label[contains(@class, 'checkbox')]"), "Terms"); - */ - } - - /* - internal abstract class TheA1qaForm : Form - { - private const string BaseUrl = "https://www.a1qa.com/"; - - protected TheA1qaForm(By locator, string name) : base(locator, name) - { - } - - protected abstract string UrlPart { get; } - - public string Url => BaseUrl + UrlPart; - - public void Open() - { - AqualityServices.Browser.GoTo(Url); - AqualityServices.Browser.WaitForPageToLoad(); - AqualityServices.Browser.Maximize(); - } - } - */ - - /* - internal class ContactUsForm : TheA1qaForm - { - public ContactUsForm() : base(By.XPath("//h3[contains(text(),'Data Tables')]"), "Data Tables form") - { - } - protected override string UrlPart => "contacts/"; - - public static readonly string ElementNameNameTextBox = "Name text box"; - public static readonly string ElementNameCompanyTextBox = "Company text box"; - public static readonly string ElementNameEmailTextBox = "Email text box"; - public static readonly string ElementNamePhoneTextBox = "Phone text box"; - public static readonly string ElementNameCommentTextBox = "Comment text box"; - - public static readonly string LocatorNameTextBox = "//input[@id='your-name']"; - public static readonly string LocatorCompanyTextBox = "//input[@id='your-company']"; - public static readonly string LocatorEmailTextBox = "//input[@id='your-email']"; - public static readonly string LocatorPhoneTextBox = "//input[@id='your-phone']"; - public static readonly string LocatorCommentTextBox = "//textarea[@id='your-message']"; - - public ITextBox NameTextBox => ElementFactory.GetTextBox(By.XPath(LocatorNameTextBox), ElementNameNameTextBox); - public ITextBox CompanyTextBox => ElementFactory.GetTextBox(By.XPath(LocatorCompanyTextBox), ElementNameCompanyTextBox); - public ITextBox EmailTextBox => ElementFactory.GetTextBox(By.XPath(LocatorEmailTextBox), ElementNameEmailTextBox); - public ITextBox PhoneTextBox => ElementFactory.GetTextBox(By.XPath(LocatorPhoneTextBox), ElementNamePhoneTextBox); - public ITextBox CommentTextBox => ElementFactory.GetTextBox(By.XPath(LocatorCommentTextBox), ElementNameCommentTextBox); - - public ICheckBox PrivacyCheckBox => ElementFactory.GetCheckBox(By.XPath("//input[@name='privacy']/following-sibling::span[1]"), "Privacy"); - public IButton SendButton => ElementFactory.GetButton(By.XPath("//div[contains(@class,'contactsForm__submit')]//button"), "Send a message"); - public ILabel EmailAlertLabel => ElementFactory.GetLabel(By.XPath("//div[contains(@class,'error')]//input[@id='your-email']"), "Email validating message"); - public ILabel TitleLabel => FormElement.FindChildElement(By.XPath("//h2[contains(@class,'blockTitle')]"), "Title"); - public ILabel TermsLabel => FormElement.FindChildElement(By.XPath("//label[contains(@class, 'checkbox')]"), "Terms"); - - //private ICheckBox TermsCheckBox => FormElement.FindChildElement(By.XPath("//input[@type='checkbox']"), "Terms", null, ElementState.ExistsInAnyState); - } - */ -} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/DataTablesForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/DataTablesForm.cs deleted file mode 100644 index a5c83e21..00000000 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/DataTablesForm.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Aquality.Selenium.Elements.Interfaces; -using OpenQA.Selenium; - -namespace Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms -{ - internal class DataTablesForm : TheInternetForm - { - const string TABLE1_BODY = "//table[@id='table1']//tbody"; - - public DataTablesForm() : base(By.XPath("//h3[contains(text(),'Data Tables')]"), "Data Tables form") - { - } - protected override string UrlPart => "tables"; - - public static readonly string ElementNameRow4Column5 = "Cell in row 4 column 5"; - public static readonly string ElementNameRow4Column4 = "Cell in row 4 column 4"; - public static readonly string ElementNameRow4Column3 = "Cell in row 4 column 3"; - public static readonly string ElementNameRow4Column2 = "Cell in row 4 column 2"; - public static readonly string ElementNameRow3Column5 = "Cell in row 3 column 5"; - public static readonly string ElementNameRow2Column5 = "Cell in row 2 column 5"; - public static readonly string ElementNameRow2Column4 = "Cell in row 2 column 4"; - public static readonly string ElementNameRow2Column3 = "Cell in row 2 column 3"; - - public static readonly string LocatorCellRow4Column5 = $"{TABLE1_BODY}//tr[4]/td[5]"; - public static readonly string LocatorCellRow4Column4 = $"{TABLE1_BODY}//tr[4]/td[4]"; - public static readonly string LocatorCellRow4Column2 = $"{TABLE1_BODY}//tr[4]/td[2]"; - public static readonly string LocatorCellRow3Column5 = $"{TABLE1_BODY}//tr[3]/td[5]"; - public static readonly string LocatorCellRow4Column3 = $"{TABLE1_BODY}//tr[4]/td[3]"; - public static readonly string LocatorCellRow2Column5 = $"{TABLE1_BODY}//tr[2]/td[5]"; - public static readonly string LocatorCellRow2Column4 = $"{TABLE1_BODY}//tr[2]/td[4]"; - public static readonly string LocatorCellRow2Column3 = $"{TABLE1_BODY}//tr[2]/td[3]"; - - public static readonly string LocatorCellRow2Column2 = $"{TABLE1_BODY}//tr[2]/td[2]"; - public static readonly string LocatorCellRow2Column1 = $"{TABLE1_BODY}//tr[2]/td[1]"; - - public ILabel CellInRow4Column5 => ElementFactory.GetLabel(By.XPath(LocatorCellRow4Column5), ElementNameRow4Column5); - public ILabel CellInRow4Column4 => ElementFactory.GetLabel(By.XPath(LocatorCellRow4Column4), ElementNameRow4Column4); - public ILabel CellInRow4Column3 => ElementFactory.GetLabel(By.XPath(LocatorCellRow4Column3), ElementNameRow4Column3); - public ILabel CellInRow4Column2 => ElementFactory.GetLabel(By.XPath(LocatorCellRow4Column2), ElementNameRow4Column2); - public ILabel CellInRow3Column5 => ElementFactory.GetLabel(By.XPath(LocatorCellRow3Column5), ElementNameRow3Column5); - public ILabel CellInRow2Column5 => ElementFactory.GetLabel(By.XPath(LocatorCellRow2Column5), ElementNameRow2Column5); - public ILabel CellInRow2Column4 => ElementFactory.GetLabel(By.XPath(LocatorCellRow2Column4), ElementNameRow2Column4); - public ILabel CellInRow2Column3 => ElementFactory.GetLabel(By.XPath(LocatorCellRow2Column3), ElementNameRow2Column3); - } -} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/ContactUsForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/ContactUsForm.cs deleted file mode 100644 index 2e9f34f8..00000000 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/ContactUsForm.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Aquality.Selenium.Elements.Interfaces; -using OpenQA.Selenium; - -namespace Aquality.Selenium.Tests.Integration.TestApp.a1qa.Forms -{ - internal class ContactUsForm : TheA1qaForm - { - public ContactUsForm() : base(By.XPath("//h3[contains(text(),'Data Tables')]"), "Data Tables form") - { - } - protected override string UrlPart => "contacts/"; - - public static readonly string ElementNameNameTextBox = "Name text box"; - public static readonly string ElementNameCompanyTextBox = "Company text box"; - public static readonly string ElementNameEmailTextBox = "Email text box"; - public static readonly string ElementNamePhoneTextBox = "Phone text box"; - public static readonly string ElementNameCommentTextBox = "Comment text box"; - - public static readonly string LocatorNameTextBox = "//input[@id='your-name']"; - public static readonly string LocatorCompanyTextBox = "//input[@id='your-company']"; - public static readonly string LocatorEmailTextBox = "//input[@id='your-email']"; - public static readonly string LocatorPhoneTextBox = "//input[@id='your-phone']"; - public static readonly string LocatorCommentTextBox = "//textarea[@id='your-message']"; - - public ITextBox NameTextBox => ElementFactory.GetTextBox(By.XPath(LocatorNameTextBox), ElementNameNameTextBox); - public ITextBox CompanyTextBox => ElementFactory.GetTextBox(By.XPath(LocatorCompanyTextBox), ElementNameCompanyTextBox); - public ITextBox EmailTextBox => ElementFactory.GetTextBox(By.XPath(LocatorEmailTextBox), ElementNameEmailTextBox); - public ITextBox PhoneTextBox => ElementFactory.GetTextBox(By.XPath(LocatorPhoneTextBox), ElementNamePhoneTextBox); - public ITextBox CommentTextBox => ElementFactory.GetTextBox(By.XPath(LocatorCommentTextBox), ElementNameCommentTextBox); - - public ICheckBox PrivacyCheckBox => ElementFactory.GetCheckBox(By.XPath("//input[@name='privacy']/following-sibling::span[1]"), "Privacy"); - public IButton SendButton => ElementFactory.GetButton(By.XPath("//div[contains(@class,'contactsForm__submit')]//button"), "Send a message"); - public ILabel EmailAlertLabel => ElementFactory.GetLabel(By.XPath("//div[contains(@class,'error')]//input[@id='your-email']"), "Email validating message"); - public ILabel TitleLabel => FormElement.FindChildElement(By.XPath("//h2[contains(@class,'blockTitle')]"), "Title"); - public ILabel TermsLabel => FormElement.FindChildElement(By.XPath("//label[contains(@class, 'checkbox')]"), "Terms"); - - //private ICheckBox TermsCheckBox => FormElement.FindChildElement(By.XPath("//input[@type='checkbox']"), "Terms", null, ElementState.ExistsInAnyState); - } -} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/TheA1qaForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/TheA1qaForm.cs deleted file mode 100644 index 92e0777a..00000000 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/a1qa/Forms/TheA1qaForm.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Aquality.Selenium.Browsers; -using Aquality.Selenium.Forms; -using OpenQA.Selenium; - -namespace Aquality.Selenium.Tests.Integration.TestApp.a1qa.Forms -{ - internal abstract class TheA1qaForm : Form - { - private const string BaseUrl = "https://www.a1qa.com/"; - - protected TheA1qaForm(By locator, string name) : base(locator, name) - { - } - - protected abstract string UrlPart { get; } - - public string Url => BaseUrl + UrlPart; - - public void Open() - { - AqualityServices.Browser.GoTo(Url); - AqualityServices.Browser.WaitForPageToLoad(); - AqualityServices.Browser.Maximize(); - } - } -}