I have a question about selenium2 (webdriver).
As selenium-2 supports following 4 types of web drivers..
1-IE
2-firefox
3-chrome
4-htmlunit
Is there any way to use any other webdriver apart from these; like Safari, Opera etc?
In C# (I think in Java too at least), there is the RemoteWebDriver which is meant to control a WebDriver on a remote machine (although it can be done locally).
RemoteWebDriver can be given a DesiredCapability that has more options. So for example:
RemoteWebDriver operaDriver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Opera());
Related
this question popped up in my mind that why we do not write RemoteWebdriver driver = new ChromeDriver(); what is the harm what are the advantages why we do not write it like this while creating our driver instance.
We do write like:
Webdriver driver = new ChromeDriver();
ChromeDriver driver = new ChromeDriver();
but not like this:
RemoteWebdriver driver = new ChromeDriver():
I am new to this so any help will be appreciated.
Thanks
When initializing ChromeDriver and assigning it to a variable whose type is ChromeDriver, you are able to use all of the concrete methods available to that type. This is useful if you need to configure the Chrome browser window:
ChromeDriver driver = new ChromeDriver();
// Configure Google Chrome
WebDriver is an interface. ChromeDriver is a concrete class which implements the WebDriver interface. When initializing a WebDriver variable to a new instance of ChromeDriver you are simply providing concrete implementation for the WebDriver abstraction. This is done when you want to test in Chrome, but you do not need Chrome specific configurations, and the methods provided by the WebDriver interface suffice for your tests.
WebDriver driver = new ChromeDriver();
// Use the WebDriver abstraction without needing to know it is Chrome
The RemoteWebDriver class is the abstract class from which ChromeDriver is derived. It has some concrete implementation related to making web service calls to a "web driver" process running on the same computer. It also contains abstractions that concrete classes like ChromeDriver must implement.
The reason you do not often see a new ChromeDriver being assigned to a RemoteWebDriver variable is because from the perspective of a test, there is no functional difference between a WebDriver object and a RemoteWebDriver object. The level of abstraction provided by RemoteWebDriver is simply not very useful.
RemoteWebDriver driver = new ChromeDriver();
// test code tends to only call methods defined in the WebDriver interface,
// so why bother with a concrete class?
Why is the code //RemoteWebDriver driver= new FirefoxDriver(); not used instead of //WebDriver driver= new FirefoxDriver() to create a driver object?
I feel that RemoteWebDriver gives more capabilities for the driver instance than webdriver reference. Can someone clarify this?
WebDriver will start up a web browser on the computer where the code instantiates it. For example. If you write a bit of code, and then run it to see how you are doing, the browser will pop up on your screen and you will see WebDriver begin to manipulate that web browser window (if everything went well!)
With a major exception which I will explain below, RemoteWebDriver will do the same thing; it will open and manipulate a browser window (if everything went well!) Generally speaking, You can actually switch the instatiation of a WebDriver with a RemoteWebDriver (well, there are advanced cases where you might not be able too do this) The major difference is that RemoteWebDriver sends that request to open and control a web browser to a server, so you normally wouldn’t see the browser open and do it’s thing.
Selenium server is the program that runs and waits for RemoteWebDriver connections. You can run it on your local computer to test it out. If you get it set up and running, you’ll be able to create a RemoteWebDriver and see that the Selenium server accepts the connection and allows you to control the web browser window.
The gains from using RemoteWebDriver?
If you can do connect to a local Selenium server, you can be confident that you have the knowledge and skills needed to connect to a remote Selenium server, or even to a paid service like SauceLabs (Hosting Selenium for you) that allows you to run lots of tests on lots of OS’s and lots of browsers without having to actually maintain or install any of them (Linux, Windows 8, Windows 10, MacOS, Andriod, IOS, IE, Firefox, Opera, Safari, Firefox Mobile, etc) You’ll want to look into running tests asynchronously at this point. You don’t have to run them one at a time, so can test a large number of OS/Browser variations in a very short time.
What does it mean when something is used only for client/server communication?
When you uses a Selenium grid with have one hub and multiple clients, you invoke RemoteWebDriver through which you instantiate the server and and make the request to it.
WebDriver is an interface in selenium which extends SearchContext interface (super most interface in selenium)
Where as RemoteWebdriver is a class which implements WebDriver,
We can use RemoteWebdriver, when we going to execute the test in romote environment,(selenium grid).
WebDriver interface will invoke the driver locally,
Currently in automation mostly we are using WebDriver only.
Grid not using widely.
WebDriver driver=new ChromeDriver() ;
driver is the reference variable where used to access chromedriver class.
Using driver instance we can access all the unimplemented methods available in WebDriver interface, also able to access all the properties available in chromedriver class.
For more details
https://www.softwaretestingmaterial.com/webdriver-driver-new-firefoxdriver/
For Chrome,
public class Chrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
}
}
for Firefox,
public class Firefox {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
Why do we need to specify the system.setProperty for Chrome and IE?
I had also same question, but after digging I found,
WebDriver uses native browser approach. Selenium offers inbuilt
driver for Firefox but not for other browsers. All drivers (Chrome
Driver, IE driver, etc.) are built based on the special JS Engine used
by each browser.
Selenium WebDriver works very well with Mozilla Firefox because it has a built in driver server. But the same is not true for Internet Explorer and Google Chrome. Firefox is the most traditional browser, thus Selenium WebDriver do not require any additional utility to be set before launching the browser. The Selenium package automatically references towards the default location of the firefox.exe, thus the user need not to set any other property.
If you ever get the “the path to the driver executable must be set by the webdriver. ie. driver system property” error or its similarly worded Chrome equivalent, it means that you need to install the driver servers on your browser. The driver server manages the calls between the browsers and the Selenium wire protocol.
The InternetExplorerDriver is a standalone server which implements WebDriver’s wire protocol
Similarly, Google Chrome doesn’t have a built-in server so you will need a Chrome driver server for communicating your Selenium code to the browser. You can download the Chrome driver server.
Founded from here.
Implementation of FirefoxDriver, ChromeDriver, InternetExplorerDriver is different, thus the way of instantiating the object differs as well.
The Firefox Driver controls the Firefox browser using a Firefox plugin. The Firefox Profile that is used is stripped down from what is installed on the machine to only include the Selenium WebDriver.xpi
The InternetExplorerDriver is a standalone server which implements WebDriver’s wire protocol.
The ChromeDriver is maintained / supported by the Chromium project iteslf. WebDriver works with Chrome through the chromedriver binary (found on the chromium project’s download page). You need to have both chromedriver and a version of chrome browser installed. chromedriver needs to be placed somewhere on your system’s path in order for WebDriver to automatically discover it. The Chrome browser itself is discovered by chromedriver in the default installation path
For more details, refer the selenium documentation
Simple answer is, each browser has its own WebDriver implementation and is not maintained by the Selenium project. Hence for selenium to interact with the browser specific driver we need to specify the full path of the driver.
Why for firefox there is no need to specify the driverpath? In Selenium 2.0, selenium RC is still present and was supporting firefox. From Selenium 3.0 onwards there is no official support for any browser specific drivers. Hence, we need to specify the driver path through System.setproperty for all the browsers.
I want to open Chrome on the client side using selenium webdriver. I have a piece of code and it works fine for single system, but I can't access it in another system.
I am using selenium-server-standalone-2.44.0.jar, chromedriver for the purpose.
This is the code I use to open browser:
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver=new ChromeDriver();
Is the ChromeDriver on the other system in the same place as on the single system?
Try something like the following (in java):
String currentDir = System.getProperty("user.dir");
String chromeDriverLocation = currentDir + "/../tools/chromedriver/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", chromeDriverLocation);
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("disable-plugins");
options.addArguments("disable-extensions");
WebDriver chrome = new ChromeDriver(options);
chrome.get("http://www.google.com");
Selenium webdriver can be used in different languages.
I can give you an example.
A web application is developed by using python in back-end and front-end is built up with html and a interpreted programming language like javascript. If we use selenium webdriver with python then browser opens at server side. and if we use selenium with javascript then browser opens at client side.
I'm not sure I quite understand the difference. WebDriver API also directly controls the browser of choice. When should you use selenium remote control (selenium RC) instead ?
Right now, my current situation is I am testing a web application by writing a suite with Selenium WebDriver API and letting it run on my computer. The tests are taking longer and longer to complete, so I have been searching for ways to run the tests on a Linux server.
If I use Selenium Remote Control, does this mean I have to rewrite everything I wrote with WebDriver API?
I am getting confused with Selenium Grid, Hudson, Selenium RC. I found a Selenium Grid plugin for Hudson, but not sure if this includes Selenium RC.
Am I taking the correct route? I envision the following architecture:
Hudson running on few Ubuntu dedicated servers.
Hudson running with Xvnc & Selenium Grid plugin. (Do I need to install Firefox separately ?)
Selenium grid running selenium RC test suites.
I think this is far more time efficient than running test on my current working desktop computer with WebDriver API.
WebDriver is now Selenium 2. The Selenium and WebDriver code bases are being merged. WebDriver gets over a number of issues that Selenium has and Selenium gets over a number of issues that Webdriver has.
If you have written your tests in Selenium one you don't have to rewrite them to work with Selenium 2. We, the core developers, have written it so that you create a browser instance and inject that into Selenium and your Selenium 1 tests will work in Selenium 2. I have put an example below for you.
// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();
// A "base url", used by selenium to resolve relative URLs
String baseUrl = "http://www.google.com";
// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");
Selenium 2 unfortunately has not been put into Selenium 2 but it shouldn't be too long until it has been added since we are hoping to reach beta in the next couple of months.
As far as I understand, Webdriver implementation started little later than Selenium RC. From my point of view, WebDriver is more flexible solution, which fixed some annoying problems of SeleniumRC.
WebDriver provides standard interface for testing web GUI. There are several implementations of this interface (HTTP, browser-specific and based on Selenium). Since you already have some WebDriver tests, you must be familiar with basic docs like this
The tests are getting longer and longer to complete, so I have been searching for ways to run the tests on a linux server.
Did you try to find actual bottlenecks? I'm not sure, that elimination of WebDriver layer will help. I think, most time is spent on Selenium commands sending and HTTP requests to system-under-test.
If I use sleneium remote control, does
this mean I have to rewrite everything
I wrote with WebDriver API ?
Generally, yes. If you did not implement some additional layer between tests code and WebDriver.
As for Selenium Grid:
You may start several Selenium RC instances on several different [virtual] nodes, then register them in Selenium Grid. Your tests connect to Selenium Grid, and it redirects all commands to SeleniumRC instances, coordinating them in accordance with required browsers.
For details of hudson plugin you may find more info here