Hi all, I am trying to write some code to log into an app via a pop-up window and then click some tabs inside it. However, when I try to encapsulate the login logic into a method, I get an error on console. I am pasting my code below followed by the console error. Any suggestions as to what I'm doing wrong? (I am using wait_until because my text verification fails as page has not loaded yet).
require 'watir' require 'watir/WindowHelper' require 'watir/testcase' include Watir class TC_MTests < Watir::TestCase #Variables @url = 'https://1.2.3.4/' @login_title = 'Connect to' @username = 'abc' @password = '123' #Start browser @ie = Watir::IE.start(test_site = @url) #If prompted about the security certificate, click to bypass certification if @ie.contains_text("Continue to this website (not recommended).") @ie.link(:text, 'Continue to this website (not recommended).').click_no_wait puts "Bypasses the security certificate warning for now." end def test_Login #Use autoit to work with the authentication popup #Pauses execution of the script until the requested window exists Watir.autoit.WinWait(@login_title) Watir.autoit.Send(@username) Watir.autoit.Send('{tab}') Watir.autoit.Send(@password) Watir.autoit.Send('{enter}') puts "Login window pop-up appears and credentials passed." #Wait until landing page has loaded completely wait_until [EMAIL PROTECTED]@username} #Check if correct user has logged in if @ie.contains_text("Logged in as: " [EMAIL PROTECTED]) puts "Test passed. User '" [EMAIL PROTECTED] +"' has logged in." else puts "Test failed. Login fails or incorrect user has logged in " end #End of method end #End of class end ------------------------------------------------------------------------------------------------------------------------------------------------------ I get the following error on console: P:\>ruby c:\ruby\tests\IanTests_temp.rb Bypasses the security certificate warning for now. Loaded suite c:/ruby/tests/IanTests_temp Started Login window pop-up appears and credentials passed. E Finished in 0.297 seconds. 1) Error: test_Login(TC_MTests): NoMethodError: undefined method `text' for nil:NilClass c:/ruby/tests/IanTests_temp.rb:37:in `test_Login' c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.6/./watir.rb:110:in `wait_until' c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.6/./watir/waiter.rb:76:in `wait_unt il' c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.6/./watir/waiter.rb:53:in `wait_unt il' c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.6/./watir/waiter.rb:76:in `wait_unt il' c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.6/./watir.rb:110:in `wait_until' c:/ruby/tests/IanTests_temp.rb:37:in `test_Login' 1 tests, 0 assertions, 0 failures, 1 errors _______________________________________________________________________________ Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Watir General" group. To post to this group, send email to [email protected] Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/watir-general -~----------~----~----~----~------~----~------~--~---
