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