Discussion:
[wtr-general] Watir Unit Test
江南
2018-01-12 14:33:48 UTC
Permalink
I have the code below to verify a text on the website I want to know how to
call the method '*test_verifyGmail*' in my Cucumber Step Definition file?

#!/usr/bin/ruby


require 'watir'
require 'selenium-webdriver'
require 'test/unit'
require 'rubygems'

class Login < Test::Unit::TestCase

def setup
$browser = Watir::Browser.new :chrome
$browser.goto "www.google.com"
end

def test_verifyGmail
assert($browser.text.include?("Gmail"))
end

end

Step Definition:

Given(/^I am on the login page$/) do
@login_page = Login.new
@login_page.test_verifyGmail
end


Currently when I run it will produce an error and is point at the @login_page = Login.new
ArgumentError: wrong number of arguments (given 0, expected 1..2)


Thanks
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Titus Fortner
2018-01-12 17:56:12 UTC
Permalink
Page Objects should not be subclasses of TestCase
Page Objects should not contain assertions, those belong in _step files

require 'rspec' in env.rb to use RSpec matchers:

Given(/^I am on the login page$/) do
@login_page = Login.new
expect(@login_page.gmail?).to eq true
end

def gmail?
$browser.text.include?("Gmail")
end
Post by 江南
I have the code below to verify a text on the website I want to know how to
call the method 'test_verifyGmail' in my Cucumber Step Definition file?
#!/usr/bin/ruby
require 'watir'
require 'selenium-webdriver'
require 'test/unit'
require 'rubygems'
class Login < Test::Unit::TestCase
def setup
$browser = Watir::Browser.new :chrome
$browser.goto "www.google.com"
end
def test_verifyGmail
assert($browser.text.include?("Gmail"))
end
end
Given(/^I am on the login page$/) do
@login_page = Login.new
@login_page.test_verifyGmail
end
ArgumentError: wrong number of arguments (given 0, expected 1..2)
Thanks
--
--
Before posting, please read
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
In short: search before you ask, be nice.
http://groups.google.com/group/watir-general
---
You received this message because you are subscribed to the Google Groups
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...