Activity: Automating Checkout

  1. Open the URL https://trainingbypackt.github.io/Beginning-Selenium/lesson_4/exercise_4_1.html in Chrome. Also, open the Chrome DevTools JavaScript in order to inspect elements.
  2. Locate the first name and last name fields, and write the appropriate values on them. Each one has a unique ID; therefore, the code will look as follows:
WebElement firstName = driver.findElement(By.id("firstName"));
firstName.sendKeys("John");
WebElement lastName = driver.findElement(By.id("lastName"));
lastName.sendKeys("Doe");
  1. Repeat step 2 for the following fields: email, address, zip, name on card, card number, expiration, and CVV:
// Email
WebElement email = driver.findElement(By.id("email"));
email.sendKeys("[email protected]");

// Address
WebElement address = driver.findElement(By.id("address"));
address.sendKeys("Road Drive 200");

// ZIP
WebElement zip = driver.findElement(By.id("zip"));
zip.sendKeys("10117");

// Name on Card
WebElement nameOnCard = driver.findElement(By.id("cc-name"));
nameOnCard.sendKeys("John Doe");

// Card number
WebElement cardNumber = driver.findElement(By.id("cc-number")); cardNumber.sendKeys("4444555566667777");

// Expiration
WebElement expiration = driver.findElement(By.id("ccexpiration"));
expiration.sendKeys("10/18");

// CVV
WebElement cvv = driver.findElement(By.id("cc-cvv"));
cvv.sendKeys("345");
  1. Locate the drop-down field to select a country, and select one. The following Java code has selected Australia:
Select country = new Select(driver.findElement(By.id("country")));
country.selectByVisibleText("Australia");
  1. Locate the checkbox to save the information for next time, and click on it; the Java code will look as follows:
WebElement saveInfo = driver.findElement(By.id("saveinfo"));
saveInfo.click();
  1. Locate and select one of the payment methods. Consider that there are no unique IDs for them, and a good option would be to use a CSS selector with a partial match, in order to find a good locator. The following Java code illustrates how to select the Debit Card payment method:
WebElement debitCard = driver.findElement(By.cssSelector("input[data-payment$='debit']"));
debitCard.click();
  1. Locate and click on the Pay button. The Java code will look as follows:
WebElement pay = driver.findElement(By.id("pay"));
pay.click();
  1. Collect all of the code pieces that you have built while interacting with the page elements, and combine them into a Java class called CheckoutForm.
  2. Run the application by navigating to Run | Run… | CheckoutForm, and observe how your automated script interacts with a checkout form.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.186