Selenium-Ruby Тестирование на основе данных о нагрузке / производительности: как вызвать один и тот же тест для нескольких настроек данных
Итак, я запускаю этот тест в 10 экземплярах на общую сумму около 1000 создаваемых учетных записей пользователей, это своего рода исчерпывающее тестирование производительности. Я хочу иметь возможность записывать тестовые файлы в качестве настроек данных и вызывать основной тест в каждом. но я до сих пор не нашел действенного ответа в Google (я удалил некоторую потенциально конфиденциальную информацию с помощью 'blahblahblah')
Изменения в настройках теста: у меня есть 10 CSV-файлов, вызываемых в 10 экземплярах на 10 дисплеях
def setup
@proxy = configure_proxy
@headless = Headless.new(display: 91)
@headless.start
# Selenium::WebDriver.logger.level = :info #uncomment this if you need more info, but less than debug
# Selenium::WebDriver.logger.level = :debug #uncomment this if you need to debug
# opts = Selenium::WebDriver::Firefox::Options.new(log_level: :trace) #uncomment this if you need to debug
@capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
@driver = Selenium::WebDriver.for :firefox, desired_capabilities: @capabilities, profile: browser_profile#, options: opts #uncomment this if you need to debug
end
def cust_data
cust_data = CSV.read '/home/mwilliams/selenium/test_data/enroll_data_1.csv'
descriptor = cust_data.shift
descriptor = descriptor.map { |key| key.to_sym }
cust_data.map { |cust| Hash[descriptor.zip(cust) ] }
end
def teardown
ensure
@driver.quit
@proxy.close
@headless.destroy
end
Тестовая настройка, которая не изменяется, определения и требования
require 'rubygems'
require 'headless'
require 'selenium-webdriver'
require 'browsermob/proxy'
require 'rspec/expectations'
require 'csv'
include RSpec::Matchers
def configure_proxy
proxy_binary = BrowserMob::Proxy::Server.new('./browsermob-proxy/bin/browsermob-proxy')
proxy_binary.start
proxy_binary.create_proxy
end
def browser_profile
browser_profile = Selenium::WebDriver::Firefox::Profile.new
browser_profile.proxy = @proxy.selenium_proxy
browser_profile
end
def teardown
ensure
@driver.quit
@proxy.close
@headless.destroy
end
def wait_for(seconds)
Selenium::WebDriver::Wait.new(timeout: seconds).until {yield}
end
def page_title
puts "Current page = #{@driver.title}"
end
def add_inbox
@driver.find_element(:css, 'blahblahblah')
end
def accept_inbox
@driver.find_element(:css, 'blahblahblahs')
end
def retry_on_accept_inbox(displayed)
yield
until !accept_inbox.displayed?
yield
end
end
def email_new
@driver.find_element(:css, 'blahblahblah')
end
def enroll_btn
@driver.find_element(id: 'blahblahblah')
end
def enroll_err
@driver.find_element(:css, 'blahblahblah')
end
def retry_on_enroll_err(displayed)
yield
until !enroll_err.displayed?
yield
end
end
def nada_email
@driver.find_element(:css, 'blahblahblah')
end
def retry_on_nada_email(displayed)
yield
until nada_email.displayed?
yield
end
end
def retry_on_wrong_email(text)
yield
until nada_email.text
yield
end
end
def login_user
@driver.find_element(id: 'username')
end
def login_err
@driver.find_element(id: 'user-form-alert')
end
def retry_on_login_err(displayed)
yield
until !login_err.displayed?
yield
end
end
def digital_consent
@driver.find_element(id: 'blahblahblah')
end
def rescue_exceptions
begin
yield
rescue Selenium::WebDriver::Error::NoSuchElementError => e
false
puts e.message
@driver.save_screenshot "/home/mwilliams/selenium/screenshots/failures/#{Time.now.strftime("no_element_%m-%d-%Y_%H%M%S")}.png"
rescue Selenium::WebDriver::Error::ElementNotVisibleError => e
false
puts e.message
@driver.save_screenshot "/home/mwilliams/selenium/screenshots/failures/#{Time.now.strftime("not_visible_%m-%d-%Y_%H%M%S")}.png"
rescue Selenium::WebDriver::Error::StaleElementReferenceError => e
false
puts e.message
@driver.save_screenshot "/home/mwilliams/selenium/screenshots/failures/#{Time.now.strftime("stale_element_%m-%d-%Y_%H%M%S")}.png"
retry
rescue Selenium::WebDriver::Error::TimeOutError => e
false
puts e.message
@driver.save_screenshot "/home/mwilliams/selenium/screenshots/failures/#{Time.now.strftime("timeout_%m-%d-%Y_%H%M%S")}.png"
rescue Selenium::WebDriver::Error::ElementClickInterceptedError => e
puts e.message
@driver.save_screenshot "/home/mwilliams/selenium/screenshots/failures/#{Time.now.strftime("intercept_%m-%d-%Y_%H%M%S")}.png"
retry
rescue Selenium::WebDriver::Error::UnknownError => e
puts e.message
@driver.save_screenshot "/home/mwilliams/selenium/screenshots/failures/#{Time.now.strftime("unknown_%m-%d-%Y_%H%M%S")}.png"
retry
rescue RSpec::Expectations::ExpectationNotMetError => e
false
puts e.message
@driver.save_screenshot "/home/mwilliams/selenium/screenshots/failures/#{Time.now.strftime("failshot_%m-%d-%Y_%H%M%S")}.png"
end
end
def run
setup
begin
yield
end
teardown
end
Основной тестовый код, не меняется.
cust_data.each do |cust|
run do
@driver.navigate.to 'blahblahblah'
main_tab = @driver.window_handle
page_title
@driver.execute_script('window.open()')
@driver.switch_to.window(@driver.window_handles.last)
@driver.navigate.to 'https://getnada.com/'
all_windows = @driver.window_handles
email_tab = @driver.window_handle
@driver.switch_to.window(email_tab)
page_title
expect(@driver.title).to eql 'Nada - temp mail - fast and free'
add_inbox.click
wait_for(5) {accept_inbox.displayed?}
rescue_exceptions {retry_on_accept_inbox true do
accept_inbox.click
end}
String email = email_new.text()
@driver.switch_to.window(main_tab)
expect(@driver.title).to eql 'blahblahblah'
page_title
@driver.find_element(:css, 'blahblahblah').click
puts "Entering data from record #{cust[:RECORDNUM]} @ #{(Time.now.strftime("%m-%d-%Y_%H%M%S"))}"
wait_for(10) {@driver.find_element(id: 'blahblahblah')}
page_title
@driver.find_element(name: 'firstname').send_keys cust[:FIRSTNAME]
@driver.find_element(name: 'lastname').send_keys cust[:LASTNAME]
@driver.find_element(name: 'ssn').send_keys cust[:SSN]
@driver.find_element(id: 'blahblahblah').click
rescue_exceptions {wait_for(15) {@driver.find_element(name: 'emailSignup').displayed?}}
rescue_exceptions {@driver.find_element(name: 'emailSignup').send_keys(email)}
@driver.find_element(name: 'usernameSignup').send_keys cust[:USERID]
@driver.find_element(name: 'passwordSignup').send_keys cust[:PASSWORD]
@driver.find_element(name: 'passwordConfirmSignup').send_keys cust[:PASSWORD]
enroll_btn.click
rescue_exceptions {enroll_btn.click}
puts "Checking for Errors"
wait_for(20) {!enroll_btn.displayed?}
@driver.switch_to.window(email_tab)
expect(@driver.title).to eql 'Nada - temp mail - fast and free'
page_title
rescue_exceptions {wait_for(10){nada_email.displayed?}}
retry_on_nada_email false do
puts "Checking Nada Email"
case rescue_exceptions {nada_email.displayed?}
when false
puts "No Email found, Refreshing"
@driver.switch_to.window(main_tab)
expect(@driver.title).to eql 'blahblahblah'
page_title
@driver.switch_to.window(email_tab)
expect(@driver.title).to eql 'Nada - temp mail - fast and free'
page_title
when true
puts "Emails found, checking for verification email."
end
end
retry_on_wrong_email false do
puts "Checking for Verification Email"
case rescue_exceptions {expect(nada_email.text).to eql 'blahblahblah'}
when false
puts "Verification Email not found, Refreshing"
@driver.switch_to.window(main_tab)
expect(@driver.title).to eql 'blahblahblah'
page_title
@driver.switch_to.window(email_tab)
expect(@driver.title).to eql 'Nada - temp mail - fast and free'
page_title
puts "Refreshed the email page"
when true
puts "Verification Email found"
rescue_exceptions {expect(nada_email.text).to eql 'blahblahblah'}
nada_email.click
wait_for(5) {@driver.find_element(id: 'idIframe').displayed?}
@driver.switch_to.frame('idIframe')
@driver.find_element(:css, 'body > p:nth-child(4) > a').click
end
end
@driver.switch_to.window(@driver.window_handles.last)
auth_tab = @driver.window_handle
puts "blahblahblah"
@driver.switch_to.window(main_tab)
expect(@driver.title).to eql 'blahblahblah'
page_title
@driver.find_element(:css, 'blahblahblah').click
expect(@driver.title).to eql 'blahblahblah'
page_title
@driver.find_element(id: 'username').send_keys cust[:USERID]
puts "user entered"
@driver.find_element(id: 'password').send_keys cust[:PASSWORD]
puts "password entered"
@driver.find_element(:css, 'blahblahblah').click
puts "login information submitted"
puts "Checking for Errors"
rescue_exceptions {wait_for(10) {!login_user.displayed?}}
case rescue_exceptions {login_user.displayed?}
when false
expect(rescue_exceptions {login_user.displayed?}).to eql false
puts "blahblahblah"
when true
expect(rescue_exceptions {login_user.displayed?}).to eql true
retry_on_login_err true do
puts "Error found trying to login"
case rescue_exceptions {login_err.displayed?}
when false
puts "No error message found"
break
when true
puts "Error message = #{login_err.text}"
@driver.switch_to.window(email_tab)
expect(@driver.title).to eql 'Nada - temp mail - fast and free'
page_title
rescue_exceptions {expect(nada_email.text).to eql 'blahblahblah'}
nada_email.click
wait_for(5) {@driver.find_element(id: 'idIframe').displayed?}
@driver.switch_to.frame('idIframe')
@driver.find_element(:css, 'body > p:nth-child(4) > a').click
@driver.switch_to.window(@driver.window_handles.last)
auth_tab = @driver.window_handle
puts "Enrolled Student Verified"
@driver.switch_to.window(main_tab)
expect(@driver.title).to eql 'blahblahblah'
page_title
login_user.send_keys cust[:USERID]
puts "user entered"
@driver.find_element(id: 'password').send_keys cust[:PASSWORD]
puts "password entered"
@driver.find_element(:css, 'blahblahblah').click
puts "login information submitted"
puts "Checking for Errors"
rescue_exceptions {wait_for(10) {!login_user.displayed?}}
end
end
end
page_title
expect(@driver.title).to eql 'blahblahblah'
case rescue_exceptions {digital_consent.displayed?}
when true
expect(rescue_exceptions {digital_consent.displayed?}).to eql true
rescue_exceptions {@driver.find_element(:css, 'blahblahblah').click}
when false
expect(rescue_exceptions {digital_consent.displayed?}).to eql false
end
end
end
Я полагаю, что мне нужен основной тестовый файл и 10 файлов данных / экземпляров, и я хочу, чтобы в каждом из них вызывался основной тестовый файл, но я не могу найти инструкции, которым могу следовать, для достижения этой цели.