我的当前问题仅在从命令行执行测试时发生。从rubymine运行脚本时,我没有问题,从命令行,它看起来像
cucumber功能/回归/createclouduser.feature -r功能/step_definitions/-r lib/p>
执行:
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$/'
它指向以下页面:
#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
这是类:
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
项目设置如下:
TestProj-|
|--Config
|--Feature
|--Regression
|-- *.features
|--step_definitions
|-- is_given_steps.rb
|--support
|-- env.rb
|--lib
|---pages
|--Common
|--IS
|--*.* (other files)
|-- CreateCustomerPage.rb
添加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)
我不确定为什么visit_page会在该页面上丢失错误。当我从Rubymine执行时,我没有问题,测试成功进行。请帮助。
由于您是手动需要文件夹,我的猜测是您不需要包含env.rb
的文件夹。
给定项目设置,我想env.rb
在support
文件夹中。您需要在Cucumber命令中包含此要求-IE -r features/support
:
cucumber features/regression/createCloudUser.feature -r features/step_definitions/ -r lib/ -r features/support
此错误
未定义的方法`wist_page'for#(nomethoderror)
意味着您尚未初始化visit_page寿命的页面。您可能需要,或者如果您在做POM,则需要为此步骤做这样的事情:
Given $/You are in Cloud Staging$/ do
@page = SomePage.new(@test_env) // initialize new object where method lives
@page.visit_page
end