SauceLabs无法读取我的用户名和访问密钥

时间:2018-08-16 16:10:57

标签: java selenium automated-tests appium saucelabs

我正在尝试使用以下代码访问ucelabs仿真器:

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();
}

但是,Saucelabs给我以下错误:

    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

为什么会发生此错误?我的用户名和密码不为空。我正在使用Selenium / Java客户端库3.9.1和Appium / Java客户端库5.0.4。

4 个答案:

答案 0 :(得分:0)

通常在出现类似以下内容时出现

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

尝试在控制台中打印URL字符串,并在添加用户名和密码后查看URL的格式是否正确。

答案 1 :(得分:0)

确保您的用户名不包含@,我也同样遇到硒,鸦片的问题。

答案 2 :(得分:0)

根据最新文档(2019年8月),将酱汁usernameaccessKey作为DesiredCapabilities的一部分发送,如下所示:

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

您可以从URL中删除用户名和accessKey。甚至更好的是,您可以使用https URL:

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

代码取自: https://github.com/saucelabs-training/demo-java/blob/master/on-boarding-modules/junit/src/test/java/Module2JunitTest.java

有用的参考资料: https://wiki.saucelabs.com/display/DOCS/Best+Practice%3A+Use+Environment+Variables+for+Authentication+Credentials

答案 3 :(得分:0)

尝试使用剩余0分钟自动化测试分钟的帐户时出现错误。 当我创建一个全新的试用帐户并使用以下代码时,该错误消失了。

@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);
   }