public void ExplicitWaitsUnreachableElementFailingTest() { using (IWebDriver driver = new ChromeDriver(".")) { try { output.WriteLine($"{DateTime.Now.ToLongTimeString()} Navigate to Home Page"); driver.Navigate().GoToUrl(HomePageUrl); DemoHelper.Pause(); output.WriteLine($"{DateTime.Now.ToLongTimeString()} Finding Element"); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(35)); IWebElement clickApplyNowButton = wait.Until((d) => d.FindElement(By.ClassName("customer-service-apply-now"))); output.WriteLine($"{DateTime.Now.ToLongTimeString()} Found Element Displayed:{clickApplyNowButton.Displayed} and Enabled:{clickApplyNowButton.Enabled}"); output.WriteLine($"{DateTime.Now.ToLongTimeString()} Clicking Element"); clickApplyNowButton.Click(); DemoHelper.Pause(); Assert.Equal(ApplyUrl, driver.Url); Assert.Equal(CreditCardPageTile, driver.Title); } catch (Exception e) { output.WriteLine($"{e} Reason for Failure: Button is still not Enabled or displayed"); } } }
public void ReloadHomePage() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(homeUrl); driver.Manage().Window.Maximize(); DemoHelper.Pause(); driver.Manage().Window.Minimize(); DemoHelper.Pause(); driver.Manage().Window.Size = new System.Drawing.Size(300, 400); DemoHelper.Pause(); driver.Manage().Window.Position = new System.Drawing.Point(1, 1); DemoHelper.Pause(); driver.Manage().Window.Position = new System.Drawing.Point(50, 50); DemoHelper.Pause(); driver.Manage().Window.Position = new System.Drawing.Point(100, 100); DemoHelper.Pause(); driver.Manage().Window.FullScreen(); DemoHelper.Pause(5000); Assert.Equal(homeTitle, driver.Title); Assert.Equal(homeUrl, driver.Url); } }
public void BeInitiatedFromHomePage_CustomerService() { using (IWebDriver driver = new ChromeDriver()) { _output.WriteLine($"{DateTime.Now.ToLongTimeString()} Navigating to HomeUrl"); driver.Navigate().GoToUrl(HomeUrl); _output.WriteLine($"{DateTime.Now.ToLongTimeString()} Finding element using explicit way"); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(35)); //IWebElement carouselNext = driver.FindElement(By.CssSelector("[data-slide='next']")); //carouselNext.Click(); //DemoHelper.Pause(1000); // allow carousel to scroll //carouselNext.Click(); //DemoHelper.Pause(1000); // allow carousel to scroll IWebElement applyLink = wait.Until(d => d.FindElement(By.ClassName("customer-service-apply-now"))); _output.WriteLine($"{DateTime.Now.ToLongTimeString()} " + $"Finding element Displayed={applyLink.Displayed} Enabled={applyLink.Enabled}"); _output.WriteLine($"{DateTime.Now.ToLongTimeString()} Clicking element"); applyLink.Click(); DemoHelper.Pause(); Assert.Equal("Credit Card Application - Credit Cards", driver.Title); Assert.Equal(ApplyUrl, driver.Url); } }
public void BeInitiatedFromHomePage_EasyApplication() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(homeUrl); DemoHelper.Pause(); IWebElement carouselNext = driver.FindElement(By.CssSelector("[data-slide='next']")); carouselNext.Click(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(1)); //Possible to remove upper carousel clik when set appopriete time this TimeSpan.FromSeconds IWebElement applyLink = wait.Until((d) => d.FindElement(By.LinkText("Easy: Apply Now!"))); applyLink.Click(); //IWebElement applyLink = driver.FindElement(By.LinkText("Easy: Apply Now!")); //applyLink.Click(); DemoHelper.Pause(); Assert.Equal("Credit Card Application - Credit Cards", driver.Title); Assert.Equal(ApplyUrl, driver.Url); } }
public void ReloadHomePageOnForward() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(AboutUrl); DemoHelper.Pause(); driver.Navigate().GoToUrl(HomeUrl); DemoHelper.Pause(); IWebElement generationTokenElement = driver.FindElement(By.Id("GenerationToken")); string initialToken = generationTokenElement.Text; driver.Navigate().Back(); DemoHelper.Pause(); driver.Navigate().Forward(); DemoHelper.Pause(); Assert.Equal(HomeTitle, driver.Title); Assert.Equal(HomeUrl, driver.Url); string reloadedToken = driver.FindElement(By.Id("GenerationToken")).Text; Assert.NotEqual(initialToken, reloadedToken); } }
public void BeSubmittedValid_VerifyFields() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(formsUrl); DemoHelper.Pause(); //IWebElement randomGreetingLinkText = // driver.FindElement(By.XPath("//*[@id='app']/div/div/div[2]/div[1]/div/div/div[2]/div")); IWebElement a = driver.FindElement(By.XPath("//div[@class='element-list collapse show']//*[name()='svg'][@stroke = 'currentColor']")); Actions builder = new Actions(driver); builder.Click(a).Build().Perform(); string ur = driver.Url.Replace("/forms", ""); driver.Navigate().GoToUrl(ur); IWebElement firstNameField = driver.FindElement(By.Id("firstName")); // firstNameField.SendKeys("Farrukh"); IWebElement lastNameField = driver.FindElement(By.Id("lastName")); IWebElement gender = driver.FindElement(By.Name("gender")); IWebElement singleRadioButton = driver.FindElement(By.Id("gender-radio-1")); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].checked = true;", singleRadioButton); Assert.True(!string.IsNullOrEmpty(firstNameField.GetAttribute("value")), "first name is required field"); Assert.True(!string.IsNullOrEmpty(lastNameField.GetAttribute("value")), "last name is required field"); Assert.True(!gender.Selected, "Gender is required field"); //lastNameField.SendKeys("Khan"); //userEmail // driver.FindElement(By.Id("userEmail")).SendKeys("*****@*****.**"); //IWebElement singleRadioButton = driver.FindElement(By.Id("gender-radio-1")); //((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].checked = true;", singleRadioButton); ////userNumber //driver.FindElement(By.Id("userNumber")).SendKeys("3132417761"); //// driver.FindElement(By.Id("submit")).Click(); //IWebElement submitBtn = driver.FindElement(By.Id("submit")); //((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", submitBtn); } }
public void LoadHomePage() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(homeUrl); DemoHelper.Pause(); Assert.Equal(homeTitle, driver.Title); Assert.Equal(homeUrl, driver.Url); } }
public void LoadApplicationPage() { using (IWebDriver driver = new ChromeDriver()) //opens and closes chrome { driver.Navigate().GoToUrl(HomeUrl); //calls the browser to go to a specific page DemoHelper.Pause(); Assert.Equal(HomeTitle, driver.Title); Assert.Equal(HomeUrl, driver.Url); } }
public void BeSubmittedWhenValid() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(ApplyUrl); driver.FindElement(By.Id("FirstName")).SendKeys("Sarah"); DemoHelper.Pause(); driver.FindElement(By.Id("LastName")).SendKeys("Smith"); DemoHelper.Pause(); driver.FindElement(By.Id("FrequentFlyerNumber")).SendKeys("123456-A"); DemoHelper.Pause(); driver.FindElement(By.Id("Age")).SendKeys("18"); DemoHelper.Pause(); driver.FindElement(By.Id("GrossAnnualIncome")).SendKeys("50000"); DemoHelper.Pause(); driver.FindElement(By.Id("Single")).Click(); DemoHelper.Pause(); IWebElement businessSourceSelectElement = driver.FindElement(By.Id("BusinessSource")); SelectElement businessSource = new SelectElement(businessSourceSelectElement); // Check default selected option is correct Assert.Equal("I'd Rather Not Say", businessSource.SelectedOption.Text); // Get all the available options foreach (IWebElement option in businessSource.Options) { output.WriteLine($"Value: {option.GetAttribute("value")} Text: {option.Text}"); } Assert.Equal(5, businessSource.Options.Count); // Select an option businessSource.SelectByValue("Email"); DemoHelper.Pause(); businessSource.SelectByText("Internet Search"); DemoHelper.Pause(); businessSource.SelectByIndex(4); // Zero-based driver.FindElement(By.Id("TermsAccepted")).Click(); //driver.FindElement(By.Id("SubmitApplication")).Click(); driver.FindElement(By.Id("Single")).Submit(); Assert.StartsWith("Application Complete", driver.Title); Assert.Equal("ReferredToHuman", driver.FindElement(By.Id("Decision")).Text); Assert.NotEmpty(driver.FindElement(By.Id("ReferenceNumber")).Text); Assert.Equal("Sarah Smith", driver.FindElement(By.Id("FullName")).Text); Assert.Equal("18", driver.FindElement(By.Id("Age")).Text); Assert.Equal("50000", driver.FindElement(By.Id("Income")).Text); Assert.Equal("Single", driver.FindElement(By.Id("RelationshipStatus")).Text); Assert.Equal("TV", driver.FindElement(By.Id("BusinessSource")).Text); } }
public void BeInitiatedFromHomePage_CustomerService() { using (IWebDriver driver = new ChromeDriver()) { output.WriteLine($"{DateTime.Now.ToLongTimeString()} Navigating to {homeUrl}"); driver.Navigate().GoToUrl(homeUrl); output.WriteLine($"{DateTime.Now.ToLongTimeString()} Setting implicit wait"); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(35); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(35)); Func <IWebDriver, IWebElement> findEnabledAndVisible = delegate(IWebDriver d) { var e = d.FindElement(By.ClassName("customer-service-apply-now")); if (e is null) { throw new NotFoundException(); } if (e.Enabled && e.Displayed) { return(e); } throw new NotFoundException(); }; IWebElement applyLink = wait.Until(findEnabledAndVisible); output.WriteLine($"{DateTime.Now.ToLongTimeString()} Navigating to {homeUrl}"); driver.Navigate().GoToUrl(homeUrl); /*IWebElement carouselNext = driver.FindElement(By.CssSelector("[data-slide='next']")); * carouselNext.Click(); * DemoHelper.Pause(1000); * carouselNext.Click(); * DemoHelper.Pause(1000); * * output.WriteLine($"{DateTime.Now.ToLongTimeString()} Finding element"); * IWebElement applyLink = driver.FindElement(By.ClassName("customer-service-apply-now"));*/ output.WriteLine($"{DateTime.Now.ToLongTimeString()} Found element Displayed={applyLink.Displayed} Enabled={applyLink.Enabled}"); applyLink.Click(); DemoHelper.Pause(); Assert.Equal("Credit Card Application - Credit Cards", driver.Title); Assert.Equal(ApplyUrl, driver.Url); } }
public void DisplayProductAndRates() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(homeUrlPluralsight); DemoHelper.Pause(); IWebElement firstTableCell = driver.FindElement(By.TagName("td")); string cellValue = firstTableCell.Text; Assert.Equal("Easy Credit Card", cellValue); } }
public void ReloadHomePage() { // smoke test using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(HomeUrl); DemoHelper.Pause(); driver.Navigate().Refresh(); Assert.Equal(HomeTitle, driver.Title); Assert.Equal(HomeUrl, driver.Url); } }
public void BeInitiatedFromHomePage_NewLowRate() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(homeUrlPluralsight); DemoHelper.Pause(); IWebElement applyLink = driver.FindElement(By.Name("ApplyLowRate")); applyLink.Click(); DemoHelper.Pause(); Assert.Equal(creditCardAppTitle, driver.Title); } }
public void BeInitiatedFromHomePage_RandomGreeting_Using_XPATH() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(HomeUrl); DemoHelper.Pause(); IWebElement randomGreetingLink = driver.FindElement(By.XPath("//a[text()[contains(.,'- Apply Now!')]]")); randomGreetingLink.Click(); Assert.Equal("Credit Card Application - Credit Cards", driver.Title); Assert.Equal(ApplyUrl, driver.Url); } }
public void DisplayProductsAndRates() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(HomeUrl); DemoHelper.Pause(); IWebElement firstTableCell = driver.FindElement(By.TagName("td")); string firstProduct = firstTableCell.Text; Assert.Equal("Easy Credit Card", firstProduct); // TODO: check rest of product table } }
public void BeInitiatedFromHomePage_NewLowRate() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(HomeUrl); DemoHelper.Pause(); IWebElement applyLink = driver.FindElement(By.Name("ApplyLowRate")); applyLink.Click(); DemoHelper.Pause(); Assert.Equal("Credit Card Application - Credit Cards", driver.Title); Assert.Equal(ApplyUrl, driver.Url); } }
public void BeInitiatedFromHomePage_RandomGreeting() { ChromeDriverFixture.Driver.Navigate().GoToUrl(HomeUrl); DemoHelper.Pause(); IWebElement randomGreetingApplyLink = ChromeDriverFixture.Driver.FindElement(By.PartialLinkText("- Apply Now!")); randomGreetingApplyLink.Click(); DemoHelper.Pause(); Assert.Equal("Credit Card Application - Credit Cards", ChromeDriverFixture.Driver.Title); Assert.Equal(ApplyUrl, ChromeDriverFixture.Driver.Url); }
public void ReloadPage() { using (IWebDriver driver = new ChromeDriver(".")) { driver.Navigate().GoToUrl(HomePageUrl); //IWebElement initialContext = driver.FindElement(By.Id("GenerationToken")); string initialTokenText = driver.FindElement(By.Id("GenerationToken")).Text; DemoHelper.Pause(); driver.Navigate().Refresh(); string refreshTokenText = driver.FindElement(By.Id("GenerationToken")).Text; Assert.Equal(HomePageTitle, driver.Title); Assert.Equal(HomePageUrl, driver.Url); Assert.NotEqual(initialTokenText, refreshTokenText); } }
public void BeSubmittedValid() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(formsUrl); DemoHelper.Pause(); //IWebElement randomGreetingLinkText = // driver.FindElement(By.XPath("//*[@id='app']/div/div/div[2]/div[1]/div/div/div[2]/div")); IWebElement a = driver.FindElement(By.XPath("//div[@class='element-list collapse show']//*[name()='svg'][@stroke = 'currentColor']")); Actions builder = new Actions(driver); builder.Click(a).Build().Perform(); string ur = driver.Url.Replace("/forms", ""); driver.Navigate().GoToUrl(ur); IWebElement firstNameField = driver.FindElement(By.Id("firstName")); firstNameField.SendKeys("Farrukh"); IWebElement lastNameField = driver.FindElement(By.Id("lastName")); lastNameField.SendKeys("Khan"); //userEmail driver.FindElement(By.Id("userEmail")).SendKeys("*****@*****.**"); IWebElement singleRadioButton = driver.FindElement(By.Id("gender-radio-1")); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].checked = true;", singleRadioButton); //userNumber driver.FindElement(By.Id("userNumber")).SendKeys("3132417761"); //dateOfBirthInput IWebElement datePicker = driver.FindElement(By.Id("dateOfBirthInput")); //executeScript("document.getElementById('id').value='1988-01-01'"); ((IJavaScriptExecutor)driver).ExecuteScript("document.getElementById('dateOfBirthInput').value='25 Apr 2021'", datePicker); //((IJavaScriptExecutor)driver).ExecuteScript("return document.getElementById('dateOfBirthInput').value", singleRadioButton); //hobbies-checkbox-1 IWebElement hobbySports = driver.FindElement(By.Id("hobbies-checkbox-1")); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].checked = true;", hobbySports); } }
public void ClickOverlayedLinkText() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl("http://localhost:44108/jsoverlay.html"); DemoHelper.Pause(); string script = "return document.getElementById('HiddenLink').innerHTML;"; IJavaScriptExecutor js = (IJavaScriptExecutor)driver; string linkText = (string)js.ExecuteScript(script); Assert.Equal("Go to Pluralsight", linkText); } }
public void AlertIfLiveChatClosed() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(HomeUrl); driver.FindElement(By.Id("LiveChat")).Click(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5)); IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent()); Assert.Equal("Live chat is currently closed.", alert.Text); DemoHelper.Pause(); alert.Accept(); // clicking OK } }
public void BeInitiatedFromHomePage_RandomGreeting_Using_XPATH() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(HomeUrl); DemoHelper.Pause(); IWebElement randomGreetingApplyLink = driver.FindElement(By.XPath("/html/body/div/div[4]/div/div/p/a")); randomGreetingApplyLink.Click(); DemoHelper.Pause(); Assert.Equal("Credit Card Application - Credit Cards", driver.Title); Assert.Equal(ApplyUrl, driver.Url); } }
public void ReloadPageOnForward() { using (IWebDriver driver = new ChromeDriver(".")) { driver.Navigate().GoToUrl(HomePageUrl); DemoHelper.Pause(); driver.Navigate().GoToUrl(AboutPage); DemoHelper.Pause(); driver.Navigate().Back(); DemoHelper.Pause(); driver.Navigate().Forward(); DemoHelper.Pause(); Assert.Equal(AboutPage, driver.Url); Assert.Equal(AboutPageTitle, driver.Title); } }
public void DisplayProductsAndRates() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(HomeUrl); DemoHelper.Pause(); ReadOnlyCollection <IWebElement> tableCells = driver.FindElements(By.TagName("td")); Assert.Equal("Easy Credit Card", tableCells[0].Text); Assert.Equal("20% APR", tableCells[1].Text); Assert.Equal("Silver Credit Card", tableCells[2].Text); Assert.Equal("18% APR", tableCells[3].Text); Assert.Equal("Gold Credit Card", tableCells[4].Text); } }
public void OpenContactFooterLinkNewTab() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(HomeUrl); driver.FindElement(By.Id("ContactFooter")).Click(); DemoHelper.Pause(); var allTabs = driver.WindowHandles; var homePageTab = allTabs[0]; var contactTab = allTabs[1]; driver.SwitchTo().Window(contactTab); // driver is now new tab's driver Assert.EndsWith("/Home/Contact", driver.Url); } }
public void VerifyPageWithLinkText() { using (IWebDriver driver = new ChromeDriver(".")) { driver.Navigate().GoToUrl(HomePageUrl); DemoHelper.Pause(); IWebElement next = driver.FindElement(By.CssSelector("[data-slide='next']")); next.Click(); DemoHelper.Pause();//wait time for carasoul IWebElement clickApplyNowButton = driver.FindElement(By.LinkText("Easy: Apply Now!")); clickApplyNowButton.Click(); DemoHelper.Pause(); Assert.Equal(ApplyUrl, driver.Url); Assert.Equal(CreditCardPageTile, driver.Title); } }
public void ReloadHomePageOnBack() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(HomeUrl); string initialToken = generationTokenElement.Text; DemoHelper.Pause(); driver.Navigate().GoToUrl(AboutUrl); DemoHelper.Pause(); driver.Navigate().Back(); DemoHelper.Pause(); Assert.Equal(HomeTitle, driver.Title); Assert.Equal(HomeUrl, driver.Url); } }
public void BeInitiatedFromHomePage_BySelectingXPath() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(homeUrl); DemoHelper.Pause(); IWebElement randomGreetingApplyLink = driver.FindElement(By.XPath("/html/body/div/div[4]/div/p/a")); // RELATIVE XPATH //a[text()[contains(.,'-Apply Now!')]] randomGreetingApplyLink.Click(); DemoHelper.Pause(); Assert.Equal("Credit Card Application - Credit Cards", driver.Title); Assert.Equal(ApplyUrl, driver.Url); } }
public void BeSubmittedWhenValid() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(ApplyUrl); /* First method to write IWebElement firstNameField = driver.FindElement(By.Id("FirstName")); * firstNameField.SendKeys("Sarah"); */ driver.FindElement(By.Id("FirstName")).SendKeys("Sarah"); DemoHelper.Pause(); driver.FindElement(By.Id("LastName")).SendKeys("Wooojcik"); DemoHelper.Pause(); driver.FindElement(By.Id("FrequentFlyerNumber")).SendKeys("123456-A"); DemoHelper.Pause(); driver.FindElement(By.Id("Age")).SendKeys("22"); DemoHelper.Pause(); driver.FindElement(By.Id("GrossAnnualIncome")).SendKeys("50000"); DemoHelper.Pause(); driver.FindElement(By.Id("Single")).Click(); IWebElement businessSourceSelectElement = driver.FindElement(By.Id("BusinessSource")); SelectElement businessSource = new SelectElement(businessSourceSelectElement); //Check default selected option is correct Assert.Equal("I'd Rather Not Say", businessSource.SelectedOption.Text); foreach (IWebElement option in businessSource.Options) { output.WriteLine($"Vaule: {option.GetAttribute("value")} Text: {option.Text}"); } //Select an option businessSource.SelectByValue("Email"); DemoHelper.Pause(); businessSource.SelectByText("Internet Search"); DemoHelper.Pause(); businessSource.SelectByIndex(4); //Zero Based indexing DemoHelper.Pause(); driver.FindElement(By.Id("TermsAccepted")).Click(); //driver.FindElement(By.Id("SubmitApplication")).Click(); First the most basic application submit driver.FindElement(By.Id("GrossAnnualIncome")).Submit(); //Assert.StartsWith("RefferedToHuman",driver.FindElement(By.Id)) } }
public void OpenContactFooterLinkInNewTab() { using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl(homeUrl); driver.FindElement(By.Id("ContactFooter")).Click(); DemoHelper.Pause(); ReadOnlyCollection <string> allTabs = driver.WindowHandles; string homePageTab = allTabs[0]; string contactTab = allTabs[1]; driver.SwitchTo().Window(contactTab); DemoHelper.Pause(); Assert.EndsWith("/Home/Contact", driver.Url); } }