Navigating in an Automation Script

The aim here is to navigate between URLs in an automation script. You'll be creating an automation script that navigates between websites. Before you begin, first make sure that you have followed the steps in the previous activity of this chapter. Then, continue to work on the same file from the same activity of this chapter. Finally, include the command that follows in the ActivityLesson02 constructor. 

This will add a wait of five seconds for the pages to load, before attempting to verify the lines of the test. We will review this subject later, in Chapter 5, Waiting for Elements:

driver.manage().timeouts().implicitlyWait(5, TimeUnit.
SECONDS);

The steps for completion of this process are as follows:

  1. Using driver.get();, load any known website:
driver.get("https://www.google.com");
  1. Use getTitle() to verify that the title of the window is equal to the one from the website that you just navigated to (a simple comparison, with an if statement, should be sufficient):
driver.getTitle().equalsIgnoreCase("Google")
  1. Using the System.out.println method, display messages that indicate whether the verification was successful:
{
System.out.println("Script worked, the
title contains 'Google'");
} else {
System.out.println("Something went wrong
with the script, 'Google' was not found");
}
  1. Using navigate().to(""), browse to a new website:
driver.navigate().to("http://www.yahoo.com");
  1. Use driver.getTitle() to verify that the title in the window is the same as the one from the website that you just navigated to (a simple comparison, with an if statement, should be sufficient):
if (driver.getTitle().equalsIgnoreCase("Google"))
  1. Using the System.out.println method, display messages that indicate whether the verification was successful:
{
System.out.println("Script worked, the
title contains 'Yahoo'");
} else {
System.out.println("Something went wrong
with the script, 'Yahoo' was not found");
}
  1. Using navigate().back(), navigate back to Google:
driver.navigate().back();
  1. Use driver.getTitle() to verify that the title in the window is the same as the one from the website that you just navigated to (a simple comparison, with an if statement, should be sufficient):
if (driver.getTitle().equalsIgnoreCase("Google"))
  1. Using the System.out.println method, display messages that indicate whether the verification was successful:
{
System.out.println("Script worked, the
title contains 'Google'");
} else {
System.out.println("Something went wrong
with the script, 'Google' was not found");
}
  1. Compile and run the script.
..................Content has been hidden....................

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