【问题标题】:Rspec Selenium passing variable using through command and use that variable in test caseRspec Selenium 使用通过命令传递变量并在测试用例中使用该变量
【发布时间】:2015-10-28 17:26:05
【问题描述】:

我有一个这样的测试用例。

  describe "City Sports" do
context 'xyz cases' do
  it 'checks the xyz signin' do
    visit "https://secure-xyz/"
    fill_in 'emailAddress', with: email
    fill_in 'password', with: "password1"
    find_button('signInButton').trigger('click')
    if current_url == "https://secure-xyz.do"
      #click_button 'Register'
      fill_in 'newEmailAddress', with: email
      find_button('registerButton').trigger('click')
      fill_in 'password', with: 'password1'
      find_button('registrationSubmitButton').trigger('click')
    end
  end
end

我有这个测试用例和我在测试用例中使用的变量 email 我想通过命令行像 rspec 规范/用户:#{email}/sign_in.rb

如何通过命令行传递电子邮件变量以及如何在测试用例中获取此变量。

【问题讨论】:

    标签: ruby-on-rails ruby selenium rspec


    【解决方案1】:

    我通过在 rake 任务中添加所有测试用例解决了这个问题,我通过它来调用它。

    email="abcAgmail.com,password" rake task:task
    

    它对我来说很好用。

    【讨论】:

      【解决方案2】:

      你最好的选择(如果你真的想走这条路)将考虑使用 rake 文件,因为据我所知,如果不自定义 rspec 命令(我不推荐这个)你不会可以传入一个变量。

      另一个更简洁的解决方案是将测试电子邮件地址等内容保存在某种配置中,然后您的测试可以使用这些配置。例如你可以有一个测试数据模块:

      module TestData
        module Users
          def known_user
            { email: 'email@example.com', password: 'password' }
          end
        end
      end
      

      然后可以在您的测试中使用TestData::Users.known_user 访问它,并根据您要获取的数据位附加[:email][:password]。这样做的好处是您不必将变量传递给测试。毕竟,您肯定会希望最终运行整个测试套件,而必须为每个测试提供参数将成为一场噩梦。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-04-20
        • 1970-01-01
        • 1970-01-01
        • 2018-09-21
        • 2012-11-20
        • 1970-01-01
        • 2021-08-26
        相关资源
        最近更新 更多