forked from SeleniumHQ/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote.html
More file actions
180 lines (126 loc) · 6.35 KB
/
remote.html
File metadata and controls
180 lines (126 loc) · 6.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!doctype html>
<meta charset=utf-8>
<title>Remote WebDriver</title>
<link rel=stylesheet href=se.css>
<link rel=prev href=wd.html title=WebDriver>
<link rel=next href=best.html title="Best Practices">
<script src=docs.js></script>
<h1>Remote WebDriver</h1>
You can use Remote webdriver the same way you would use webdriver
locally. The primary difference is that remote webdriver needs to be
configured so that it can run your tests on a seperate machine.
The RemoteWebDriver is composed of two pieces: a client and a
server. The client is your WebDriver test and the server is simply a
Java servlet, which can be hosted in any modern JEE app server.
<h2>The RemoteWebDriver Server</h2>
The server will always run on the machine with the browser you want to
test. There are two ways to user the server: command line or
configured in code.
<h3>Starting the Server from The Command Line</h3>
Once you have downloaded selenium-server-standalone-{VERSION}.jar
place it on the computer with the browser you want to test. Then from
the directory with the jar run the following
<pre><code>java -jar selenium-server-standalone-{VERSION}.jar</code></pre>
<h3>Considerations when running server</h3>
The caller is expected to terminate each session properly, calling
either Selenium#stop() or WebDriver#quit.
The selenium-server keeps in-memory logs for each ongoing session,
which are cleared when Selenium#stop() or WebDriver#quit is called. If
you forget to terminate these sessions your server may leak memory. If
you keep extremely long-running sessions you will probably need to
stop/quit every now and then (or increase memory with -Xmx jvm option)
<h3>Timeouts (from version 2.21)</h3>
The server has two different timeouts, which can be set as follows:
<pre>j<code>ava -jar selenium-server-standalone-{VERSION}.jar -timeout=20 -browserTimeout=60</code></pre>
<dl>
<dt>browserTimeout</dt>
<dd>Controls how long the browser is allowed to hang (value in seconds)
<dt>timeout</dt>
<dd>Controls how long the client is is allowed to be gone
before the session is reclaimed (value in seconds)
</dl>
<p>The system property <var>selenium.server.session.timeout</var>
is no longer supported as of 2.21.
<p>Please note that the <var>browserTimeout</var>
is intended as a backup timeout mechanism
when the ordinary timeout mechanism fails,
which should be used mostly in grid/server environments
to ensure that crashed/lost processes do not stay around for too long,
polluting the runtime environment.
<h3>Configuring the Server in Code</h3>
<p>In theory, the process is as simple as mapping the "DriverServlet" to
a URL, but it's also possible to host the page in a lightweight
container, such as Jetty configured entirely in code. Steps to do this
follow.
<p>Download the "selenium-server.zip" and unpack. Put the JARs on the
CLASSPATH Create a new class called "AppServer". Here, I'm using
Jetty, so you'll need to download that as well:
<pre><code class=java>import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;
import javax.servlet.Servlet;
import java.io.File;
import org.openqa.selenium.remote.server.DriverServlet;
public class AppServer {
private Server server = new Server();
public AppServer() throws Exception {
WebAppContext context = new WebAppContext();
context.setContextPath("");
context.setWar(new File("."));
server.addHandler(context);
context.addServlet(DriverServlet.class, "/wd/*");
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(3001);
server.addConnector(connector);
server.start();
}
}</code></pre>
<h2 class=running_remotewebdriver_client>Running RemoteWebDriver Client</h2>
<p>First we need to connect to remote webdriver.
We do this by pointing the URL to the address of the server running our tests.
In order to customize our configuration, we set desired capabilities.
Below is an example of instantiating a remote WebDriver object
pointing to our remote web server, <em>www.example.com</em>,
running our tests on Firefox.
<pre><code class=rb>require 'selenium-webdriver'
driver = Selenium::WebDriver.for :remote, :url => "http://www.example.com", :desired_capabilities => :firefox
driver.get "http://www.google.com"
driver.close</code></pre>
<p>To further customize our test configuration
we can add additional desired capabilities.
<h3>Desired Capabilities</h3>
<p>Desired capabilities can be expanded further.
All RemoteWebdriver capabilities are sent through JsonWireProtocol.
For a list of configurable capabilities, and more information on JsonWireProtocol,
please visit the documentation here:
https://code.google.com/p/selenium/wiki/DesiredCapabilities
<p>For example, suppose you wanted to run chrome on Windows XP,
using Chrome version 27:
<pre><code class=rb>caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps.platform = Windows XP
caps.version = 27
driver = Selenium::WebDriver.for :remote, :url => "http://www.example.com", :desired_capabilities => caps</code></pre>
<h3>Local File Detector</h3>
<p>The Local File Detector allows the transfer of files from the client
machine to the remote server. For example if a test needs to upload a
file to a web application, RemoteWebDriver can automatically transfer
the file from the local machine to the remote web server during
runtime. This allows the file to be uploaded from the remote machine
running the test. It is not enabled by default and can be enabled in
the following way:
<pre><code class=java>driver.setFileDetector(new LocalFileDetector());</code></pre>
<pre><code class=rb>@driver.file_detector = lambda do |args|
# args => ["/path/to/file"]
str = args.first.to_s
str if File.exist?(str)
end</code></pre>
<p>Once the above code is defined,
you can upload a file in your test in the following way:
<pre><code class=java>driver.get("http://sso.dev.saucelabs.com/test/guinea-file-upload");
WebElement upload = driver.findElement(By.id("myfile"));
upload.sendKeys("/Users/sso/the/local/path/to/darkbulb.jpg");</code></pre>
<pre><code class=rb>@driver.navigate.to "http://sso.dev.saucelabs.com/test/guinea-file-upload"
element = @driver.find_element(:id, 'myfile')
element.send_keys "/Users/sso/SauceLabs/sauce/hostess/maitred/maitred/public/images/darkbulb.jpg"</code></pre>