Question

My current issue only occurs when executing test from command line. When running the script from RubyMine I have no issues, from command line it looks like this

cucumber features/regression/createCloudUser.feature -r features/step_definitions/ -r lib/

Execution:

Feature: User pages Creation
  Add user to system

  Background:                   # features/regression/createUser.feature:4
Given you are in Cloud Staging # features/step_definitions/is_given_steps.rb:5
  undefined method `visit_page' for #<Object:0x007fe29cb4c798> (NoMethodError)
  ./features/step_definitions/old_pages.rb:10:in `/^you are accessing User Page$/'

it points to the following page:

#is_given_steps.rb
When(/^you are accessing User Page$/) do
  defined? $base_url
  #pry
  visit_page CreateCustomerPage   #Error is on this line unsure why?
end

Here is the class:

require 'fig_newton'
require 'page-object'

class CreateCustomerPage
  include PageObject
  include DataMagic

  page_url "https://#{FigNewton.site_url}/admin/users/new"

  text_field(:first_name, :id => 'user_first_name')
  text_field(:last_name, :id => 'user_last_name')
  text_field(:user_email, :id => 'user_email')

  button(:create_customer, :name => 'commit')
  button(:cancel, :name => 'button')


  def customerIsCreated
    raise 'User Not Created' unless browser.text.include?("#{FigNewton.customer_created.to_s.strip}")
    return true
  end

  def customerIsNotCreated
    raise 'User was Created' unless browser.text.include?("#{FigNewton.customer_no_created.to_s.strip}")
    return true
  end

  def complete_user_creation (data = { })
    populate_page_with data_for(:create_user, data)

    create_customer
  end

end

project is set up as follows:

TestProj-|
         |--Config
         |--Feature
              |--Regression
                    |-- *.features
              |--step_definitions
                    |-- is_given_steps.rb    
              |--support
                    |-- env.rb
         |--lib
              |---pages
                    |--Common
                    |--IS
                        |--*.* (other files)
                        |-- CreateCustomerPage.rb

added env.rb

#env.rb
#ADDED THIS AS TEST
$: << File.dirname(__FILE__)+'/../../lib'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../', 'lib'))

require 'rspec-expectations'
require 'page-object'
require 'selenium-webdriver'
require 'fig_newton'
require 'data_magic'
require 'require_all'
require 'time'
require 'date'
require 'yaml'
require 'fileutils'
require 'aws-sdk'

require_all 'lib'


$base_url = FigNewton.sys_url #used to parse a separate Url


World(PageObject::PageFactory)

I am not sure why visit_page would throw an error on that page. When I execute from Rubymine I have no issue and the test runs successfully. Please help.

Was it helpful?

Solution

Since you are manually requiring folders, my guess is that you are not requiring the folder that includes the env.rb.

Given the project setup, I would guess that the env.rb is in the support folder. You need to include a require for this in your Cucumber command - ie -r features/support:

cucumber features/regression/createCloudUser.feature -r features/step_definitions/ -r lib/ -r features/support

OTHER TIPS

This error

undefined method `visit_page' for # (NoMethodError)

means that you have not initialized the page where visit_page lives. You could require, or if you're doing a POM, you need to do something like this for where ever that step lives:

Given $/You are in Cloud Staging$/ do 
  @page = SomePage.new(@test_env) // initialize new object where method lives
  @page.visit_page
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top