Migrate commands from selenium v1 to selenium v3 in Java

 

Selenium v1 means use java package com.thoughtworks.selenium to call/test csv, run Selenium,

Selenium v3 means use java package org.seleniumhq.selenium, support Remote Selenium WebDriver

Later will explain how to difference for starting.

These 2 different selenium versions also support different browser versions, e.g. Firefox

Tested in selenium v1 on FFv3, and selenium v2 on FFv63

Here will compare this two different selenium typical commands usage:

#Open

Sele1:

     Selenium.open(url);

Sele3:

     Webdriver.get(url);

 

#TYPE

Sele1:

     Selenium.type(element,value);

Sele3:

     WebElement.sendKeys(value);

#CLICK

Sele1:

     Selenium.click(element);

Sele3:

     WebElement.click();

#WAIT

Sele1:

     Selenium.waitForPageToLoad(timeout);

Sele3:

long waitSeconds=...;

try {

      Thread.sleep(waitSeconds);

}catch(InterruptedException e){

      e.printStackTrace();

}

#CLICKAT

Sele1:

     Selenium.clickAt(element,posString);

Sele3:

     WebDriver driver...;

     Actions builder = new Actions(driver);

     builder.moveToElement(element, 0, 0).click().build().perform();

#SELECT

Sele1:

     Selenium.select(element,value);

Sele3:

     WebElement.click();

 

#KEYPRESS

Sele1:

     Selenium.keyPress(element,value);

Sele3:

     WebDriver driver..;.

     Actions action = new Actions(driver);

     action.sendKeys(value);

#ASSERTTEXTPRESENT

Sele2:

     Selenium.isTextPresent(element);

Sele3:

     WebDriver.getPageSource().contains(element);

 

 

Actually, there are still many commands need to migrate,  such as selectAndwait,check,typefilename,AssertElementPresent…

can combine implemented above Sele3 commands, others e.g. WindowFocus,OpenWindow etc, we can use JavascriptExecutor to implement or specially handle for Actions class.

Leave a Reply

Your email address will not be published. Required fields are marked *