I am new to PageObject (and ruby)...
I am having issues handling the Alert popup when user ID is not provided.
Here is the code and scenario:
When I click 'sign in' button without user ID then I am expecting an alert with a message, which I am verifying in my script.
currently I get an error:
NoMethodError: undefined method
alert' for nil:NilClass`
cucumber Then statement: Then I should see an popup message 'enter card number'
step definition: `
Then(/^I should see an popup message "([^"]*)"$/) do |popup_msg|
on(LoginPage).alert_msg
end
***Page object code:***
class LoginPage
require_relative 'common'
include PageObject
include Common
text_field(:collector, :id => 'j_col')
text_field(:password, :id => 'j_password1')
button(:sign_in, :value => 'Sign in')
def login_to_nectar (collector = FigNewton.collector.colid, password = FigNewton.collector.password)
self.collector = collector
self.password = password
sign_in
end
span(:pwd_error_msg, :css => 'p.error-message')
def alert_msg
message = @curr_page.alert do
sign_in.click
end
message.should == 'enter card numbe'
@alert_msg
end
end
`
....LATEST INFO....progress
@Johnson thanks...now I am getting the error:
Selenium::WebDriver::Error::UnhandledAlertError: Modal dialog present: "enter card number. "
I can see that PageObject is handling the popup. My new code below:
def alert_msg
alert do
self.sign_in.click
end
@alert_msg
end
I call this in step definition in the step before verifying the message as so....
When(***without a card number$/) do
on(HomePage).click_login
on(LoginPage).login_to_nectar('', FigNewton.collector.password)
@current_page.**alert_msg**
end
Then***
on(LoginPage).**alert_msg**.should == popup_msg
end