public void TestMethod() { LaunchPage launchPage = new LaunchPage(); LoginPage loginPage = launchPage.GoToLoginPage(); MyHomePage myHomePage = loginPage.DoLogin("aman123", "testing123"); ShoppingCartPage shoppingCartPage = myHomePage.BuyProduct("top"); OrderReviewPage orderReviewPage = shoppingCartPage.ConfirmOrder(); OrderStatusPage orderStatusPage = orderReviewPage.PlaceOrder(); orderStatusPage.GeTTopMenu().LogOut(); // loging out }
public void TestLoginWithInvalidMail() { // Arrange MyHomePage.NavigateToPageUrl(); string[] invalidEmails = { "plainaddress", "#@%^%#$@#$@#.com", "email.domain.com", "email@[email protected]" }; // Act foreach (var email in invalidEmails) { MyHomePage.EnterEmailAddress(email); MyHomePage.CleanDropDown(); // This is bad practice and is for demo purposes only. // Consider using Selenium Wait System.Threading.Thread.Sleep(1000); MyHomePage.Login(); // Assert try { Assert.AreEqual( "Please enter a valid e-mail address", MyHomePage.ErrorMessage.Text, "This error messege shoud appear when invalid mail is entered"); } catch (Exception e) { MakeScreenshot(); Assert.Fail(e.Message, "This error messege shoud appear when invalid mail is entered"); } } }
private static void ClearTransportLevelErrorsBeforeTestRun() { if (AppConfig.RestartDbServerBeforeTestRun && AppConfig.ClearTransportLevelErrorsAfterDbServerRestart) { var firstBrowser = Browsers.FirstOrDefault(); if (firstBrowser != null) { bool errorExists; const string errorMessage = "A transport-level error has occurred"; var signOnPage = new SignOnPage(firstBrowser); var personalHomePage = new MyHomePage(firstBrowser); do // after restarting db server, first couple of form submissions may have { // transport-level errors. these can be cleared by resubmitting the forms. errorExists = false; // go to sign in page firstBrowser.Navigate().GoToUrl(signOnPage.AbsoluteUrl); firstBrowser.WaitUntil(b => b.Url.StartsWith(signOnPage.AbsoluteUrl), string.Format( "Test run failed to initialize in @Browser because it did not arrive at the sign on page.")); // attempt to sign in var element = firstBrowser.WaitUntil(b => b.FindElement(By.Id("EmailAddress")), string.Format( "Test run failed to initialize in @Browser because it could not find an EmailAddress text box on the sign in page.")); element.ClearAndSendKeys("*****@*****.**"); element = firstBrowser.WaitUntil(b => b.FindElement(By.Id("Password")), string.Format( "Test run failed to initialize in @Browser because it could not find a Password text box on the sign in page.")); element.ClearAndSendKeys("asdfasdf"); element = firstBrowser.WaitUntil(b => b.FindElement(By.Id("sign_in_submit_button")), string.Format( "Test run failed to initialize in @Browser because it could not find a sign in submit button.")); element.ClickButton(); firstBrowser.WaitUntil(b => b.Url.StartsWith(signOnPage.AbsoluteUrl) || b.Url.StartsWith(personalHomePage.AbsoluteUrl), string.Format( "Test run failed to initialize in @Browser because it did not arrive at the sign in or about me page.")); // look for a transport-level error ysod var error = firstBrowser.TryFindElement(By.TagName("body")); if (error != null && error.Text.Contains(errorMessage)) { continue; // try again } // go to the about me page firstBrowser.Navigate().GoToUrl(personalHomePage.AbsoluteUrl); firstBrowser.WaitUntil(b => b.Url.StartsWith(personalHomePage.AbsoluteUrl), string.Format( "Test run failed to initialize in @Browser because it did not arrive at the about me page.")); // attempt to save the form (without making any changes) element = firstBrowser.WaitUntil(b => b.FindElement(By.Id("person_name_submit_button")), string.Format( "Test run failed to initialize in @Browser because it could not find a submit button for the about me form.")); element.ClickButton(); firstBrowser.WaitUntil(b => b.Url.StartsWith(personalHomePage.AbsoluteUrl), string.Format( "Test run failed to initialize in @Browser because it did not arrive at the about me page.")); // look for a transport-level error ysod error = firstBrowser.TryFindElement(By.TagName("body")); if (error != null && error.Text.Contains(errorMessage)) { errorExists = true; // try again } } while (errorExists); } } }