Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit e0a5439

Browse files
committed
Test working with Selenium 4 alpha
Fixed deprecations in the remove calls
1 parent ae47741 commit e0a5439

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

pom.xml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.hi-fi</groupId>
77
<artifactId>robotframework-seleniumlibrary</artifactId>
8-
<version>3.141.59.265358-SNAPSHOT</version>
8+
<version>4.0.0-alpha-1.0-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>Robot Framework :: SeleniumLibrary</name>
@@ -70,8 +70,8 @@
7070
<aspectj.version>1.9.1</aspectj.version>
7171
<java.version>1.8</java.version>
7272
<robotframework.maven.plugin.version>1.5.1</robotframework.maven.plugin.version>
73-
<robotframework.version>3.1.1</robotframework.version>
74-
<selenium.version>3.141.59</selenium.version>
73+
<robotframework.version>3.1.2</robotframework.version>
74+
<selenium.version>4.0.0-alpha-1</selenium.version>
7575
<keywords.class>SeleniumLibrary</keywords.class>
7676
<browser>jbrowser</browser>
7777
<downloadWebDriver>False</downloadWebDriver>
@@ -118,6 +118,16 @@
118118
<groupId>io.appium</groupId>
119119
<artifactId>java-client</artifactId>
120120
<version>7.0.0</version>
121+
<exclusions>
122+
<exclusion>
123+
<groupId>org.seleniumhq.selenium</groupId>
124+
<artifactId>selenium-support</artifactId>
125+
</exclusion>
126+
<exclusion>
127+
<groupId>org.seleniumhq.selenium</groupId>
128+
<artifactId>selenium-api</artifactId>
129+
</exclusion>
130+
</exclusions>
121131
</dependency>
122132
<dependency>
123133
<groupId>org.apache.commons</groupId>
@@ -127,7 +137,7 @@
127137
<dependency>
128138
<groupId>com.machinepublishers</groupId>
129139
<artifactId>jbrowserdriver</artifactId>
130-
<version>1.0.1</version>
140+
<version>1.1.0-RC1</version>
131141
</dependency>
132142
<dependency>
133143
<groupId>org.seleniumhq.selenium</groupId>

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagement.java

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import org.apache.http.auth.AuthScope;
2121
import org.apache.http.auth.NTCredentials;
2222
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.CredentialsProvider;
24+
import org.apache.http.impl.client.BasicCredentialsProvider;
25+
import org.apache.http.impl.client.HttpClientBuilder;
26+
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
2627
import org.json.simple.JSONArray;
2728
import org.json.simple.JSONObject;
2829
import org.json.simple.JSONValue;
@@ -41,8 +42,6 @@
4142
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
4243
import org.openqa.selenium.ie.InternetExplorerDriver;
4344
import org.openqa.selenium.ie.InternetExplorerOptions;
44-
import org.openqa.selenium.opera.OperaDriver;
45-
import org.openqa.selenium.opera.OperaOptions;
4645
import org.openqa.selenium.remote.Augmenter;
4746
import org.openqa.selenium.remote.DesiredCapabilities;
4847
import org.openqa.selenium.remote.HttpCommandExecutor;
@@ -65,7 +64,6 @@
6564
import com.machinepublishers.jbrowserdriver.JBrowserDriver;
6665
import com.machinepublishers.jbrowserdriver.Settings;
6766

