Hurry! 20% Off Ends SoonRegister Now

How to use WebDriver Backed Selenium

 

WebDriver Backed Selenium

The Java version of Webdriver provides an implementation of the Selenium-RC API. This means that you can use the underlying WebDriver technology using the Selenium-RC API. This is primarily provided for backward compatibility. It allows those who have existing test suites using the Selenium-RC API to use WebDriver under the covers. It’s provided to help ease the migration path to Selenium-Web driver.
Sample Backed web driver script looks like this:

package webone;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.selenium.SeleneseTestCase;

import com.thoughtworks.selenium.Selenium;
@SuppressWarnings("deprecation")
public class BackedSelenium extends SeleneseTestCase {
//web driver ??here we are declaring the browser
WebDriver driver = new FirefoxDriver();
@Before
public void setUp() throws Exception {
String baseUrl = "https://www.google.co.in/";
selenium = new WebDriverBackedSelenium(driver, baseUrl);
}

@TEST
public void testBackedSelenium() throws Exception {
//This is using selenium
selenium.open("/");
selenium.click("id=gbi5");
selenium.click("id=gmlas");
selenium.waitForPageToLoad("30000");
selenium.type("name=as_q", "test");
//Here we are using Webdriver
driver.findElement(By.id("as_oq1")).sendKeys("naga");

driver.findElement(By.id("as_oq2")).sendKeys("Webdriver");
Thread.sleep(5000);
}

@After
public void tearDown() throws Exception {
selenium.stop();
}
}

By using the above format, you can use both the Selenium API and Web driver API…

MindMajix YouTube Channel

Run WebDriver Scripts in Chrome

We run the Selenium Webdriver programs in the Google Chrome web browser to perform automation testing.
Below theory explains to you how to run your web driver script in google chrome..
Firefox Browser:
driver=new FirefoxDriver();---it will work and will launch your Firefox browser,
Google Chrome:
driver= new Chromedriver() --- it will throw an error.
Error:
FAILED CONFIGURATION: @BeforeClass before class
java.lang.IllegalStateException:
The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information.
To overcome this, we need to download the chrome driver.exe and we have to specify the path of a chrome driver in the script
Download path:

https://code.google.com/p/chromedriver/downloads/list take the latest exe file.

 

Selenium Interview Questions

Save the chrome driver in a folder and you need to specify the path of a driver in your web driver script.
Below is the sample code:

package testng;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class ChromedriverTest {
111
public WebDriver driver;

@BeforeClass
public void beforeClass() {
// Create chrome driver instance...
System.setProperty("webdriver.chrome.driver", "C:xxxJarchromedriver.exe");

driver=new ChromeDriver();
}

@TEST
public void testChromedriverTest() throws Exception {
driver.navigate().to("https://bing.com");
Thread.sleep(5000);
}

@AfterClass
public void afterClass() {
driver.quit();

}
}

Use the above code for your script which will run in Google chrome.

Explore Selenium Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

 

 

Job Support Program

Online Work Support for your on-job roles.

jobservice

Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
Selenium Training Dec 24 to Jan 08View Details
Selenium Training Dec 28 to Jan 12View Details
Selenium Training Dec 31 to Jan 15View Details
Selenium Training Jan 04 to Jan 19View Details
Last updated: 04 Apr 2023
About Author

 

Madhuri is a Senior Content Creator at MindMajix. She has written about a range of different topics on various technologies, which include, Splunk, Tensorflow, Selenium, and CEH. She spends most of her time researching on technology, and startups. Connect with her via LinkedIn and Twitter .

read less
  1. Share:
Selenium Articles