20
20
import org .apache .http .auth .AuthScope ;
21
21
import org .apache .http .auth .NTCredentials ;
22
22
import org .apache .http .auth .UsernamePasswordCredentials ;
23
- import org .apache .http .client .config .RequestConfig ;
23
+ import org .apache .http .conn .params .ConnRoutePNames ;
24
+ import org .apache .http .impl .client .DefaultHttpClient ;
25
+ import org .apache .http .impl .conn .DefaultHttpRoutePlanner ;
24
26
import org .json .simple .JSONArray ;
25
27
import org .json .simple .JSONObject ;
26
28
import org .json .simple .JSONValue ;
27
29
import org .openqa .selenium .Dimension ;
28
- import org .openqa .selenium .MutableCapabilities ;
29
30
import org .openqa .selenium .Platform ;
30
31
import org .openqa .selenium .WebDriver ;
31
32
import org .openqa .selenium .WebElement ;
36
37
import org .openqa .selenium .ie .InternetExplorerDriver ;
37
38
import org .openqa .selenium .phantomjs .PhantomJSDriver ;
38
39
import org .openqa .selenium .remote .Augmenter ;
40
+ import org .openqa .selenium .remote .DesiredCapabilities ;
39
41
import org .openqa .selenium .remote .HttpCommandExecutor ;
40
42
import org .openqa .selenium .remote .RemoteWebDriver ;
41
43
import org .openqa .selenium .safari .SafariDriver ;
@@ -210,8 +212,8 @@ public String openBrowser(String url, String browserName, String alias, String r
210
212
}
211
213
212
214
public String openBrowser (String url , String browserName , String alias , String remoteUrl ,
213
- String mutableCapabilities ) throws Throwable {
214
- return openBrowser (url , browserName , alias , remoteUrl , mutableCapabilities , null );
215
+ String desiredCapabilities ) throws Throwable {
216
+ return openBrowser (url , browserName , alias , remoteUrl , desiredCapabilities , null );
215
217
}
216
218
217
219
/**
@@ -285,19 +287,19 @@ public String openBrowser(String url, String browserName, String alias, String r
285
287
* later to switch back to it. Index starts from 1 and is reset back to it
286
288
* when the `Close All Browsers` keyword is used.<br>
287
289
* <br>
288
- * <b>mutableCapabilities </b><br>
289
- * The mutableCapabilities can be specified in a simple key:value format or
290
+ * <b>DesiredCapabilities </b><br>
291
+ * The DesiredCapabilities can be specified in a simple key:value format or
290
292
* as a JSON object. With the JSON format more complex parameters, like the
291
293
* proxy, can be configured.<br>
292
294
* <br>
293
- * Example of mutableCapabilities as simple string:<br>
295
+ * Example of desiredCapabilities as simple string:<br>
294
296
* <table border="1" cellspacing="0" summary="">
295
297
* <tr>
296
298
* <td>platform:Windows 8,browserName:firefox,version:25</td>
297
299
* </tr>
298
300
* </table>
299
301
* <br>
300
- * Example of mutableCapabilities as JSON object:<br>
302
+ * Example of desiredCapabilities as JSON object:<br>
301
303
* <table border="1" cellspacing="0" summary="">
302
304
* <tr>
303
305
* <td>{<br>
@@ -359,15 +361,15 @@ public String openBrowser(String url, String browserName, String alias, String r
359
361
* Default=False. Optional remote grid URL. When specified no
360
362
* local WebDriver instance is created, but a network connection
361
363
* to a Selenium 2 WebDriver Grid Hub at the given URL is opened.
362
- * @param mutableCapabilities
364
+ * @param desiredCapabilities
363
365
* Default=NONE. Optional desired capabilities of the newly
364
366
* created remote browser instances can be specified in a simple
365
367
* key1:val1,key2:val2 format or as a JSON object (see examples
366
368
* above). Used to communicate to the remote grid, which kind of
367
369
* browser, etc. should be used. For more information see:
368
370
* <a href=
369
- * "http://code.google.com/p/selenium/wiki/mutableCapabilities " >
370
- * mutableCapabilities </a>
371
+ * "http://code.google.com/p/selenium/wiki/DesiredCapabilities " >
372
+ * DesiredCapabilities </a>
371
373
* @param browserOptions
372
374
* Default=NONE. Extended browser options as JSON structure.
373
375
* @return The index of the newly created browser instance.
@@ -379,10 +381,10 @@ public String openBrowser(String url, String browserName, String alias, String r
379
381
* @see BrowserManagement#switchBrowser
380
382
*/
381
383
@ RobotKeyword
382
- @ ArgumentNames ({ "url" , "browserName=firefox" , "alias=NONE" , "remoteUrl=False" , "mutableCapabilities =NONE" ,
384
+ @ ArgumentNames ({ "url" , "browserName=firefox" , "alias=NONE" , "remoteUrl=False" , "desiredCapabilities =NONE" ,
383
385
"browserOptions=NONE" })
384
386
public String openBrowser (String url , String browserName , String alias , String remoteUrl ,
385
- String mutableCapabilities , String browserOptions ) throws Throwable {
387
+ String desiredCapabilities , String browserOptions ) throws Throwable {
386
388
try {
387
389
logging .info ("browserName: " + browserName );
388
390
if (remoteUrl != null ) {
@@ -392,7 +394,7 @@ public String openBrowser(String url, String browserName, String alias, String r
392
394
logging .info (String .format ("Opening browser '%s' to base url '%s'" , browserName , url ));
393
395
}
394
396
395
- WebDriver webDriver = createWebDriver (browserName , mutableCapabilities , remoteUrl , browserOptions );
397
+ WebDriver webDriver = createWebDriver (browserName , desiredCapabilities , remoteUrl , browserOptions );
396
398
webDriver .get (url );
397
399
String sessionId = webDriverCache .register (webDriver , alias );
398
400
logging .debug (String .format ("Opened browser with session id %s" , sessionId ));
@@ -802,8 +804,8 @@ public String getTitle() {
802
804
* is requested in the desired capabilities, no error is thrown;</b> a
803
805
* read-only capabilities object is returned that indicates the capabilities
804
806
* the session actually supports. For more information see:
805
- * <a href= "http://code.google.com/p/selenium/wiki/mutableCapabilities " >
806
- * mutableCapabilities </a><br>
807
+ * <a href= "http://code.google.com/p/selenium/wiki/DesiredCapabilities " >
808
+ * DesiredCapabilities </a><br>
807
809
*
808
810
* @return The capabilities of the remote node.
809
811
*
@@ -1357,17 +1359,17 @@ protected String getPasswordFromURL(URL url) {
1357
1359
return auth .substring (index + 1 );
1358
1360
}
1359
1361
1360
- protected WebDriver createWebDriver (String browserName , String mutableCapabilitiesString , String remoteUrlString ,
1362
+ protected WebDriver createWebDriver (String browserName , String desiredCapabilitiesString , String remoteUrlString ,
1361
1363
String browserOptions ) throws MalformedURLException {
1362
1364
browserName = browserName .toLowerCase ().replace (" " , "" );
1363
- MutableCapabilities mutableCapabilities = createmutableCapabilities (browserName , mutableCapabilitiesString ,
1365
+ DesiredCapabilities desiredCapabilities = createDesiredCapabilities (browserName , desiredCapabilitiesString ,
1364
1366
browserOptions );
1365
1367
1366
1368
WebDriver webDriver ;
1367
1369
if (remoteUrlString != null && !"False" .equals (remoteUrlString )) {
1368
- webDriver = createRemoteWebDriver (mutableCapabilities , new URL (remoteUrlString ));
1370
+ webDriver = createRemoteWebDriver (desiredCapabilities , new URL (remoteUrlString ));
1369
1371
} else {
1370
- webDriver = createLocalWebDriver (browserName , mutableCapabilities );
1372
+ webDriver = createLocalWebDriver (browserName , desiredCapabilities );
1371
1373
}
1372
1374
1373
1375
webDriver .manage ().timeouts ().setScriptTimeout ((int ) (timeout * 1000.0 ), TimeUnit .MILLISECONDS );
@@ -1376,35 +1378,35 @@ protected WebDriver createWebDriver(String browserName, String mutableCapabiliti
1376
1378
return webDriver ;
1377
1379
}
1378
1380
1379
- protected WebDriver createLocalWebDriver (String browserName , MutableCapabilities mutableCapabilities ) {
1381
+ protected WebDriver createLocalWebDriver (String browserName , DesiredCapabilities desiredCapabilities ) {
1380
1382
System .out .println (browserName );
1381
1383
if ("ff" .equals (browserName ) || "firefox" .equals (browserName )) {
1382
- return new FirefoxDriver (mutableCapabilities );
1384
+ return new FirefoxDriver (desiredCapabilities );
1383
1385
} else if ("ie" .equals (browserName ) || "internetexplorer" .equals (browserName )) {
1384
- return new InternetExplorerDriver (mutableCapabilities );
1386
+ return new InternetExplorerDriver (desiredCapabilities );
1385
1387
} else if ("gc" .equals (browserName ) || "chrome" .equals (browserName ) || "googlechrome" .equals (browserName )) {
1386
- return new ChromeDriver (mutableCapabilities );
1388
+ return new ChromeDriver (desiredCapabilities );
1387
1389
} else if ("opera" .equals (browserName )) {
1388
- return new OperaDriver (mutableCapabilities );
1390
+ return new OperaDriver (desiredCapabilities );
1389
1391
} else if ("phantomjs" .equals (browserName )) {
1390
- return new PhantomJSDriver (mutableCapabilities );
1392
+ return new PhantomJSDriver (desiredCapabilities );
1391
1393
} else if ("safari" .equals (browserName )) {
1392
- return new SafariDriver (mutableCapabilities );
1394
+ return new SafariDriver (desiredCapabilities );
1393
1395
} else if ("htmlunit" .equals (browserName )) {
1394
- return new HtmlUnitDriver (mutableCapabilities );
1396
+ return new HtmlUnitDriver (desiredCapabilities );
1395
1397
} else if ("htmlunitwithjs" .equals (browserName )) {
1396
- HtmlUnitDriver driver = new HtmlUnitDriver (mutableCapabilities );
1398
+ HtmlUnitDriver driver = new HtmlUnitDriver (desiredCapabilities );
1397
1399
driver .setJavascriptEnabled (true );
1398
1400
return driver ;
1399
1401
} else if ("iphone" .equals (browserName ) || "ipad" .equals (browserName )) {
1400
1402
try {
1401
- return new IOSDriver <WebElement >(new URL ("" ), mutableCapabilities );
1403
+ return new IOSDriver <WebElement >(new URL ("" ), desiredCapabilities );
1402
1404
} catch (Exception e ) {
1403
1405
throw new SeleniumLibraryFatalException ("Creating " + browserName + " instance failed." , e );
1404
1406
}
1405
1407
} else if ("android" .equals (browserName )) {
1406
1408
try {
1407
- return new SelendroidDriver (mutableCapabilities );
1409
+ return new SelendroidDriver (desiredCapabilities );
1408
1410
} catch (Exception e ) {
1409
1411
throw new SeleniumLibraryFatalException (e );
1410
1412
}
@@ -1415,67 +1417,67 @@ protected WebDriver createLocalWebDriver(String browserName, MutableCapabilities
1415
1417
throw new SeleniumLibraryFatalException (browserName + " is not a supported browser." );
1416
1418
}
1417
1419
1418
- protected WebDriver createRemoteWebDriver (MutableCapabilities mutableCapabilities , URL remoteUrl ) {
1420
+ protected WebDriver createRemoteWebDriver (DesiredCapabilities desiredCapabilities , URL remoteUrl ) {
1419
1421
HttpCommandExecutor httpCommandExecutor = new HttpCommandExecutor (remoteUrl );
1420
1422
setRemoteWebDriverProxy (httpCommandExecutor );
1421
- return new Augmenter ().augment (new RemoteWebDriver (httpCommandExecutor , mutableCapabilities ));
1423
+ return new Augmenter ().augment (new RemoteWebDriver (httpCommandExecutor , desiredCapabilities ));
1422
1424
}
1423
1425
1424
- protected MutableCapabilities createmutableCapabilities (String browserName , String mutableCapabilitiesString ,
1426
+ protected DesiredCapabilities createDesiredCapabilities (String browserName , String desiredCapabilitiesString ,
1425
1427
String browserOptions ) {
1426
- mutableCapabilities mutableCapabilities ;
1428
+ DesiredCapabilities desiredCapabilities ;
1427
1429
if ("ff" .equals (browserName ) || "firefox" .equals (browserName )) {
1428
- mutableCapabilities = mutableCapabilities .firefox ();
1429
- parseBrowserOptionsFirefox (browserOptions , mutableCapabilities );
1430
+ desiredCapabilities = DesiredCapabilities .firefox ();
1431
+ parseBrowserOptionsFirefox (browserOptions , desiredCapabilities );
1430
1432
} else if ("ie" .equals (browserName ) || "internetexplorer" .equals (browserName )) {
1431
- mutableCapabilities = mutableCapabilities .internetExplorer ();
1433
+ desiredCapabilities = DesiredCapabilities .internetExplorer ();
1432
1434
} else if ("gc" .equals (browserName ) || "chrome" .equals (browserName ) || "googlechrome" .equals (browserName )) {
1433
- mutableCapabilities = mutableCapabilities .chrome ();
1435
+ desiredCapabilities = DesiredCapabilities .chrome ();
1434
1436
} else if ("opera" .equals (browserName )) {
1435
- mutableCapabilities = mutableCapabilities .opera ();
1437
+ desiredCapabilities = DesiredCapabilities .opera ();
1436
1438
} else if ("phantomjs" .equals (browserName )) {
1437
- mutableCapabilities = mutableCapabilities .phantomjs ();
1439
+ desiredCapabilities = DesiredCapabilities .phantomjs ();
1438
1440
} else if ("safari" .equals (browserName )) {
1439
- mutableCapabilities = mutableCapabilities .safari ();
1441
+ desiredCapabilities = DesiredCapabilities .safari ();
1440
1442
} else if ("ipad" .equals (browserName )) {
1441
- mutableCapabilities = mutableCapabilities .ipad ();
1443
+ desiredCapabilities = DesiredCapabilities .ipad ();
1442
1444
} else if ("iphone" .equals (browserName )) {
1443
- mutableCapabilities = mutableCapabilities .iphone ();
1445
+ desiredCapabilities = DesiredCapabilities .iphone ();
1444
1446
} else if ("android" .equals (browserName )) {
1445
- mutableCapabilities = mutableCapabilities .android ();
1447
+ desiredCapabilities = DesiredCapabilities .android ();
1446
1448
} else if ("htmlunit" .equals (browserName ) || "htmlunitwithjs" .equals (browserName )) {
1447
- mutableCapabilities = mutableCapabilities .htmlUnit ();
1449
+ desiredCapabilities = DesiredCapabilities .htmlUnit ();
1448
1450
} else if ("jbrowser" .equals (browserName )) {
1449
- mutableCapabilities = new mutableCapabilities ("jbrowser" , "1" , Platform .ANY );
1451
+ desiredCapabilities = new DesiredCapabilities ("jbrowser" , "1" , Platform .ANY );
1450
1452
} else {
1451
1453
throw new SeleniumLibraryFatalException (browserName + " is not a supported browser." );
1452
1454
}
1453
1455
1454
- if (mutableCapabilitiesString != null && !"None" .equals (mutableCapabilitiesString )) {
1455
- JSONObject jsonObject = (JSONObject ) JSONValue .parse (mutableCapabilitiesString );
1456
+ if (desiredCapabilitiesString != null && !"None" .equals (desiredCapabilitiesString )) {
1457
+ JSONObject jsonObject = (JSONObject ) JSONValue .parse (desiredCapabilitiesString );
1456
1458
if (jsonObject != null ) {
1457
1459
// Valid JSON
1458
1460
Iterator <?> iterator = jsonObject .entrySet ().iterator ();
1459
1461
while (iterator .hasNext ()) {
1460
1462
Entry <?, ?> entry = (Entry <?, ?>) iterator .next ();
1461
- mutableCapabilities .setCapability (entry .getKey ().toString (), entry .getValue ());
1463
+ desiredCapabilities .setCapability (entry .getKey ().toString (), entry .getValue ());
1462
1464
}
1463
1465
} else {
1464
1466
// Invalid JSON. Old style key-value pairs
1465
- for (String capability : mutableCapabilitiesString .split ("," )) {
1467
+ for (String capability : desiredCapabilitiesString .split ("," )) {
1466
1468
String [] keyValue = capability .split (":" );
1467
1469
if (keyValue .length == 2 ) {
1468
- mutableCapabilities .setCapability (keyValue [0 ], keyValue [1 ]);
1470
+ desiredCapabilities .setCapability (keyValue [0 ], keyValue [1 ]);
1469
1471
} else {
1470
- logging .warn ("Invalid mutableCapabilities : " + mutableCapabilitiesString );
1472
+ logging .warn ("Invalid desiredCapabilities : " + desiredCapabilitiesString );
1471
1473
}
1472
1474
}
1473
1475
}
1474
1476
}
1475
- return mutableCapabilities ;
1477
+ return desiredCapabilities ;
1476
1478
}
1477
1479
1478
- protected void parseBrowserOptionsFirefox (String browserOptions , MutableCapabilities mutableCapabilities ) {
1480
+ protected void parseBrowserOptionsFirefox (String browserOptions , DesiredCapabilities desiredCapabilities ) {
1479
1481
if (browserOptions != null && !"NONE" .equals (browserOptions )) {
1480
1482
JSONObject jsonObject = (JSONObject ) JSONValue .parse (browserOptions );
1481
1483
if (jsonObject != null ) {
@@ -1514,7 +1516,7 @@ protected void parseBrowserOptionsFirefox(String browserOptions, MutableCapabili
1514
1516
logging .warn ("Unknown browserOption: " + key + ":" + entry .getValue ());
1515
1517
}
1516
1518
}
1517
- mutableCapabilities .setCapability (FirefoxDriver .PROFILE , firefoxProfile );
1519
+ desiredCapabilities .setCapability (FirefoxDriver .PROFILE , firefoxProfile );
1518
1520
} else {
1519
1521
logging .warn ("Invalid browserOptions: " + browserOptions );
1520
1522
}
@@ -1552,7 +1554,7 @@ protected void setRemoteWebDriverProxy(HttpCommandExecutor httpCommandExecutor)
1552
1554
// proxies correctly.
1553
1555
client .setRoutePlanner (new DefaultHttpRoutePlanner (client .getConnectionManager ().getSchemeRegistry ()));
1554
1556
HttpHost proxy = new HttpHost (remoteWebDriverProxyHost , Integer .parseInt (remoteWebDriverProxyPort ));
1555
- client .getParams ().setParameter (RequestConfig .DEFAULT_PROXY , proxy );
1557
+ client .getParams ().setParameter (ConnRoutePNames .DEFAULT_PROXY , proxy );
1556
1558
} catch (SecurityException e ) {
1557
1559
throw new SeleniumLibraryFatalException (
1558
1560
String .format ("The SecurityManager does not allow us to lookup to the %s field." , fieldName ));
0 commit comments