68-
@SuppressWarnings("deprecation")
6967
@RobotKeywords
7068
public class BrowserManagement extends RunOnFailureKeywordsAdapter {
7169

@@ -162,32 +160,27 @@ public void closeBrowser() {
162160
"| Firefox | firefox, ff |\r\n" +
163161
"| Firefox (headless) | firefoxheadless, ffheadless |\r\n" +
164162
"| Google Chrome | googlechrome, chrome, gc |\r\n" +
165-
"| Google Chrome (headless) | googlechromeheadless, chromeheadless, gcheadless |\r\n" +
166-
"| Internet Explorer | internetexplorer, ie |\r\n" +
167-
"| Edge | edge |\r\n" +
168-
"| Safari | safari |\r\n" +
169-
"| Opera | opera |\r\n" +
170-
"| Android | android |\r\n" +
171-
"| Iphone | iphone |\r\n" +
172-
"| JBrowser | jbrowser |\r\n" +
173-
"| HTMLUnit | htmlunit |\r\n" +
174-
"| HTMLUnit with Javascript | htmlunitwithjs |\r\n" +
175-
"\r\n" +
176-
"To be able to actually use one of these browsers, you need to have a matching Selenium browser driver available. See the [https://github.com/Hi-Fi/robotframework-seleniumlibrary-java#browser-drivers|project documentation] for more details.\r\n" +
177-
"\r\n" +
178-
"Optional ``alias`` is an alias given for this browser instance and it can be used for switching between browsers. An alternative approach for switching is using an index returned by this keyword. These indices start from 1, are incremented when new browsers are opened, and reset back to 1 when `Close All Browsers` is called. See `Switch Browser` for more information and examples.\r\n" +
179-
"\r\n" +
180-
"Optional ``remote_url`` is the URL for a remote Selenium server. If you specify a value for a remote, you can also specify ``desired_capabilities`` to configure, for example, a proxy server for Internet Explorer or a browser and operating system when using [http://saucelabs.com|Sauce Labs]. Desired capabilities can be given as a dictionary. [https://github.com/SeleniumHQ/selenium/wiki/Capabilities| Selenium documentation] lists possible capabilities that can be enabled.\r\n" +
181-
"\r\n" +
182-
"Optional ``ff_profile_dir`` is the path to the Firefox profile directory if you wish to overwrite the default profile Selenium uses. Notice that prior to SeleniumLibrary 3.0, the library contained its own profile that was used by default.\r\n" +
183-
"\r\n" +
184-
"Optional ``isWebDriverManager`` is a flag of using automation download driver of browser and setting system variable for driver path.\r\n" +
185-
"\r\n" +
186-
"Examples:\r\n" +
187-
"| `Open Browser` | http://example.com | Chrome |\r\n" +
188-
"| `Open Browser` | http://example.com | Firefox | alias=Firefox |\r\n" +
189-
"| `Open Browser` | http://example.com | Edge | remote_url=http://127.0.0.1:4444/wd/hub |\r\n" +
190-
"\r\n" +
163+
"| Google Chrome (headless) | googlechromeheadless, chromeheadless, gcheadless |\r\n" +
164+
"| Internet Explorer | internetexplorer, ie |\r\n" +
165+
"| Edge | edge |\r\n" +
166+
"| Safari | safari |\r\n" +
167+
"| Android | android |\r\n" +
168+
"| Iphone | iphone |\r\n" +
169+
"| JBrowser | jbrowser |\r\n" +
170+
"\r\n" +
171+
"To be able to actually use one of these browsers, you need to have a matching Selenium browser driver available. See the [https://github.com/Hi-Fi/robotframework-seleniumlibrary-java#browser-drivers|project documentation] for more details.\r\n" +
172+
"\r\n" +
173+
"Optional ``alias`` is an alias given for this browser instance and it can be used for switching between browsers. An alternative approach for switching is using an index returned by this keyword. These indices start from 1, are incremented when new browsers are opened, and reset back to 1 when `Close All Browsers` is called. See `Switch Browser` for more information and examples.\r\n" +
174+
"\r\n" +
175+
"Optional ``remote_url`` is the URL for a remote Selenium server. If you specify a value for a remote, you can also specify ``desired_capabilities`` to configure, for example, a proxy server for Internet Explorer or a browser and operating system when using [http://saucelabs.com|Sauce Labs]. Desired capabilities can be given as a dictionary. [https://github.com/SeleniumHQ/selenium/wiki/Capabilities| Selenium documentation] lists possible capabilities that can be enabled.\r\n" +
176+
"\r\n" +
177+
"Optional ``ff_profile_dir`` is the path to the Firefox profile directory if you wish to overwrite the default profile Selenium uses. Notice that prior to SeleniumLibrary 3.0, the library contained its own profile that was used by default.\r\n" +
178+
"\r\n" +
179+
"Examples:\r\n" +
180+
"| `Open Browser` | http://example.com | Chrome |\r\n" +
181+
"| `Open Browser` | http://example.com | Firefox | alias=Firefox |\r\n" +
182+
"| `Open Browser` | http://example.com | Edge | remote_url=http://127.0.0.1:4444/wd/hub |\r\n" +
183+
"\r\n" +
191184
"If the provided configuration options are not enough, it is possible to use `Create Webdriver` to customize browser initialization even more.")
192185
@ArgumentNames({ "url", "browserName=firefox", "alias=None", "remoteUrl=None", "desiredCapabilities=None",
193186
"browserOptions=None", "isWebDriverManager=false" })
@@ -661,8 +654,6 @@ protected WebDriver createLocalWebDriver(String browserName, Capabilities desire
661654
case "chromeheadless":
662655
case "googlechromeheadless":
663656
return new ChromeDriver((ChromeOptions)desiredCapabilities);
664-
case "opera":
665-
return new OperaDriver(new OperaOptions().merge(desiredCapabilities));
666657
case "safari":
667658
return new SafariDriver(new SafariOptions().merge(desiredCapabilities));
668659
case "jbrowser":
@@ -769,9 +760,6 @@ protected Capabilities createCapabilities(String browserName, String desiredCapa
769760
parseBrowserOptionsChrome(browserOptions, desiredCapabilities);
770761
((ChromeOptions)desiredCapabilities).setHeadless(true);
771762
break;
772-
case "opera":
773-
desiredCapabilities = new OperaOptions();
774-
break;
775763
case "safari":
776764
desiredCapabilities = new SafariOptions();
777765
break;
@@ -909,25 +897,29 @@ protected void setRemoteWebDriverProxy(HttpCommandExecutor httpCommandExecutor)
909897
className = "DefaultHttpClient";
910898
Field field = HttpCommandExecutor.class.getDeclaredField(fieldName);
911899
field.setAccessible(true);
912-
DefaultHttpClient client = (DefaultHttpClient) field.get(httpCommandExecutor);
900+
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
901+
//DefaultHttpClient client = (DefaultHttpClient) field.get(httpCommandExecutor);
913902

914903
// set the credentials for the proxy
915904
AuthScope authScope = new AuthScope(remoteWebDriverProxyHost, Integer.parseInt(remoteWebDriverProxyPort));
905+
CredentialsProvider credsProvider = new BasicCredentialsProvider();
916906
if (remoteWebDriverProxyDomain.length() == 0) {
917907
// BASIC Authentication
918-
client.getCredentialsProvider().setCredentials(authScope,
908+
credsProvider.setCredentials(authScope,
919909
new UsernamePasswordCredentials(remoteWebDriverProxyUser, remoteWebDriverProxyPassword));
910+
clientBuilder.setDefaultCredentialsProvider(credsProvider);
920911
} else {
921912
// NTLM Authentication
922-
client.getCredentialsProvider().setCredentials(authScope, new NTCredentials(remoteWebDriverProxyUser,
913+
credsProvider.setCredentials(authScope, new NTCredentials(remoteWebDriverProxyUser,
923914
remoteWebDriverProxyPassword, remoteWebDriverProxyWorkstation, remoteWebDriverProxyDomain));
915+
clientBuilder.setDefaultCredentialsProvider(credsProvider);
924916
}
925917

926918
// Set the RoutePlanner back to something that handles
927919
// proxies correctly.
928-
client.setRoutePlanner(new DefaultHttpRoutePlanner(client.getConnectionManager().getSchemeRegistry()));
929920
HttpHost proxy = new HttpHost(remoteWebDriverProxyHost, Integer.parseInt(remoteWebDriverProxyPort));
930-
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
921+
clientBuilder.setRoutePlanner(new DefaultProxyRoutePlanner(proxy));
922+
clientBuilder.setProxy(proxy);
931923
} catch (SecurityException e) {
932924
throw new SeleniumLibraryFatalException(
933925
String.format("The SecurityManager does not allow us to lookup to the %s field.", fieldName));
@@ -937,9 +929,6 @@ protected void setRemoteWebDriverProxy(HttpCommandExecutor httpCommandExecutor)
937929
} catch (IllegalArgumentException e) {
938930
throw new SeleniumLibraryFatalException(
939931
String.format("The field %s does not belong to the given object.", fieldName));
940-
} catch (IllegalAccessException e) {
941-
throw new SeleniumLibraryFatalException(
942-
String.format("The SecurityManager does not allow us to access to the %s field.", fieldName));
943932
} catch (ClassCastException e) {
944933
throw new SeleniumLibraryFatalException(
945934
String.format("The %s field does not contain a %s.", fieldName, className));

0 commit comments

Comments
 (0)