셀레늄 RC : 여러 브라우저에서 테스트를 자동으로 실행합니다
-
03-07-2019 - |
문제
그래서 나는 사용하는 루비 단위 테스트를 만들기 시작했습니다. 셀레늄 RC 브라우저에서 내 웹 앱을 직접 테스트합니다. 나는 사용하고있다 Selenum-Client 루비를 위해. 다른 모든 셀레늄 테스트를위한 기본 클래스를 만들었습니다.
이것은 수많은 Seleniumdriver 인스턴스를 생성하며 누락 된 모든 방법이 각 인스턴스에서 호출됩니다. 이것은 본질적으로 테스트를 병렬로 실행합니다.
다른 사람들이 이것을 어떻게 자동화 했습니까?
이것은 내 구현입니다.
class SeleniumTest < Test::Unit::TestCase
def setup
@seleniums = %w(*firefox *iexplore).map do |browser|
puts 'creating browser ' + browser
Selenium::SeleniumDriver.new("localhost", 4444, browser, "http://localhost:3003", 10000)
end
start
open start_address
end
def teardown
stop
end
#sub-classes should override this if they want to change it
def start_address
"http://localhost:3003/"
end
# Overrides standard "open" method
def open(addr)
method_missing 'open', addr
end
# Overrides standard "type" method
def type(inputLocator, value)
method_missing 'type', inputLocator, value
end
# Overrides standard "select" method
def select(inputLocator, optionLocator)
method_missing 'select', inputLocator, optionLocator
end
def method_missing(method_name, *args)
@seleniums.each do |selenium_driver|
if args.empty?
selenium_driver.send method_name
else
selenium_driver.send method_name, *args
end
end
end
end
이것은 작동하지만 하나의 브라우저가 실패하면 전체 테스트가 실패하고 어떤 브라우저가 실패했는지 알 수있는 방법이 없습니다.
해결책
시도해 보았 니 셀레늄 그리드? 필요한 세부 정보를 보여주는 꽤 좋은 요약 보고서를 작성한다고 생각합니다. 꽤 오랫동안 사용하지 않았기 때문에 틀릴 수 있습니다.
다른 팁
나는 셀레늄의 프로토콜을 수정하여 AssertionFailedError
둘 다 @browser_string
그리고 메시지가 반환되었습니다 응답이 "OK"로 시작되지 않은 경우 Selenium RC에서. 나는 또한 수정했다 http_post
전체 응답 본문을 반환하는 방법 method_missing
get_x 명령을 Selenium RC에 발행하기위한 반환 값을 반환합니다.
질문 에서이 코드를 코드에 추가하십시오 그리고 어떤 브라우저에 어떤 어설 션이 실패하는지 확인할 수 있어야합니다.
# Overrides a few Driver methods to make assertions return the
# browser string if they fail
module Selenium
module Client
class Driver
def remote_control_command(verb, args=[])
timeout(default_timeout_in_seconds) do
status, response = http_post(http_request_for(verb, args))
raise Test::Unit::AssertionFailedError.new("Browser:#{@browser_string} result:#{response}") if status != 'OK'
return response[3..-1]
end
end
def http_post(data)
http = Net::HTTP.new(@server_host, @server_port)
response = http.post('/selenium-server/driver/', data, HTTP_HEADERS)
#return the first 2 characters and the entire response body
[ response.body[0..1], response.body ]
end
end
end
end
#Modify your method_missing to use seleniums.map to return the
#results of all the function calls as an array
class SeleniumTest < Test::Unit::TestCase
def method_missing(method_name, *args)
self.class.seleniums.map do |selenium_driver|
selenium_driver.send(method_name, *args)
end
end
end
면책 조항 : 셀레늄 전문가가 아닙니다.
어떤 브라우저가 실패했는지 알고 싶습니까, 아니면 모든 브라우저에서 테스트를 실행하고 완료되면 총 고장을보고 하시겠습니까?
전자는 설정에 해시로 드라이버를 저장하면 매우 간단합니다. (해시와 함께이 작업을 수행하는 멋진 바지 방법이 있다고 확신하지만 게으르다.)
@seleniums = {}
%w(*firefox *iexplore).each do |browser|
puts 'creating browser ' + browser
@seleniums[browser] = Selenium::SeleniumDriver.new("localhost", 4444, browser, "http://localhost:3003", 10000)
end
그런 다음 핵심 기능을 변경하여 사용중인 드라이버의 이름을 포함하도록 예외를 수정하십시오.
@seleniums.each do |name, driver|
begin
driver.send method_name, *args
rescue Exception => ex
raise ex.exception(ex.message + " (in #{name})")
end
end
당신을 가까이 데려 가야합니다.
모든 테스트를 독립적으로 처리해야합니다. 따라서 하나의 테스트가 실패하면 다른 테스트 테스트를 계속합니다. 체크 아웃 phpunit 및 셀레늄 RC