第一个测试套件失败了allure-rspec

时间:2015-05-25 10:46:37

标签: ruby rspec selenium-webdriver allure

我正在努力将allure集成到我的测试中,但遇到了第一个测试套件失败并返回未定义方法`find_element' for nil:套件中的每个测试都出现NilClass错误。当我没有使用诱惑时,测试按预期运行,无论运行什么套件,都会发生同样的事情。

我已经查看了它,似乎我的规范助手中的前后钩子都没有在失败的测试中使用。可能导致这种情况的任何想法?

require 'rspec'
require 'selenium-webdriver'
require 'allure-rspec'
require 'nokogiri'
require 'uuid'
require 'pathname'

RSpec.configure do |c|


c.include AllureRSpec::Adaptor


c.expect_with :rspec do |c|
    ### Enable both should and expect syntax ###
    c.syntax = [:should, :expect]
end

c.before(:all) do
    #Start the Phantom-js driver before running any headless tests
    case ENV['browser']
    when 'headless'
        ## Run in command line before a headless test: phantomjs --webdriver=8001
        system('start cmd /k phantomjs --webdriver=8001')
        sleep 3
    end
end

c.before(:each) do  
    #Find the browser to the used and set the driver to the appropriate one
    case ENV['browser']
    when 'chrome'
        @driver = Selenium::WebDriver.for :chrome
        #@driver = Selenium::WebDriver.for(:remote, url: 'http://localhost:5555/wd/hub', desired_capabilities: :chrome)
    when 'ie'
        @driver = Selenium::WebDriver.for :internet_explorer
        #@driver = Selenium::WebDriver.for(:remote, url: 'http://localhost:5555/wd/hub', desired_capabilities: :ie)
    when 'firefox'
        @driver = Selenium::WebDriver.for :firefox
        #@driver = Selenium::WebDriver.for(:remote, url: 'http://localhost:5555/wd/hub', desired_capabilities: :firefox)
    when 'headless'
        @driver = Selenium::WebDriver.for :remote, url: 'http://localhost:8001'
    end
    #Maximize the browser
    @driver.manage.window.maximize
    @driver.get ENV['base_url']
end

c.after(:each) do |c|
    #Takes a screen shot if an exception is thrown and attaches it to the allure XML when running Rake tests
    if c.exception != nil
        $failure = true

            c.attach_file("screenshot", File.new(@driver.save_screenshot(File.join(Dir.pwd, "test_reports/allure/#{UUID.new.generate}.png"))))

    end 
    @driver.quit
end 

end

AllureRSpec.configure do |c|
   #Outputs the Allure XML
   c.output_dir = "test_reports/allure"
end

0 个答案:

没有答案