Scene
In a nutshell, we can think of remote Webdriver as running Webdriver scripts on long-range machines.
Imagine the simplest scenario: you and your co-workers develop a webdriver script, and then you need to run the script in a common environment. Why run in a public environment? That's because everyone's development machine is different, but if you use the same test machine, then the factors of environmental differences can be basically excluded. We should often hear development say such words: "This bug in my environment is good ah!" "。 Because of the differences in the operating environment, we need a unified operating environment to eliminate the differences.
In this scenario, we need to use remote webdriver, we develop the script locally, and then call remote Webdriver to perform our tests on the test machine.
Installation
The installation of the Remote Webdriver is simple.
Download Selenium-server-standalone-last-version.jar first.
Then run the java -jar selenium-server-standalone.jar command. If there is no error, the machine has been configured as a remote machine, and later Webdriver will start the browser on this machine, execute the script.
Start driver
The following code can start driver on the remote machine, which, by default, will open localhost, which is the Firefox browser on this computer.
driver = Selenium::WebDriver.for(:remote)
If your remote Webdriver is not running locally and you want to specify a browser other than Firefox, use the following code
driver = Selenium::WebDriver.for(:remote, :url => "http://myserver:4444/wd/hub", :desired_capabilities => :chrome)
Typically, MyServer can be an IP address such as 192.168.x.x.
In addition, the configuration can be configured Selenium::WebDriver::Remote::Capabilities to achieve a more customized browser configuration, this is beyond the scope of this article, do not describe.
Start driver with Watir-webdriver
You can use the following code to let Watir-webdriver also use remote Webdriver mode
browser = Watir::Browser.new(:remote, {desired_capabilities: :chrome, url: "http://myserver:4444/wd/hub"})
Python version
c == webdriver. Remote (command_executor='http://127.0.0.1:4444/wd/hub', Desired_capabilities=c)
Note that the code for starting remote Webdriver used in the python binding wiki is not the same as what I gave above, probably because my selenium version is lower (30), and the newest version of the student can try the code on the wiki.
31.Remote Webdriver