Thus far we have been using Selenium IDE in Firefox for functional testing but this plugin is no longer supported. It was time anyway to move on to Selenium itself.

Objective: test a website using Selenium webdriver  for Chrome in a Windows10 environment.

Eclipse setup

Best suited IDE seems to be Eclipse (best Java support?). Netbeans is getting us nowhere.

Download Eclipse

eclipse-java-oxygen-2-win32-x86_64.zip

(btw eclipse-jee-oxygen-2-win32-x86_64.zip will get you into all sorts of trouble)

extract and place Eclipse folder in C:\Program Files

next download selenium-server-standalone-3.8.1.jar from seleniumhq.org.

In Eclipse start a new Java project.

This makes available in the workspace:

  • JRE System Library (Java SE-1.8)
  • an empty SRC folder

Next import the selenium standalone server:

properties >> libraries >> add external jar >> selenium-server-standalone-3.8.1.jar

A new folder is now available (“referenced libraries”) with in it the collection of selenium jar files. Among them the selenium webdriver class and the selenium chromedriver class (you need both) .

Next add the Javadocs:

Properties >> Java Build Path >> libraries >> select the standalone jar   >> expand it >>  find the “Javadoc location option” and enter for javadoc location path

http://seleniumhq.github.io/selenium/docs/api/java/

Now all methods are documented.

Create test script

Next in the scr folder open a new class with package name com.assessmentee.tests and name AssessmenteeTest.

Also create a stub: public static void main. This makes available:

package com.assessmentee.tests;

public class AssessmenteeTest {

  public static void main(String[] args) {
 
  }
}

The most basic test script now looks like:

package com.assessmentee.tests;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class AssessmenteeTest {

  public static void main(String[] args) throws InterruptedException {

   System.setProperty("webdriver.chrome.driver",
              "C:\\Drivers\\chromedriver.exe"); 
    WebDriver driver = new ChromeDriver();
    driver.get("http://assessmentee.com");
    driver.close();
 }
}

Omitting the system property will generate an error: The path to the driver executable must be set by the webdriver.chrome.driver system property

The webdriver chromedriver.exe (2.34) can be found at http://www.seleniumhq.org/download/ in the third party browser drivers section as azip file.

Hitting run (ctrl + F11) will open a chrome browser  and in it the requested domain.

Links

Advertisements