Take a screenshot with Cucumber

后端 未结 6 857
伪装坚强ぢ
伪装坚强ぢ 2021-01-03 17:31

I just learn how to use cucumber. Can you tell me how to complete this code?

You can implement step definitions for undefined steps with these snippets:



        
6条回答
  •  孤独总比滥情好
    2021-01-03 18:05

    I am providing the code which will take the snapshot when scenario is failed, I hope you can modify according to your uses, Comment here if you can't do that. This code is in ruby with Ubuntu system

    #Create a directory for storing snapshot
    dir_path = "/home/vchouhan/vijay_work/snapshot"
    unless Dir.exist?(dir_path)
        Dir.mkdir(dir_path,0777)
        puts "=========Directory is created at #{dir_path}"
    else
        puts "=========Directory is exist at #{dir_path}"
    end
    
    #Run after each scenario
    After do |scenario|
      #Check, scenario is failed?
      if(scenario.failed?)
             time = Time.now.strftime('%Y_%m_%d_%Y_%H_%M_%S_')
             name_of_scenario = time + scenario.name.gsub(/\s+/, "_").gsub("/","_")
             puts "Name of snapshot is #{name_of_scenario}"
             file_path = File.expand_path(dir_path)+'/'+name_of_scenario +'.png'
             page.driver.browser.save_screenshot file_path
             puts "Snapshot is taken"
        puts "#===========================================================#"
        puts "Scenario:: #{scenario.name}"
        puts "#===========================================================#"
      end
    end
    

提交回复
热议问题