Creating the Main Structure of Your First Selenium Automation Script

Here, we shall be creating the main structure of the script, import the required libraries, and instantiate our WebDriver object. Before you begin, make sure that you have followed the steps in Environment Configuration, of the previous chapter. Then, use IntelliJ IDEA for the creation of a Selenium automation script. The steps for completion of this process are as follows:

  1. Import, via WebDriver, WebElement, and ChromeDriver, the minimum libraries required for a Selenium script to run:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
  1. Create the main class of the script, as follows:
public class ActivityLesson02 {
}

  1. Inside of the ActivityLesson02 class, create a method that will instantiate the driver. Add the quit call, in order to end the session, and then close the browser:
public static void main(String[] args) {
activityLesson02AutomationScript();
}

private static void activityLesson02AutomationScript(){

WebDriver driver = new ChromeDriver();

// the other script code will go here
driver.quit();
}
  1. Compile and execute the script. As in the previous chapter, you should see the Chrome browser open and close.
  1. Save the file as Activity01Lesson02.java.

You should now know how to instantiate a WebDriver variable for Chrome.

..................Content has been hidden....................

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