Wednesday, January 21, 2015

Selenium Register and Log-in Test Automation

  // objects and variables instantiation
   WebDriver driver = new FirefoxDriver();
 
// Clear cache and cookies  
      driver.manage().deleteAllCookies(); //delete all cookies

// maximize the browser window
   driver.manage().window().maximize();

//click on the Login button
   WebElement logInNav = driver.findElement(By.partialLinkText("Log"));
   logInNav.click();

//create new account (Deutsch interface)
   WebElement createAccount = driver.findElement(By.partialLinkText("Konto"));
   createAccount.click();
 
// enter a valid username in the email textbox
     WebElement usernamereg = driver.findElement(By.name("user[email]"));
     usernamereg.clear();
     usernamereg.sendKeys("mz@rocketmail.com");
 
// enter a valid password in the password textbox
   WebElement passwordreg = driver.findElement(By.name("user[password]"));
   passwordreg.clear();
   passwordreg.sendKeys("abcdef");

// Select the terms and conditions checkbox
   if ( !driver.findElement(By.id("user_terms_and_conditions")).isSelected())
   {
        driver.findElement(By.id("user_terms_and_conditions")).click();
   }


 //click on the Konto anlegen (create account) button
  kontoAnlegenButton = driver.findElement(By.xpath("(//button[@type='submit'])[2]"));
//WebElement kontoAnlegenButton = driver.findElement(By.partialLinkText("Konto"));
    kontoAnlegenButton.click();
 
 
  //click on the Login button
   WebElement logInInitial = driver.findElement(By.partialLinkText("Log"));
   logInInitial.click();
 
  // enter a valid username in the email textbox
     WebElement username = driver.findElement(By.name("user[email]"));
     username.clear();
     username.sendKeys("abcd@yahoo.com");
 
// enter a valid password in the password textbox
   WebElement password = driver.findElement(By.name("user[password]"));
   password.clear();
   password.sendKeys("abcdef");
 
//click on the Login button
   WebElement logInButton = driver.findElement(By.xpath("//button[@type='submit']"));
   logInButton.click();
 

// launch the home url of the application
    String homeUrl = "http://staging.farmilio.net";
   driver.get(homeUrl);
   
//click on the Start Farmilio link
   WebElement startFarmilio = driver.findElement(By.partialLinkText("Direkt"));
   startFarmilio.click();
 

//Enter offer name/s in the Searchbox
   WebElement searchBox = driver.findElement(By.xpath("//input[@type='text']"));
   searchBox.clear();
   searchBox.sendKeys("fruits");
 

//click on the Search button
   WebElement searchButton = driver.findElement(By.xpath("//button[@type='submit']"));
   searchButton.click();

 
// close the web browser
   driver.close();
   System.out.println("Test script executed successfully.");
 
// terminate the program
   System.exit(0);

No comments :

Post a Comment