【问题标题】:Ruby Selenium Webdriver - configuring Sauce Labs Pass/FailRuby Selenium Webdriver - 配置 Sauce Labs 通过/失败
【发布时间】:2014-05-02 07:17:05
【问题描述】:

Sauce Labs 有一个特定的:passed 选项,可用于报告测试的通过/失败状态 - (https://saucelabs.com/docs/additional-config)。

我似乎无法理解如何在 Ruby 中完成此任务。

我尝试在我的 类 中创建一个全局变量 ($status),用作 Sauce Labs 测试中 :passed 值的占位符。然后在拆卸期间将占位符更新为适当的值。

在此示例中,测试将始终返回 Fail

在我的班级

$status = false

在我的设置中

caps[:passed] = $status

在我的拆解

def success
  $status = true
end

def error
  $status = false
end

我假设caps[:passed] = $status 在设置期间设置并且无法更改。

我不知道如何在作业完成后更新:passed 状态。

【问题讨论】:

  • 我也试过在我的 teardown 中简单地添加 caps[:passed] = true,但它只是被忽略了。

标签: ruby selenium webdriver saucelabs


【解决方案1】:

直接来自 Sauce Labs found here 的示例。

require 'rubygems'
require "test/unit"
require 'selenium-webdriver'

class ExampleTest < Test::Unit::TestCase
    def setup
        caps = Selenium::WebDriver::Remote::Capabilities.firefox
        caps.version = "5"
        caps.platform = :XP
        caps[:name] = "Testing Selenium 2 with Ruby on Sauce"

        @driver = Selenium::WebDriver.for(
          :remote,
          :url => "http://username-string:access-key-string@ondemand.saucelabs.com:80/wd/hub",
          :desired_capabilities => caps)
    end

    def test_sauce
        @driver.navigate.to "http://saucelabs.com/test/guinea-pig"
        assert @driver.title.include?("I am a page title - Sauce Labs")
    end

    def teardown
        @driver.quit
    end
end

【讨论】:

  • Aww 对不起@sircapsalot 我应该更清楚。 Sauce Labs 中有一个特定的:passed 选项,但我找不到如何使用它的清晰示例(在 Ruby 中)。不过感谢您的帮助。
【解决方案2】:

我能够通过使用 sauce_whisk gem (https://github.com/saucelabs/sauce_whisk) 来完成此操作

“SauceWhisk 为 Sauce Labs RESTful API 提供了一个“ActiveRecord”风格的客户端。如果您不使用 Sauce Gem 并且想要一种与我们的 API 交互的好方法,请尝试一下。”

在driver 设置期间检索SauceLabs 作业ID - 类似于@job_id = @driver.instance_variable_get("@bridge").instance_variable_get("@session_id")

然后在拆卸过程中,我可以使用SauceWhisk::Jobs.pass_job @job_id 或SauceWhisk::Jobs.fail_job @job_id 来设置作业的状态。

【讨论】:

    猜你喜欢
    • 2016-08-27
    • 2012-12-31
    • 2013-06-21
    • 2018-02-17
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 2018-01-01
    • 2014-10-02
    相关资源
    最近更新 更多