2014-09-29 13 views
0

我是新來PageObject(和紅寶石)...PageObject寶石 - 警報彈出不被處理

我有當沒有提供用戶ID處理警報彈出的問題。

下面是代碼和情景:

當我點擊,而無需用戶ID,然後我期待有一個消息,我在我的劇本我驗證警報按鈕「符號」。

目前我得到一個錯誤: NoMethodError: undefined method警報」的零:NilClass`

黃瓜然後聲明: 然後我看到一個彈出消息 '輸入卡號'

步驟定義: `

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 

`

....最新信息....進步

@Johnson感謝...我現在得到的錯誤:

Selenium::WebDriver::Error::UnhandledAlertError: Modal dialog present: "enter card number. " 

我可以看到PageObject正在處理彈出窗口。我下面的新代碼:

def alert_msg 
    alert do 
     self.sign_in.click 
    end 
    @alert_msg 
end 

我在步驟驗證消息使之前調用此步驟定義....

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 
+0

約翰遜感謝指向我在正確的方向......但是現在我收到以下錯誤: – Asif 2014-09-30 07:40:34

+0

現在問題的答案是?我不清楚身份是什麼。 – 2014-10-01 22:51:34

+0

是的,這是...在我做了最初的改變之後,得到了模態相關的錯誤。我在我的頁面類中實現了我的login_to_nectar方法調用了'sign_in'元素,因此實際上這被調用了兩次(第二次在alert_msg方法中)。我把它從'login_to_nectar方法中解放出來,一切正常。 – Asif 2014-10-03 08:13:19

回答

0

我做了最初的改變並且得到了模態相關的錯誤。我在我的頁面類中實現了我的login_to_nectar方法調用了'sign_in'元素,因此實際上這被調用了兩次(第二次在alert_msg方法中)。我把它從'login_to_nectar方法中解放出來,一切正常。謝謝..

1

錯誤消息NoMethodError: undefined method 'alert' for nil:NilClass意味着你@curr_page是零,因而沒有定義的#alert方法。看看你在哪裏定義這個實例變量。這是罪魁禍首。

+0

約翰遜感謝您指點正確的方向...... – Asif 2014-09-30 07:39:10