Class: SetupWatirCucumber::CucumberInit
- Inherits:
-
Object
- Object
- SetupWatirCucumber::CucumberInit
- Defined in:
- lib/setupWatirCucumber.rb
Instance Method Summary collapse
- #create_base_scenario(path) ⇒ Object
- #create_base_step(path) ⇒ Object
- #create_config_yml(path) ⇒ Object
- #create_env(path) ⇒ Object
- #create_hooks(path) ⇒ Object
- #cucumber_init(path) ⇒ Object
- #init(path) ⇒ Object
-
#initialize(path) ⇒ CucumberInit
constructor
A new instance of CucumberInit.
Constructor Details
#initialize(path) ⇒ CucumberInit
Returns a new instance of CucumberInit.
9 10 11 |
# File 'lib/setupWatirCucumber.rb', line 9 def initialize(path) init(path) end |
Instance Method Details
#create_base_scenario(path) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/setupWatirCucumber.rb', line 69 def create_base_scenario(path) puts "Configuring base.feature file" File.open("#{path}features/base.feature", "w+") do |f| f.write ' Feature: Medium Scenario: Find user Gederson Chiquesi Given that I am in the website http://medium.com When I search for GedersonChiquesi Then I should see the user "Gederson Chiquesi" ' end end |
#create_base_step(path) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/setupWatirCucumber.rb', line 83 def create_base_step(path) puts "configuring base_steps.rb file" File.open("#{path}/features/step_definitions/base_steps.rb","w+") do |f| f.write ' Given("that I am in the website http://medium.com") do @browser.goto "http://medium.com" expect(@browser.title).to eq("Medium – Read, write and share stories that matter") end When("I search for GedersonChiquesi") do @browser.text_field(:class => "js-predictiveSearchInput").set "GedersonChiquesi" end Then("I should see the user {string}") do |string| user = @browser.div.span(:class => "avatar-text").text expect(user).to eq("Gederson Chiquesi") puts user end ' end end |
#create_config_yml(path) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/setupWatirCucumber.rb', line 57 def create_config_yml(path) puts "configuring cucumber.yml file" system "mkdir #{path}/config/" File.open("#{path}/config/cucumber.yml", "w+") do |f| f.write " # config/cucumber.yml ##YAML Template --- html_report: --format pretty --format html --out=features_report.html" end end |
#create_env(path) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/setupWatirCucumber.rb', line 27 def create_env(path) puts "Configuring env.rb file" File.open("#{path}/features/support/env.rb","w+") do |f| f.write "require 'setupWatirCucumber'\n\nbrowser = Watir::Browser.new :chrome\nbrowser.driver.manage.window.maximize\n\nBefore do\n @browser = browser\nend\n\nat_exit do\n browser.cookies.clear\n browser.close\nend" end end |
#create_hooks(path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/setupWatirCucumber.rb', line 35 def create_hooks(path) puts "Configuring hooks.rb file" File.open("#{path}/features/support/hooks.rb", "w+") do |f| f.write ' Before do |scenario| @path_screenshots = "screenshots/#{scenario.feature.name}/#{scenario.name}" FileUtils.mkpath @path_screenshots end AfterStep do |step| screenshot = "#{@path_screenshots}/#{Time.now.strftime("%d%m%Y%H%M")}.png" @browser.screenshot.save(screenshot) embed screenshot , "image/png" end After do |scenario| @browser.cookies.clear rescue warn "No session to clear" @browser.refresh end' end end |
#cucumber_init(path) ⇒ Object
22 23 24 25 |
# File 'lib/setupWatirCucumber.rb', line 22 def cucumber_init(path) puts "cucumber --int" system "cd #{path} && cucumber --init" end |
#init(path) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/setupWatirCucumber.rb', line 13 def init(path) cucumber_init(path) create_env(path) create_hooks(path) create_config_yml(path) create_base_scenario(path) create_base_step(path) end |