2

I'm trying to access a saucelabs emulator with the following code:

public static final String USERNAME = "redacted";
public static final String ACCESS_KEY = "redacted";
public static final String URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub";

public static void main(String[] args) throws Exception {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", "Samsung Galaxy S9 WQHD GoogleAPI Emulator");
    capabilities.setCapability("platformVersion", "7.1");
    capabilities.setCapability("app", "sauce-storage:test-app.apk");
    capabilities.setCapability("browserName", "");
    capabilities.setCapability("deviceOrientation", "portrait");
    capabilities.setCapability("appiumVersion", "1.7.2");

    AndroidDriver driver = new AndroidDriver(new URL(URL), capabilities);

    driver.quit();
}

However, Saucelabs is giving me the following error:

    Exception in thread "main" org.openqa.selenium.WebDriverException: Unable to parse remote response: Misconfigured -- Sauce Labs Authentication Error.
You used username 'None' and access key 'None' to authenticate, which are not valid Sauce Labs credentials.

The following desired capabilities were received:
{'app': 'sauce-storage:test-app.apk',
 'appiumVersion': '1.7.2',
 'browserName': '',
 'deviceName': 'Samsung Galaxy S9 WQHD GoogleAPI Emulator',
 'deviceOrientation': 'portrait',
 'platformName': 'Android',
 'platformVersion': '7.1'}
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'LCHIPB7K9GM', ip: '10.219.159.36', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_162'
Driver info: driver.version: AndroidDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:111)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:83)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:93)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:72)
    at com.qecop.tests.troubleshoot.main(troubleshoot.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Process finished with exit code 1

Why is this error occurring? My username and password is not blank. I'm using Selenium/Java client library 3.9.1 and Appium/Java client library 5.0.4.

Emily
  • 82
  • 1
  • 10

4 Answers4

1

Make sure that your user name doesn't contains @,i too have faced same problem with selenium, appium.

Nagasatish
  • 36
  • 4
0

This generally comes when you have something like :

public static final String USERNAME = "";
public static final String ACCESS_KEY = "";

Try to print your URL String in console and see if the URL is forming properly when Username and password are appended.

dangi13
  • 1,275
  • 1
  • 8
  • 11
  • The URL is forming correctly. I just tried printing out the URL (not the string) and it's working. As shown in my code that I posted, I did not leave the username or access_key fields to be empty strings. – Emily Aug 16 '18 at 16:40
0

As per the latest documentation (Aug 2019), send the Sauce username and accessKey as part of the DesiredCapabilities, like this:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("username", sauceUserName);
capabilities.setCapability("accessKey", sauceAccessKey);
// ... other capabilities

You can remove the username and accessKey from the URL. And even better, you can use the https URL:

String URL = "https://ondemand.saucelabs.com/wd/hub";

Code taken from: https://github.com/saucelabs-training/demo-java/blob/master/on-boarding-modules/junit/src/test/java/Module2JunitTest.java

Helpful reference: https://wiki.saucelabs.com/display/DOCS/Best+Practice%3A+Use+Environment+Variables+for+Authentication+Credentials

Jagan
  • 447
  • 5
  • 12
0

I was getting that error when trying to use an account that had 0 automation test minutes remaining. When I created a brand new trial account, and used the below code, the error went away.

@BeforeTest
   public void setUp() throws Exception{
       capabilities = new DesiredCapabilities();
       capabilities.setCapability("deviceName","Android Emulator");
       capabilities.setCapability("deviceOrientation", "portrait");
       capabilities.setCapability("browserName", "");
       capabilities.setCapability("platformVersion","5.1");
       capabilities.setCapability("platformName","Android");
       capabilities.setCapability("app","sauce-storage:samsclub.apk");


       driver = new AndroidDriver(new URL("https://newUsername:1234567890Key@ondemand.saucelabs.com:443/wd/hub"),capabilities);
   }
HRVHackers
  • 2,793
  • 4
  • 36
  • 38