Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove desired capabilities #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions java/testng/W3CChromeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.testng.asserts.*;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.JavascriptExecutor;

Expand All @@ -21,7 +20,7 @@ public class W3CChromeTest {
- Define Environment Variables for Sauce Credentials ("SAUCE_USERNAME" and "SAUCE_ACCESS_KEY")
- Define Chrome Options such as W3C protocol
- Define the "sauce:options" capabilities, indicated by the "sauceOpts" MutableCapability object
- Define the WebDriver capabilities, indicated by the "caps" DesiredCapabilities object
- Define the WebDriver capabilities, indicated by the ChromeOptions object
- Define the service URL for communicating with SauceLabs.com indicated by "sauceURL" string
- Set the URL to sauceURl
- Set the driver instance to a RemoteWebDriver
Expand All @@ -33,13 +32,6 @@ public void setup(Method method) throws MalformedURLException {
String username = System.getenv("SAUCE_USERNAME");
String accessKey = System.getenv("SAUCE_ACCESS_KEY");
String methodName = method.getName();

/** ChomeOptions allows us to set browser-specific behavior such as profile settings, headless capabilities, insecure tls certs,
and in this example--the W3C protocol
For more information see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html */

ChromeOptions chromeOpts = new ChromeOptions();
chromeOpts.setExperimentalOption("w3c", true);

/** The MutableCapabilities class came into existence with Selenium 3.6.0 and acts as the parent class for
all browser implementations--including the ChromeOptions class extension.
Expand All @@ -50,17 +42,26 @@ public void setup(Method method) throws MalformedURLException {
sauceOpts.setCapability("seleniumVersion", "3.141.59");
sauceOpts.setCapability("username", username);
sauceOpts.setCapability("accessKey", accessKey);
sauceOpts.setCapability("tags", "w3c-chrome-tests")
/** Below we see the use of our other capability objects, 'chromeOpts' and 'sauceOpts',
defined in ChromeOptions.CAPABILITY and sauce:options respectively.
sauceOpts.setCapability("tags", "w3c-chrome-tests");

/** Below we see set the ChromeOptions of the browser to connect to a Chrome instance of
* a browser. We can also set Chrome-specific options in this object as well.
*/
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
ChromeOptions options = new ChromeOptions();
options.setCapability("browserName", "googlechrome");
options.setCapability("browserVersion", "71.0");
options.setCapability("platformName", "windows 10");

/** ChomeOptions allows us to set browser-specific behavior such as profile settings, headless capabilities, insecure tls certs,
and in this example--the W3C protocol
For more information see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html */

options.setExperimentalOption("w3c", true);


/** Set the sauceOptions capability to make use of Sauce's capabilities */
caps.setCapability("sauce:options", sauceOpts);
caps.setCapability("browserName", "googlechrome");
caps.setCapability("browserVersion", "71.0");
caps.setCapability("platformName", "windows 10");


/** Finally, we pass our DesiredCapabilities object 'caps' as a parameter of our RemoteWebDriver instance */
String sauceUrl = "https://ondemand.saucelabs.com:443/wd/hub";
Expand Down
32 changes: 13 additions & 19 deletions java/testng/W3CFireFoxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ public void setup(Method method) throws MalformedURLException {
String username = System.getenv("SAUCE_USERNAME");
String accessKey = System.getenv("SAUCE_ACCESS_KEY");
String methodName = method.getName();

/** FirefoxOptions allows us to set browser-specific behavior such as profile settings, headless capabilities, insecure tls certs,
and in this example--the W3C protocol
For more information see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxOptions.html */

FirefoxOptions foxOpts = new FirefoxOptions();
foxOpts.setCapability("w3c", true);

/** The MutableCapabilities class came into existence with Selenium 3.6.0 and acts as the parent class for
all browser implementations--including the FirefoxOptions class extension.
Expand All @@ -50,18 +43,19 @@ public void setup(Method method) throws MalformedURLException {
sauceOpts.setCapability("seleniumVersion", "3.141.59");
sauceOpts.setCapability("username", username);
sauceOpts.setCapability("accessKey", accessKey);
sauceOpts.setCapability("tags", "w3c-chrome-tests")

/** Below we see the use of our other capability objects, 'foxOpts' and 'sauceOpts',
defined in 'moz:firefoxOptions' and sauce:options respectively.
*/
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("moz:firefoxOptions", foxOpts);
caps.setCapability("sauce:options", sauceOpts);
caps.setCapability("browserName", "firefox");
caps.setCapability("browserVersion", "64.0");
caps.setCapability("platformName", "windows 10");

sauceOpts.setCapability("tags", "w3c-firefox-tests")

/** FirefoxOptions allows us to set browser-specific behavior such as profile settings, headless capabilities, insecure tls certs,
and in this example--the W3C protocol
For more information see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxOptions.html */

FirefoxOptions foxOpts = new FirefoxOptions();
options.setCapability("w3c", true);
options.setCapability("browserName", "firefox");
options.setCapability("browserVersion", "64.0");
options.setCapability("platformName", "windows 10");
option.setCapability("sauce:options", sauceOpts);

/** Finally, we pass our DesiredCapabilities object 'caps' as a parameter of our RemoteWebDriver instance */
String sauceUrl = "https://ondemand.saucelabs.com:443/wd/hub";
URL url = new URL(sauceUrl);
Expand Down