From e79ff4ac900dd7e0156b5116e08daca73d5968c1 Mon Sep 17 00:00:00 2001 From: Justas Skarzauskas Date: Mon, 14 May 2018 16:20:23 +0300 Subject: [PATCH 1/3] Custom web element for web components (shadowdom) Signed-off-by: Justas Skarzauskas --- .../DriverFactory/LocalDriverFactory.cs | 2 + .../WebComponents/WebComponentsElement.cs | 460 ++++++++++++++++++ .../WebComponentsElementHelper.js | 209 ++++++++ Vaft.Framework/Vaft.Framework.csproj | 7 +- .../Pages/WebComponentsDemoPage.cs | 67 +++ Vaft.PageObjects/Vaft.PageObjects.csproj | 1 + Vaft.SeleniumNunitTests/App.config | 4 +- .../Resources/WebComponentsDemoPage.html | 166 +++++++ .../Tests/ShadowDomWebElementTests.cs | 45 ++ .../Vaft.SeleniumNunitTests.csproj | 4 + 10 files changed, 962 insertions(+), 3 deletions(-) create mode 100644 Vaft.Framework/Element/Customization/WebComponents/WebComponentsElement.cs create mode 100644 Vaft.Framework/Element/Customization/WebComponents/WebComponentsElementHelper.js create mode 100644 Vaft.PageObjects/Pages/WebComponentsDemoPage.cs create mode 100644 Vaft.SeleniumNunitTests/Resources/WebComponentsDemoPage.html create mode 100644 Vaft.SeleniumNunitTests/Tests/ShadowDomWebElementTests.cs diff --git a/Vaft.Framework/DriverFactory/LocalDriverFactory.cs b/Vaft.Framework/DriverFactory/LocalDriverFactory.cs index f4aa2fc..f342fa0 100644 --- a/Vaft.Framework/DriverFactory/LocalDriverFactory.cs +++ b/Vaft.Framework/DriverFactory/LocalDriverFactory.cs @@ -70,6 +70,8 @@ private IWebDriver CreateFirefoxDriver() var ffp = new FirefoxProfile(); ffp.SetPreference("intl.accept_languages", Config.Settings.RuntimeSettings.BrowserLanguage); + ffp.SetPreference("dom.webcomponents.enabled",true); + ffp.SetPreference("dom.webcomponents.shadowdom.enabled",true); var proxy = GetProxy(); if (proxy != null) { diff --git a/Vaft.Framework/Element/Customization/WebComponents/WebComponentsElement.cs b/Vaft.Framework/Element/Customization/WebComponents/WebComponentsElement.cs new file mode 100644 index 0000000..d68bfdd --- /dev/null +++ b/Vaft.Framework/Element/Customization/WebComponents/WebComponentsElement.cs @@ -0,0 +1,460 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; +using OpenQA.Selenium.Edge; +using OpenQA.Selenium.Firefox; +using OpenQA.Selenium.IE; +using OpenQA.Selenium.Internal; +using OpenQA.Selenium.Opera; +using OpenQA.Selenium.Remote; +using OpenQA.Selenium.Support.PageObjects; + +namespace Vaft.Framework.Element.Customization.WebComponents +{ + public class WebComponentsElement : IWebElement, IWrapsElement + { + private const string JavaScriptHelperFilePath = "Vaft.Framework.Element.Customization.WebComponents.WebComponentsElementHelper.js"; + private readonly By _by; + private readonly IWebDriver _webdriver; + private IWebElement _cashedElement; + private IWebElement _parrentField; + private readonly List _parrentFieldSelectors; + private List _parrentFields; + + + /// ShadowDomWebElement constructor + /// + /// WebDriver object + /// Element selector + /// List of parent element selectors. This param can be used if there is a need explicitly define parent selector or selectors that are outside target element shadow dom. + /// + public WebComponentsElement(IWebDriver driver, By by, List parrentSelectors = null) + { + _webdriver = driver; + _by = by; + _parrentFieldSelectors = parrentSelectors; + } + + + /// Static ShadowDomWebElement initializator + /// WebDriver object + /// Element selector + /// List of parent element selectors. This param can be used if there is a need explicitly define parent selector or selectors that are outside target element shadow dom. + public static WebComponentsElement CreateInstance(IWebDriver driver, By by, List parentSelectors = null) + { + return new WebComponentsElement(driver, by, parentSelectors); + } + + public IWebElement Element + { + get + { + IWebElement parentField = _parrentField; + if (_parrentFieldSelectors != null && _parrentFieldSelectors.Any()) + { + _parrentFields = FindParrentFields(); + if (_parrentFields != null && _parrentFields.Any()) + { + parentField = _parrentFields.Last(); + } + } + + How how = GetFindMethod(_by); + string usingstring = GetUsingString(how, _by); + _cashedElement = SearchElement(how, usingstring, parentField); + return _cashedElement; + } + } + + /// + /// Search for IwebElement by given By selector. Element search is done at first in the main page DOM and if no elements were found then element search is done in all existing Shadow DOM's + /// + /// + /// + public IWebElement FindElement(By by) + { + IWebElement expectedElement = null; + + //1st seach in current element shadow root + How howMethod = GetFindMethod(by); + string usingString = GetUsingString(howMethod, by); + try + { + expectedElement = SearchElement(howMethod, usingString, Element); + if (expectedElement != null) + { + return expectedElement; + } + } + catch (Exception) + { + // ignored + } + + //2nd search in current element + try + { + expectedElement = Element.FindElement(by); + if (expectedElement != null) + { + return expectedElement; + } + } + catch (Exception) + { + // ignored + } + + return expectedElement; + } + + public ReadOnlyCollection FindElements(By by) + { + return Element.FindElements(by); + } + + public void SetParrentField(IWebElement parrentField) + { + _parrentField = parrentField; + } + + public void Clear() + { + Element.Clear(); + } + + public void SendKeys(string text) + { + Element.SendKeys(text); + } + + public void Submit() + { + Element.Submit(); + } + + public void Click() + { + Element.Click(); + } + + public string GetAttribute(string attributeName) + { + return Element.GetAttribute(attributeName); + } + + public string GetProperty(string propertyName) + { + return Element.GetProperty(propertyName); + } + + public string GetCssValue(string propertyName) + { + return Element.GetCssValue(propertyName); + } + + public string TagName => Element.TagName; + public string Text => Element.Text; + public bool Enabled => Element.Enabled; + public bool Selected => Element.Selected; + public Point Location => Element.Location; + public Size Size => Element.Size; + public bool Displayed => Element.Displayed; + public IWebElement WrappedElement => Element; + + + /// + /// Search for IwebElement in ShadowDOM. + /// + /// + /// + /// If rootElement is defined then the search is performed inside rootElement + /// + /// + public IWebElement SearchElement(How how, string usingString, IWebElement rootElement = null) + { + List elementsList; + elementsList = SearchElements(how, usingString, rootElement); + if (elementsList.Count > 0) + { + return elementsList.First(); + } + + throw new NoSuchElementException($"Failed to find element in shadowDom By:{_by}"); + } + + public IWebElement SearchElement(By by, IWebElement rooElement = null) + { + How how = GetFindMethod(by); + string usingString = GetUsingString(how, by); + return SearchElement(how, usingString, rooElement); + } + + public IWebElement SearchElement(IWebElement rooElement = null) + { + How how = GetFindMethod(_by); + string usingString = GetUsingString(how, _by); + return SearchElement(how, usingString, rooElement); + } + + public List SearchElements(How how, string usingstring, IWebElement rootElement = null) + { + List elementsList = new List(); + switch (how) + { + case How.CssSelector: + elementsList = SearchElementsByCss(rootElement, usingstring); + break; + case How.XPath: + elementsList = SearchElementByXpath(rootElement, usingstring); + if (elementsList != null && elementsList.Count > 0) + { + foreach (RemoteWebElement element in elementsList) + { + try + { + IWebElement webElement = element.FindElement(_by); + elementsList.Add((RemoteWebElement)webElement); + } + catch (Exception) + { + //ignored + } + } + } + + break; + case How.ClassName: + throw new InvalidSelectorException("How.ClassName is not supported yet"); + case How.Id: + elementsList = SearchElementById(rootElement, usingstring); + break; + + } + + if (elementsList != null && elementsList.Count.Equals(0)) + { + throw new NoSuchElementException($"Failed to find elements in shadowDom By:{_by}"); + } + + return elementsList; + } + + public List SearchElements(By by, IWebElement rootField = null) + { + How how = GetFindMethod(by); + string usingString = GetUsingString(how, by); + return SearchElements(how, usingString, rootField); + } + + public List SearchElements(IWebElement rootField = null) + { + return SearchElements(_by, rootField); + } + + private List FilterRezultsList(IReadOnlyCollection list) + { + List remoteWebElements = new List(); + if (list != null && list.Count > 0) + { + foreach (object element in list) + { + var elementType = element.GetType(); + if (elementType.Equals(typeof(RemoteWebElement)) || + elementType.Equals(typeof(FirefoxWebElement))|| + elementType.Equals(typeof(ChromeWebElement)) || + elementType.Equals(typeof(InternetExplorerWebElement)) || + elementType.Equals(typeof(EdgeWebElement)) || + elementType.Equals(typeof(OperaWebElement)) + ) + { + remoteWebElements.Add((RemoteWebElement)element); + } + + if (element.GetType() == typeof(ReadOnlyCollection)) + { + foreach (IWebElement subElement in (ReadOnlyCollection)element) + { + if (subElement.GetType() == typeof(RemoteWebElement)) + { + remoteWebElements.Add((RemoteWebElement)subElement); + } + } + } + } + } + + return remoteWebElements; + } + + private List FindParrentFields() + { + _parrentFields = new List(); + IWebElement previuosElement = null; + for (int i = 0; i < _parrentFieldSelectors.Count; i++) + { + How how = GetFindMethod(_parrentFieldSelectors[i]); + string usingString = GetUsingString(how, _parrentFieldSelectors[i]); + if (i.Equals(0)) + { + //Try search first in regular DOM + try + { + if (_parrentField != null) + { + previuosElement = _parrentField.FindElement(_parrentFieldSelectors[i]); + } + else + { + previuosElement = _webdriver.FindElement(_parrentFieldSelectors[i]); + } + + _parrentFields.Add(previuosElement); + continue; + } + catch (Exception) + { + //ignored + } + + //search in shadowdom + try + { + previuosElement = SearchElements(how, usingString, _parrentField).First(); + _parrentFields.Add(previuosElement); + continue; + } + catch (Exception e) + { + throw new Exception("Failed to find first parrent field", e); + } + } + + try + { + var subsequentElement = SearchElement(_parrentFieldSelectors[i], previuosElement); + _parrentFields.Add(subsequentElement); + previuosElement = subsequentElement; + } + catch (Exception e) + { + throw new Exception($"Failed to find subsequent element using: {_parrentFieldSelectors[i]}", e); + } + } + + return _parrentFields; + } + + private List SearchElementByCss(IWebElement rootElement, string selectorString) + { + string jsMethodCall = "return searchForElementByCss(arguments[0])"; + if (rootElement != null) + { + jsMethodCall = "return searchForElementByCss(arguments[0],arguments[1])"; + } + + return SearchForElements(jsMethodCall, selectorString, rootElement); + } + + private List SearchElementsByCss(IWebElement rootElement, string selectorString) + { + string jsMethodCall = "return searchForElementByCss(arguments[0])"; + if (rootElement != null) + { + jsMethodCall = "return searchForAllElementsByCss(arguments[0],arguments[1])"; + } + + return SearchForElements(jsMethodCall, selectorString, rootElement); + } + + private List SearchElementByXpath(IWebElement rootElement, string selectorString) + { + string jsMethodCall = "return searchForElementByXpath(arguments[0])"; + if (rootElement != null) + { + jsMethodCall = "return searchForElementByXpath(arguments[0],arguments[1])"; + } + + return SearchForElements(jsMethodCall, selectorString, rootElement); + } + + private List SearchElementById(IWebElement rootElement, string id) + { + string jsMethodCall = "return searchForElementById(arguments[0])"; + if (rootElement != null) + { + jsMethodCall = "return searchForElementById(arguments[0],arguments[1])"; + } + + return SearchForElements(jsMethodCall, id, rootElement); + } + + private List SearchForElements(string javascriptMethod, string selector, IWebElement rootElement = null) + { + IReadOnlyCollection searchRezults = (IReadOnlyCollection)((IJavaScriptExecutor)_webdriver).ExecuteScript(GetElementsSearchJavascript() + javascriptMethod, selector, rootElement); + return FilterRezultsList(searchRezults); + } + + private string GetElementsSearchJavascript() + { + var asm = Assembly.GetExecutingAssembly(); + using (var stream = asm.GetManifestResourceStream(JavaScriptHelperFilePath)) + { + if (stream != null) + { + var reader = new StreamReader(stream); + return reader.ReadToEnd(); + } + throw new Exception($"ShadowIwebElement javacript helper file is not found. Path [{JavaScriptHelperFilePath}]. Check file build actions settings or file path"); + } + } + + private How GetFindMethod(By by) + { + How? how = null; + string stringVersion = by.ToString(); + stringVersion = stringVersion.Replace("By.", string.Empty); + if (stringVersion.StartsWith(How.CssSelector.ToString())) + { + how = How.CssSelector; + } + + if (stringVersion.StartsWith(How.ClassName.ToString())) + { + how = How.ClassName; + } + + if (stringVersion.StartsWith(How.Id.ToString())) + { + how = How.Id; + } + + if (stringVersion.StartsWith(How.XPath.ToString())) + { + how = How.XPath; + } + + if (how == null) + { + throw new ArgumentException("How: is not identified "); + } + + return how.Value; + } + + private string GetUsingString(How how, By by) + { + string usingString = by.ToString().Replace("By." + how + ": ", string.Empty); + return usingString; + } + + } + + +} \ No newline at end of file diff --git a/Vaft.Framework/Element/Customization/WebComponents/WebComponentsElementHelper.js b/Vaft.Framework/Element/Customization/WebComponents/WebComponentsElementHelper.js new file mode 100644 index 0000000..9fff658 --- /dev/null +++ b/Vaft.Framework/Element/Customization/WebComponents/WebComponentsElementHelper.js @@ -0,0 +1,209 @@ +var seleniumIdCounter = 0; + +function GetXpathArray(xpath, isArrayAsText, contextNode) { + + var searchContex; + if (contextNode == null) { + searchContex = document; + } + else { + searchContex = contextNode; + } + + var result = document.evaluate(xpath, searchContex, null, XPathResult.ANY_TYPE, null); + var rez; + if (!result) { + return null; + } + switch (result.resultType) { + case XPathResult.NUMBER_TYPE: + rez = ReturnSingleNumber(result); + break; + case XPathResult.STRING_TYPE: + rez = ReturnSingleString(result); + break; + case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: + rez = ReturnAsArray(result, isArrayAsText); + break; + default: + rez = 'Not expected result type ' + result.resultTyp; + } + return rez; +} + + + + +function ReturnSingleString(xpathResult) { + return xpathResult.stringValue; +} + +function ReturnSingleNumber(xpathResult) { + return xpathResult.numberValue; +} + +function ReturnAsArray(xpathResult, asText) { + var result = []; + var next = xpathResult.iterateNext(); + while (next) { + try { + var value; + if (asText == true) { + value = next.textContent; + } + else { + value = next; + } + + result.push(value); + next = xpathResult.iterateNext(); + } + catch (err) { + } + } + return result; +} +var RootElement; + +function setRootElement(root) { + if (root == null) { + RootElement = document; + } + else { + + RootElement = root; + } +} + +function getAllShadowDomDocumentFragments(rooElement) { + + if (rooElement == null) { + ; + rooElement = document; + } + + var shdw = []; + var childrensArr = []; + if (rooElement.shadowRoot != null) { + + shdw.push(rooElement.shadowRoot); + if (rooElement.shadowRoot.children != null) { + var shadowChildrens = rooElement.shadowRoot.children; + for (var c = 0; c < shadowChildrens.length; c++) { + childrensArr = []; + childrensArr = (getAllShadowDomDocumentFragments(shadowChildrens[c])); + shdw = shdw.concat(childrensArr); + } + } + } + if (rooElement.children != null) { + for (var c = 0; c < rooElement.children.length; c++) { + childrensArr = (getAllShadowDomDocumentFragments(rooElement.children[c])); + shdw = shdw.concat(childrensArr); + childrensArr = []; + } + + } + return shdw; +} + +function searchForElementByXpath(xpathString, rootElement) { + /* Search is not possible with by xpath in document-fragment, so in this case search by xpath will be done in temp element with document-fragment innerHtml and if any nodes are found then there will be returned document fragment that contains desired elements */ + var fragmentsArray = getAllShadowDomDocumentFragments(rootElement); + setCustomAttributesForAllFields(fragmentsArray); + var xpathResultsArray = []; + var filteredFragmentsArray = []; + var cssResults = []; + for (var a = 0; a < fragmentsArray.length; a++) { + + var tempElement = document.createElement('tempElement'); + tempElement.innerHTML = fragmentsArray[a].innerHTML; + + var currentRez = GetXpathArray(xpathString, false, tempElement); + + if (currentRez.length > 0) { + for (var xr = 0; xr < currentRez.length; xr++) { + var selid = currentRez[xr].getAttribute("selenium-id"); + if (selid != null) { + var cssresult = searchForElementByCss('*[selenium-id=\"' + selid + '\"]'); + cssResults.push(cssresult); + } + } + } + } + return cssResults; +} + +function setCustomAttributesForAllFields(fragmentsArray) { + for (var j = 0; j < fragmentsArray.length; j++) { + if (fragmentsArray[j] != null) { + if (fragmentsArray[j].children != null) { + for (var c = 0; c < fragmentsArray[j].children.length; c++) { + fragmentsArray[j].children[c].setAttribute("selenium-id", seleniumIdCounter); + seleniumIdCounter = seleniumIdCounter + 1; + setCustomAttributesForChildElements(fragmentsArray[j].children[c]); + + } + } + } + } +} + +function setCustomAttributesForChildElements(element) { + for (var j = 0; j < element.children.length; j++) { + if (element.children[j] != null) { + element.children[j].setAttribute("selenium-id", seleniumIdCounter); + seleniumIdCounter = seleniumIdCounter + 1; + setCustomAttributesForChildElements(element.children[j]); + } + } +} + + + +function searchForAllElementsByCss(selector, rootElement) { + var fragmentsArray = getAllShadowDomDocumentFragments(rootElement); + + var cssResultArray = []; + for (var a = 0; a < fragmentsArray.length; a++) { + + var currentRez = fragmentsArray[a].querySelectorAll(selector); + if (currentRez != null) { + for (var cr = 0; cr < currentRez.length; cr++) { + cssResultArray.push(currentRez[cr]); + } + } + } + return cssResultArray; +} + +function searchForElementByCss(selector, rootElement) { + var fragmentsArray = getAllShadowDomDocumentFragments(rootElement); + + var cssResultArray = []; + + for (var a = 0; a < fragmentsArray.length; a++) { + var currentRez = fragmentsArray[a].querySelector(selector); + if (currentRez != null) { + cssResultArray.push(currentRez); + } + } + return cssResultArray; +} + +function searchForElementById(selector, rootElement) { + var fragmentsArray = getAllShadowDomDocumentFragments(rootElement); + + var byIdResultArray = []; + + for (var a = 0; a < fragmentsArray.length; a++) { + var currentRez = fragmentsArray[a].getElementById(selector); + if (currentRez != null) { + byIdResultArray.push(currentRez); + } + } + return byIdResultArray; +} + + + diff --git a/Vaft.Framework/Vaft.Framework.csproj b/Vaft.Framework/Vaft.Framework.csproj index 42a552f..8cbdc57 100644 --- a/Vaft.Framework/Vaft.Framework.csproj +++ b/Vaft.Framework/Vaft.Framework.csproj @@ -123,6 +123,7 @@ + @@ -157,7 +158,11 @@ - + + + Always + + diff --git a/Vaft.PageObjects/Pages/WebComponentsDemoPage.cs b/Vaft.PageObjects/Pages/WebComponentsDemoPage.cs new file mode 100644 index 0000000..d241716 --- /dev/null +++ b/Vaft.PageObjects/Pages/WebComponentsDemoPage.cs @@ -0,0 +1,67 @@ +using System.Collections.Generic; +using OpenQA.Selenium; +using Vaft.Framework.Core; +using Vaft.Framework.Element.Customization.WebComponents; + +namespace Vaft.PageObjects.Pages +{ + public class WebComponentsDemoPage : PageBase + { + public WebComponentsDemoPage(IWebDriver driver) : base(driver) + { + InitFields(); + } + + private WebComponentsElement _shadow1InputFieldTwo; + private WebComponentsElement _shadow2DummyText; + private WebComponentsElement _shadow3InputFieldSub3Two; + private WebComponentsElement _shadow3DummyText; + private WebComponentsElement _shadow22NdInputFieldSub2Two; + private WebComponentsElement _shadow22NdDummyText; + + private void InitFields() + { + _shadow1InputFieldTwo = WebComponentsElement.CreateInstance(Driver, By.Id("two")); + _shadow2DummyText = WebComponentsElement.CreateInstance(Driver, By.CssSelector("div.data-view-text"),new List {By.Id("container"), By.Id("internal")}); + _shadow3InputFieldSub3Two = WebComponentsElement.CreateInstance(Driver, By.Id("sub3-two")); + _shadow3DummyText = WebComponentsElement.CreateInstance(Driver, By.CssSelector("div.data-view-text"),new List {By.Id("internal1")}); + _shadow22NdInputFieldSub2Two = WebComponentsElement.CreateInstance(Driver, By.Id("sub2-two")); + _shadow22NdDummyText = WebComponentsElement.CreateInstance(Driver, By.CssSelector("div.data-view-text"),new List {By.Id("container"), By.Id("internal2")}); + } + + public string GetShadow1InputTwoFieldValue() + { + return GetValueAttribute(_shadow1InputFieldTwo.Element); + } + + public string GetShadow2DummyTextValue() + { + return _shadow2DummyText.Element.Text; + } + + public string GetShadow3InputFieldSub3TwoValue() + { + return GetValueAttribute(_shadow3InputFieldSub3Two.Element); + } + + public string GetShadow3DummyTextValue() + { + return _shadow3DummyText.Element.Text; + } + + public string GetShadow22InputFieldSub2TwoValue() + { + return GetValueAttribute(_shadow22NdInputFieldSub2Two.Element); + } + + public string GetShadow22DummyTextValue() + { + return _shadow22NdDummyText.Element.Text; + } + + private string GetValueAttribute(IWebElement element) + { + return element.GetAttribute("value"); + } + } +} \ No newline at end of file diff --git a/Vaft.PageObjects/Vaft.PageObjects.csproj b/Vaft.PageObjects/Vaft.PageObjects.csproj index faf262e..825b631 100644 --- a/Vaft.PageObjects/Vaft.PageObjects.csproj +++ b/Vaft.PageObjects/Vaft.PageObjects.csproj @@ -88,6 +88,7 @@ + diff --git a/Vaft.SeleniumNunitTests/App.config b/Vaft.SeleniumNunitTests/App.config index 6b276fa..ef6bf55 100644 --- a/Vaft.SeleniumNunitTests/App.config +++ b/Vaft.SeleniumNunitTests/App.config @@ -8,8 +8,8 @@ - - + + diff --git a/Vaft.SeleniumNunitTests/Resources/WebComponentsDemoPage.html b/Vaft.SeleniumNunitTests/Resources/WebComponentsDemoPage.html new file mode 100644 index 0000000..a229a9f --- /dev/null +++ b/Vaft.SeleniumNunitTests/Resources/WebComponentsDemoPage.html @@ -0,0 +1,166 @@ + + + + + + Web components demo page + + + +

+ Demo page for web components UI automation with Selenium +

+ +
+ +
+
+ some text here +
+
+
+ + + + + + + + + + + + + + diff --git a/Vaft.SeleniumNunitTests/Tests/ShadowDomWebElementTests.cs b/Vaft.SeleniumNunitTests/Tests/ShadowDomWebElementTests.cs new file mode 100644 index 0000000..195a4e9 --- /dev/null +++ b/Vaft.SeleniumNunitTests/Tests/ShadowDomWebElementTests.cs @@ -0,0 +1,45 @@ +using System; +using System.IO; +using System.Reflection; +using NUnit.Framework; +using Vaft.Framework.Core; +using Vaft.PageObjects.Pages; + +namespace Vaft.SeleniumNunitTests.Tests +{ + public class ShadowDomWebElementTests:TestBase + { + private readonly string DemoPage = "Resources\\WebComponentsDemoPage.html"; + private WebComponentsDemoPage _demoPage; + + + [SetUp] + public void SetUp() + { + _demoPage= new WebComponentsDemoPage(Driver); + Driver.Navigate().GoToUrl("file:///"+Path.Combine(GetExecutingAssemblyPath(), DemoPage)); + } + + + [Test] + public void VerifyPageValues() + { + string text1 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."; + string text2 ="Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry."; + + Assert.AreEqual( "987777",_demoPage.GetShadow1InputTwoFieldValue()); + Assert.AreEqual(text1,_demoPage.GetShadow2DummyTextValue()); + Assert.AreEqual("2133546",_demoPage.GetShadow3InputFieldSub3TwoValue()); + Assert.AreEqual(text1,_demoPage.GetShadow3DummyTextValue()); + Assert.AreEqual("5",_demoPage.GetShadow22InputFieldSub2TwoValue()); + Assert.AreEqual(text2,_demoPage.GetShadow22DummyTextValue()); + } + + private string GetExecutingAssemblyPath() + { + var assemblyFile = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath; + var path = Path.GetDirectoryName(assemblyFile); + return Uri.UnescapeDataString(path); + } + } +} \ No newline at end of file diff --git a/Vaft.SeleniumNunitTests/Vaft.SeleniumNunitTests.csproj b/Vaft.SeleniumNunitTests/Vaft.SeleniumNunitTests.csproj index 91dd4ec..b3d8cbe 100644 --- a/Vaft.SeleniumNunitTests/Vaft.SeleniumNunitTests.csproj +++ b/Vaft.SeleniumNunitTests/Vaft.SeleniumNunitTests.csproj @@ -93,6 +93,7 @@ +
@@ -131,6 +132,9 @@ Always + + Always + From 19d6af144ad3de265c4b5c4517ffacc34d9f21d9 Mon Sep 17 00:00:00 2001 From: Justas Skarzauskas Date: Mon, 14 May 2018 16:31:59 +0300 Subject: [PATCH 2/3] Restored Tests app.config default settings --- Vaft.SeleniumNunitTests/App.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vaft.SeleniumNunitTests/App.config b/Vaft.SeleniumNunitTests/App.config index ef6bf55..336ce95 100644 --- a/Vaft.SeleniumNunitTests/App.config +++ b/Vaft.SeleniumNunitTests/App.config @@ -8,8 +8,8 @@ - - + + From 33f4f60b293b6cf49cf0c306a0c8051ccffb23bc Mon Sep 17 00:00:00 2001 From: Justas Skarzauskas Date: Mon, 14 May 2018 16:39:15 +0300 Subject: [PATCH 3/3] Restored Tests app.config default settings --- Vaft.SeleniumNunitTests/App.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vaft.SeleniumNunitTests/App.config b/Vaft.SeleniumNunitTests/App.config index 336ce95..6b276fa 100644 --- a/Vaft.SeleniumNunitTests/App.config +++ b/Vaft.SeleniumNunitTests/App.config @@ -8,7 +8,7 @@ - +