【问题标题】:Where are the code examples for connecting your tests to Sauce Connect?将测试连接到 Sauce Connect 的代码示例在哪里?
【发布时间】:2013-03-12 18:03:27
【问题描述】:

我已阅读:Sauce Labs: Connect page

并浏览了互联网,但我找不到任何关于如何将我的 Selenium 测试转换为使用 Sauce Connect 的文档。

有人能指出我正确的方向吗?

干杯

戴夫

【问题讨论】:

  • 也许您可以在投反对票时添加有用的评论?

标签: webdriver saucelabs


【解决方案1】:

默认情况下,Sauce Connect 将通过http://localhost:4445 提供,因此您只需将测试更改为:

WebDriver driver = new RemoteWebDriver(new URL("http://" + username + ":" + accessKey + "@ondemand.saucelabs.com:80/wd/hub"), capabilities);

到:

WebDriver driver = new RemoteWebDriver(new URL("http://" + username + ":" + accessKey + "@localhost:4445/wd/hub"), capabilities);

在使用 Sauce Connect 运行测试时,您不需要更改实际的测试逻辑。

我创建了一个demo project,主要演示如何构建测试以使用 Jenkins 和 Bamboo 的 Sauce 插件,但还包括一个 sample SauceConnectTest,它断言可以使用 Sauce 针对本地网站运行测试使用 Sauce Connect 的实验室。

【讨论】:

  • 这是否意味着我的测试需要在与 SauceConnect 相同的机器上运行?
  • 不,如果 Sauce Connect 在另一台服务器上启动,那么您只需要引用该服务器 URL,例如。新 URL("http://" + 用户名 + ":" + accesskey + "@some.other.host:4445/wd/hub")
  • 感谢您的回答。我应该注意到,SauceLabs 在线文档并没有这么详细地给出这个答案。谢谢。
  • Saucelabs 在线文档即使在 3 年后仍然没有此信息。感谢您提供详细信息
【解决方案2】:

要初始化 webDriver,请使用:

WebDriver webDriver = null;
DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("firefox");
webDriver = new RemoteWebDriver(new URL("http://" + username + ":" + accessKey + "@ondemand.saucelabs.com:80/wd/hub"), capabilities);

现在测试网站,无论您需要什么,假设您需要 google:

webDriver.get("http://www.google.com");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    相关资源
    最近更新 更多