Untitled
package testpackage.Tests; import static Common.Constants.*; import Common.Constants; import net.thucydides.core.annotations.Steps; import net.thucydides.core.annotations.Title; import steps.AlertSteps; import steps.HomepageSteps; import steps.LoginSteps; import steps.NavigationSteps; import steps.ProductSteps; import org.junit.Test; import org.junit.internal.TextListener; import org.junit.runner.JUnitCore; import org.junit.Before; import org.apache.xerces.impl.xpath.XPath; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.junit.After; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.Dimension; import org.openqa.selenium.JavascriptExecutor; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.time.Duration; import java.util.*; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.WebDriverWait; import testpackage.base.BaseTest; import org.openqa.selenium.interactions.Actions; public class SanityTest extends BaseTest { private LoginSteps loginPage; private AlertSteps alertPage; private NavigationSteps navigation; private ProductSteps productSteps; @Before public void setUp() throws IOException, ParseException { this.loginPage = new LoginSteps(this.driver); this.alertPage = new AlertSteps(this.driver); this.navigation = new NavigationSteps(this.driver); this.productSteps = new ProductSteps(this.driver); //parseJson("testpackage/jsons/login.json"); } // @Test // @Title("Login success") // public void test1() throws InterruptedException { // logger.info("test1 started"); // // this.navigation.clickOnLoginLink(); // // this.loginPage.fillUsernameField(VALID_USERNAME); // sleep(); // this.loginPage.fillPasswordField(VALID_PASSWORD); // sleep(); // this.navigation.clickOnLoginButton(); // sleep(4000); // this.loginPage.checkTextOfWelcome(VALID_USERNAME); // logger.error("test1 finished"); // } // @Test // @Title("Login failed , username is not exist") // public void test2() throws InterruptedException { // logger.info("test2 started"); // // this.navigation.clickOnLoginLink(); // sleep(1000); // this.loginPage.fillUsernameField("sdgadgs41gas12rgarg61argar"); // sleep(); // this.loginPage.fillPasswordField(VALID_PASSWORD); // sleep(); // this.navigation.clickOnLoginButton(); // sleep(); // this.alertPage.verifyAlertMessage(LOGIN_USER_NOT_EXIST_MESSAGE); // sleep(); // this.alertPage.clickOk(); // logger.error("test2 finished"); // } /* @Test @Title("Login failed , password is wrong") public void test3() throws InterruptedException { logger.info("test3 started"); this.navigation.clickOnLoginLink(); this.loginPage.fillUsernameField(VALID_USERNAME); sleep(); this.loginPage.fillPasswordField(UNVALID_PASSWORD); sleep(); this.navigation.clickOnLoginButton(); sleep(); this.alertPage.verifyAlertMessage(LOGIN_WRONG_PASSWORD_MESSAGE); this.alertPage.clickOk(); logger.error("test3 finished"); } @Test @Title("Login failed , password is empty") public void test4() throws InterruptedException { logger.info("test4 started"); this.navigation.clickOnLoginLink(); this.loginPage.fillUsernameField(VALID_USERNAME); sleep(); this.loginPage.fillPasswordField(""); sleep(); this.navigation.clickOnLoginButton(); sleep(); this.alertPage.verifyAlertMessage(LOGIN_MISSING_VALUES_MESSAGE); this.alertPage.clickOk(); logger.error("test4 finished"); } @Test @Title("Login failed , Username is empty") public void test5() throws InterruptedException { logger.info("test5 started"); this.navigation.clickOnLoginLink(); this.loginPage.fillUsernameField(""); sleep(); this.loginPage.fillPasswordField(VALID_PASSWORD); sleep(); this.navigation.clickOnLoginButton(); sleep(); this.alertPage.verifyAlertMessage(LOGIN_MISSING_VALUES_MESSAGE); this.alertPage.clickOk(); logger.error("test5 finished"); } @Test @Title("Login failed , Username & Password is empty") public void test6() throws InterruptedException { logger.info("test6 started"); this.navigation.clickOnLoginLink(); this.loginPage.fillUsernameField(""); sleep(); this.loginPage.fillPasswordField(""); sleep(); this.navigation.clickOnLoginButton(); sleep(); this.alertPage.verifyAlertMessage(LOGIN_MISSING_VALUES_MESSAGE); this.alertPage.clickOk(); logger.error("test6 finished"); } @Test @Title("clicking x and exit log in form") public void test7() throws InterruptedException { logger.info("test7 started"); this.navigation.clickOnLoginLink(); sleep(); this.loginPage.clickOnX(); logger.error("test7 finished"); } */ @Test @Title("all flow of sanity check") public void test8() throws InterruptedException { logger.info("test8 started"); this.navigation.clickOnLoginLink(); sleep(2000); this.loginPage.fillUsernameField("dori123321123321"); sleep(2000); this.loginPage.fillPasswordField("111111"); sleep(2000); this.navigation.clickOnLoginButton(); sleep(); this.navigation.clickOnHomeLink(); sleep(); logger.info("until 1"); this.productSteps.clickOnIphoneItem(); sleep(); this.productSteps.clickOnAddItem(); sleep(); this.alertPage.clickOk(); sleep(); this.navigation.clickOnCartLink(); sleep(); logger.info("until 2"); this.productSteps.verifyProductAdded("Samsung galaxy s6"); sleep(); this.productSteps.verifyTotalPrice("360"); sleep(); this.navigation.clickOnHomeLink(); sleep(); this.productSteps.clickOnIphoneItem(); sleep(); logger.info("until 3"); this.productSteps.clickOnAddItem(); sleep(); this.alertPage.clickOk(); sleep(); this.navigation.clickOnCartLink(); sleep(); this.productSteps.verifyTotalPrice("720"); sleep(); this.productSteps.clickOnDeleteItem(); sleep(); logger.info("until 4"); this.productSteps.verifyTotalPrice("360"); sleep(); this.productSteps.clickOnDeleteItem(); sleep(); this.productSteps.verifyTotalPriceIsEmpty(); sleep(); this.navigation.logOut(); logger.error("test8 and last finished"); } public static void main(String args[]) { JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); org.junit.runner.Result result = junit.run(SanityTest.class); // Replace "SampleTest" with the name of your class if (result.getFailureCount() > 0) { System.out.println("Test failed."); System.exit(1); } else { System.out.println("Test finished successfully."); System.exit(0); } } } /* public void parseJson() { InputStream inputStream = getClass().getClassLoader().getResourceAsStream("testpackage/jsons/login.json"); if (inputStream != null) { try { JSONParser jsonParser = new JSONParser(); InputStreamReader reader = new InputStreamReader(inputStream); this.json = (JSONArray) jsonParser.parse(reader); // Assign to class variable this.users // Now you can work with the JSONArray object } catch (Exception e) { e.printStackTrace(); } } else { System.err.println("File not found!"); } } */ /* //wait .. but we need a loot of data types to get !!... for (int i = 0; i < json.size(); i++) { JSONObject obj = (JSONObject) json.get(i); this.loginPage.clickLoginButton(); this.loginPage.fillUsernameField((String) obj.get("username")); this.loginPage.fillPasswordField((String) obj.get("password")); this.loginPage.clickOnLoginButton(); this.alertSteps.verifyAlertMessage(LOGIN_WRONG_PASSWORD_MESSAGE); if (driver.getCurrentUrl().contains((String) obj.get("expectedResult"))) { System.out.println("test passed"); } else { System.out.println("test failed"); } } */ /* * @Test @Title("Login success") public void testLoginSuccess() { loginSteps.fillUsernameField(REGISTERED_USER); loginSteps.fillPasswordField(REGISTERED_USER_PASSWORD); loginSteps.clickOnLoginButton(); } @Test @Title("Login with Wrong password") public void testLoginWithWrongPassword() { loginSteps.fillUsernameField(REGISTERED_USER); loginSteps.fillPasswordField(REGISTERED_USER_WRONG_PASSWORD); loginSteps.clickOnLoginButton(); //alertSteps.verifyAlertMessage(LOGIN_WRONG_PASSWORD_MESSAGE); } @Test @Title("Login with empty password field") public void testLoginWithEmptyPassword() { loginSteps.fillUsernameField(REGISTERED_USER); loginSteps.clickOnLoginButton(); //alertSteps.verifyAlertMessage(LOGIN_MISSING_PASSWORD_MESSAGE); } */ /* * /// to change @Test public void placeOrderFromCart() { // Add a product to the cart driver.findElement(By.linkText("Samsung Galaxy S20")).click(); driver.findElement(By.linkText("Add to cart")).click(); // Proceed to the cart and checkout driver.findElement(By.linkText("Cart")).click(); driver.findElement(By.linkText("Place Order")).click(); // Fill in shipping details driver.findElement(By.id("name")).sendKeys("John Doe"); driver.findElement(By.id("country")).sendKeys("United States"); driver.findElement(By.id("city")).sendKeys("New York"); driver.findElement(By.id("card")).sendKeys("1234 5678 9012 3456"); // Complete the order driver.findElement(By.cssSelector("button[type='submit']")).click(); // Verify order confirmation String confirmationMessage = driver.findElement(By.className("confirm-message")).getText(); if (confirmationMessage.contains("Thank you for your purchase!")) { System.out.println("Order placement test passed. Order confirmed successfully."); } else { System.out.println("Order placement test failed. Order confirmation message not found."); } } */
Leave a Comment