/* * Performs a click on a button */ void IActionsVisitor.visitButton(ArcliteButton element) { IWebElement e; try { e = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(element._elementXPath))); } catch (ElementNotVisibleException eve) { throw eve; } try { e.Click(); } catch (ElementClickInterceptedException) { driver.ExecuteJavaScript("arguments[0].click();", e); } catch (StaleElementReferenceException) { driver.ExecuteJavaScript("arguments[0].click();", e); } }
/* * Enter text in the textbox */ void IActionsVisitor.visitTextBox(ArcliteTextBox element, InputVal wanted) { string text = wanted.getSelectedVal(); IWebElement input; long number = 0; bool canConvert = long.TryParse(text, out number); if (element._secondXPath == null) { try { input = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(element.elementXPath))); new ArcliteButton("", element.elementXPath).accept(this, new InputVal()); } catch (WebDriverTimeoutException) { input = driver.FindElement(By.XPath(element.elementXPath)); } } else { input = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(element.elementXPath + wanted.valTwo + element._secondXPath))); new ArcliteButton("", element.elementXPath + wanted.valTwo + element._secondXPath).accept(this, new InputVal()); } if (canConvert) { input.Clear(); input.SendKeys(text); } else { driver.ExecuteJavaScript("arguments[0].value = '" + text + "';", input); } }
public void clickWhenReady(By locator, int timeout) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)); WebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(locator)); element.Click(); }
//[Ignore("Ignore a test")] public void ExecuteReposytoryCreation() { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); Assert.Multiple(() => { Assert.AreEqual(driver.Title, "GitHub", "Page title is incorrect"); Assert.IsTrue(driver.FindElement(By.XPath("//a[@class='btn shelf-cta mx-2 mb-3']")).Text.Equals("Start a project"), "Button 'SP' is absent"); Assert.IsTrue(driver.FindElement(By.XPath("//a[@class='btn btn-primary shelf-cta mx-2 mb-3']")).Displayed, "Block 'Read the guide' is absent"); }); Log.Information("Third block of Asserts is passed"); RepositoryCreator repositoryCreator1 = new RepositoryCreator(); PageFactory.InitElements(driver, repositoryCreator1); repositoryCreator1.startProjectButton.Click(); Assert.Multiple(() => { Assert.AreEqual(driver.Title, "Create a New Repository", "Incorrect page title"); Assert.IsTrue(driver.FindElement(By.XPath("//input[@id='repository_visibility_public']")).Selected, "Check-box 'Public' is NOT selected"); Assert.IsFalse(driver.FindElement(By.XPath("//input[@id='repository_visibility_private']")).Selected, "Check-box 'Private' is selected"); Assert.IsFalse(driver.FindElement(By.XPath("//input[@id='repository_auto_init']")).Selected, "Check-box 'ReadME' is selected"); Assert.IsTrue(driver.FindElement(By.XPath("//button[@class='btn btn-primary first-in-line']")).Displayed, "Button 'Create Repository' is absent"); }); Log.Information("Forth block of Asserts is passed"); bool selection = driver.FindElement(By.XPath("//input[@id='repository_name']")).Displayed && driver.FindElement(By.XPath("//input[@id='repository_description']")).Displayed && driver.FindElement(By.XPath("//input[@id='repository_auto_init']")).Displayed; switch (selection) { case true: repositoryCreator1.typeRepositoryName.SendKeys(RepositoryName); repositoryCreator1.typeDescription.SendKeys(Description); repositoryCreator1.readMeRadioButton.Click(); IWebElement createButton = wait.Until(ExpectedConditions.ElementToBeClickable( By.XPath("//button[@class='btn btn-primary first-in-line']"))); repositoryCreator1.createRepositoryButton.Click(); Log.Information("Repository is created successfully! Time is {Now}", DateTime.Now); Thread.Sleep(2000); break; case false: Log.Information("Fail of Repository Creation! Time is {Now}", DateTime.Now); break; default: Log.Information("That's impossible!"); break; } }
//[Ignore("Ignore a test")] public void ExecuteFileCreation() { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); Assert.Multiple(() => { Assert.IsTrue(driver.FindElement(By.XPath("//h2[@class='shelf-title']")).Text.Equals("Learn Git and GitHub without any code!"), "Incorrect main title"); Assert.IsTrue(driver.FindElement(By.XPath("//span[@class='text-gray-dark mr-2']")).Text.Equals(Description), "Incorrect Description of repository"); Assert.IsTrue(driver.FindElement(By.XPath("//button[@class='btn btn-sm BtnGroup-item']")).Displayed, "Button 'Create New File' is absent"); }); Log.Information("Fifth block of Asserts is passed"); FileCreator fileCreator1 = new FileCreator(); PageFactory.InitElements(driver, fileCreator1); fileCreator1.clickCreateFile.Click(); Assert.Multiple(() => { Assert.IsTrue(driver.FindElement(By.XPath("//a[@class='Header-link']//*[local-name()='svg']")).Displayed, "The Button 'CommitButton' is absent"); Assert.IsTrue(driver.FindElement(By.XPath("//div[contains(@class,'form-checkbox pl-4 mt-0 mb-2')]//label[1]/input")).Selected, "Check-box 'Commit directly to the master branch' is NOT selected"); Assert.IsFalse(driver.FindElement(By.XPath("//div[contains(@class,'form-checkbox pl-4 my-0')]//label[1]/input")).Selected, "Check-box 'Create a new branch for this commit and start a pull request' is NOT selected"); Assert.IsTrue(driver.FindElement(By.XPath("//a[contains(@class,'btn btn-danger flex-auto text-center mx-3 mx-md-0')]")).Enabled, "The Button 'CANCEL' is NOT selected"); }); Log.Information("Sixth block of Asserts is passed"); if ( driver.FindElement(By.XPath("//input[@placeholder='Name your file…']")).Displayed && driver.FindElement(By.XPath("//pre[contains(@class,'CodeMirror-line')]")).Displayed && driver.FindElement(By.XPath("//input[@id='commit-summary-input']")).Displayed && driver.FindElement(By.XPath("//textarea[@id='commit-description-textarea']")).Displayed ) { fileCreator1.typeNameFile.SendKeys(NameFile); fileCreator1.typeBodyFile.SendKeys(BodyFile); fileCreator1.typeCommitFile.SendKeys(CommitFile); fileCreator1.typeCommitDescription.SendKeys(CommitDescription); fileCreator1.clickCommitButton.Click(); IWebElement logoButton = wait.Until(ExpectedConditions.ElementToBeClickable( By.XPath("//a[@class='Header-link']//*[local-name()='svg']"))); fileCreator1.clickLogo.Click(); Log.Information("File Creation process is executed successfully! Time is {Now}", DateTime.Now); } else { Log.Error("Elements are absent!Time is {Now}", DateTime.Now); } }
public static IWebElement WaitUntilElementClickable(IWebElement element, int timeout = 30) { try { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)); return(wait.Until(ExpectedConditions.ElementToBeClickable(element))); } catch (NoSuchElementException) { Console.WriteLine("Element with locator: '" + element + "' was not found in current context page."); throw; } }
internal void ClickGoogleLinkAndFillInformation() { InitiateWaitVariable(); wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//span[contains(text(),'Google')]"))).Click(); wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//input[@type='email']"))).SendKeys("*****@*****.**"); Driver.FindElement(By.XPath("//*[@class='VfPpkd-LgbsSe VfPpkd-LgbsSe-OWXEXe-k8QpJ VfPpkd-LgbsSe-OWXEXe-dgl2Hf nCP5yc AjY5Oe DuMIQc qIypjc TrZEUc lw1w4b']")).Click(); wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@type='password']"))).SendKeys("lordNikon"); Driver.FindElement(By.XPath("//*[@class='VfPpkd-LgbsSe VfPpkd-LgbsSe-OWXEXe-k8QpJ VfPpkd-LgbsSe-OWXEXe-dgl2Hf nCP5yc AjY5Oe DuMIQc qIypjc TrZEUc lw1w4b']")).Click(); bool isAcctCreated; try { var acctCreated = wait.Until(ExpectedConditions.ElementExists(By.XPath("//span[contains(text(),'Hi Yavor')]"))).Enabled; isAcctCreated = Convert.ToBoolean(acctCreated); } catch (WebDriverTimeoutException exc) { Console.WriteLine(exc.Message); isAcctCreated = false; } if (isAcctCreated) { var myAcct = Driver.FindElement(By.XPath("//span[@type='accountFilled']")); myAcct.Click(); var acctName = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//span[contains(text(),'Hi Yavor')]"))).Text; Console.WriteLine("You have already registered account with this name: " + acctName); } else { wait.Until(ExpectedConditions.ElementIsVisible(By.Id("BirthDay"))).Click(); Driver.FindElement(By.XPath("//option[@value='27']")).Click(); Driver.FindElement(By.Id("BirthMonth")).Click(); Driver.FindElement(By.XPath("//option[contains(text(),'January')]")).Click(); Driver.FindElement(By.Id("BirthYear")).Click(); Driver.FindElement(By.XPath("//option[@value='1982']")).Click(); Driver.FindElement(By.XPath("//label[contains(text(),'Menswear')]")).Click(); Driver.FindElement(By.Id("promosLabel")).Click(); Driver.FindElement(By.Id("newnessLabel")).Click(); Driver.FindElement(By.Id("register")).Click(); } }
/* * gets the value from a textbox */ string IActionsVisitor.getValue(ArcliteTextBox textbox) { IWebElement input; try { input = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(textbox.elementXPath))); } catch (WebDriverTimeoutException) { input = driver.FindElement(By.XPath(textbox.elementXPath)); } string res = input.GetAttribute("value"); return(res); }
/* * Enter text in a search box and clicks on search button if there is one */ void IActionsVisitor.visitSearch(ArcliteSearch arcliteSearch, InputVal wanted) { if (arcliteSearch._searchButtonXpath == null) { IArcliteWebElement search = new ArcliteTextBox("", arcliteSearch._searchInputXPath); search.accept(this, wanted); IWebElement webElement; webElement = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(search.elementXPath))); webElement.SendKeys(Keys.Enter); } else { IArcliteWebElement search = new ArcliteTextBox("", arcliteSearch._searchInputXPath); search.accept(this, wanted); IArcliteWebElement confirm = new ArcliteButton("", arcliteSearch._searchButtonXpath); confirm.accept(this, new InputVal()); } }
/* * visit canvas in workflow builder and createds one step, and opens it */ void IActionsVisitor.visitCanvas(ArcliteCanvas element, InputVal wanted) { int baseX = 170; int baseY = 130; int destX = int.Parse(wanted.valOne); int destY = int.Parse(wanted.valTwo); IWebElement canvas = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(element.elementXPath))); Actions click = new Actions(driver); element.addStep.accept(this, new InputVal()); click.MoveToElement(canvas, baseX, baseY).ClickAndHold().Build().Perform(); click.MoveByOffset(destX, destY).Build().Perform(); click.Release().Build().Perform(); click.MoveToElement(canvas, destX + baseX, destY + baseY).DoubleClick().Build().Perform(); }
internal void ClickMyProfileIcon() { InitiateWaitVariable(); Driver.FindElement(By.XPath("//*[@type='accountUnfilled']")).Click(); wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[@data-testid='signin-link']"))).Click(); }
protected void WaitElementIsClickable(By locator, int seconds) { var waiter = new WebDriverWait(_driver, TimeSpan.FromSeconds(seconds)); waiter.Until(ExpectedConditions.ElementToBeClickable(locator)); }