【问题标题】:Running selenium test against multiple websites with a different sub-domain针对具有不同子域的多个网站运行 selenium 测试
【发布时间】:2022-08-16 23:54:19
【问题描述】:

当我在 ruby​​ 文件中硬编码一个 URL 以供 Selenium 执行时,我有一个测试工作,但是我需要对具有不同子域的多个 URL 运行相同的测试

当我运行以下命令时,我收到一个错误,即 split 是一种未知方法

require \'rubygems\'
require \'selenium-webdriver\'

driver = Selenium::WebDriver.for :chrome

pageLoad = sleep 1
subD = ARGV.split(\",\")
instances = []
subD.each do |test|
  instances << test
end
instances.each do |cub|
url = \'http://\' + sub + \'.test.com\'
driver.get url
puts \"#{url}\"

begin
  driver.find_element(:id, \'user_login\').send_keys \'user 1\'
  driver.find_element(:id, \'user_password\').send_keys \'password1\'
  driver.find_element(:id, \'login_button\').click
  puts \'Logging In\'
rescue StandardError
  puts \'Unable to login\'
end
pageLoad
puts \'Test Complete\'
sleep 5
end
driver.quit

这是错误

test.rb:8:in `<main>\': undefined method `split\' for [\"test1,test2,test3\"]:Array (NoMethodError)

输入

ruby test.rb test1,test2,test3

    标签: ruby selenium selenium-webdriver selenium-ruby


    【解决方案1】:

    ARGV 是一个数组而不是一个字符串,你要么需要分别传递每个子域然后遍历 ARGV,要么使用ARGV[0] 访问 ARGV 的第一个成员

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 2013-01-31
      • 2013-04-07
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      相关资源
      最近更新 更多