Skip to content

Instantly share code, notes, and snippets.

@DylanLacey
Created March 7, 2018 04:23
Show Gist options
  • Save DylanLacey/52c8f0bfae0daca6658f2690464898b3 to your computer and use it in GitHub Desktop.
Save DylanLacey/52c8f0bfae0daca6658f2690464898b3 to your computer and use it in GitHub Desktop.
Encoding Usernames for RemoteWebDriver
// Add to the end of your imports
import java.net.URLEncoder;
public String username = "someone@company";
public String accesskey = "abc123-defgh4312-deftg";
// Inside your driver creation method
String seleniumServer = "ondemand.saucelabs.com:443";
String authenticatedURL = "https://" + URLEncoder.encode(username) + ":" + accesskey + "@" + seleniumUrl + "/wd/hub";
URL seleniumURL = new URL(authenticatedURL);
// Can be removed entirely once you can connect (or replaced with a call to your logger)
System.out.println(seleniumURL.toString());
// Launch remote browser and set it as the current thread
webDriver.set(new RemoteWebDriver(
seleniumURL,
capabilities));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment