我的当前问题仅在从命令行执行测试时发生。从RubyMine运行脚本时,我没有任何问题,从命令行看起来像这样
黄瓜功能/回归/ createCloudUser.feature -r features / step_definitions / -r lib /
执行:
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执行时,我没有问题,测试成功运行。请帮忙。
答案 0 :(得分:2)
由于您手动要求文件夹,我猜您不需要包含env.rb
的文件夹。
鉴于项目设置,我猜测env.rb
位于support
文件夹中。您需要在Cucumber命令中包含此要求 - 即-r features/support
:
cucumber features/regression/createCloudUser.feature -r features/step_definitions/ -r lib/ -r features/support
答案 1 :(得分:1)
此错误
#(NoMethodError)的未定义方法`visit_page'
表示您尚未初始化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