-2

Using: Ruby Cucumber Watir running the following Browser Stack Command line - cucumber BS_USERNAME=XXX BS_AUTHKEY=XXX SELENIUM_PLATFORM=WINDOWS SELENIUM_BROWSER=CHROME The error points to the following line -

@browser.text_field(:id => 'uname').when_present.set 'xxxxxxx'

Note:I tried appending the @browser with @element = @browser. Got the same error. The file structure in Ruby mine appears to be fine. Any insight would be greatly appreciated...

2 Answers2

2

The exception suggests that @browser is a Selenium::WebDriver::Driver. To use Watir's text_field method, @browser needs to be a Watir::Browser (or a Watir::Element).

You are likely opening the browser with a line like:

@browser = Selenium::WebDriver.for :chrome

However, to use Watir, the browser should be opened like:

@browser = Watir::Browser.new :chrome
Justin Ko
  • 44,820
  • 5
  • 82
  • 95
  • Thanks for the feedback .... made the stated change. I am now using @browser - Watir::Browser.new :chrome. I now have the error : uninitialized constant Watir (NameError). I made the change in the env.rb and step def .rb file / – kclarke Jan 25 '17 at 16:31
  • It sounds like you are missing a `require 'watir'`. Is this a brand new Cucumber test suite or are you trying to migrate an existing Selenium one to Watir? – Justin Ko Jan 25 '17 at 17:21
  • I am trying to migrate Selenium to waiter – kclarke Jan 25 '17 at 20:13
  • I added the require watir as well as other required gems. error:uninitialized constant Watir::WebDriver (NameError) .is there a way to upload myenv.rb and step file to this discussion ? I don't see that feature on Stack over flow – kclarke Jan 25 '17 at 20:24
  • You can just edit the question to include the relevant code. Note that you just need to provide enough code to reproduce the problem. – Justin Ko Jan 25 '17 at 21:16
0

As mentioned by Justin, you're using method text_field which is not available in selenium webdriver. Use below code to make this work:

require 'watir-webdriver'
@browser = Watir::Browser.new :chrome
yudi2312
  • 313
  • 3
  • 19
  • Thanks for your response. I need to convert the ruby selenium to ruby watir-webdriver as you mentions. I changed the notation from Selenium::Webdrive to Watir Webdrive in my env.rb file ......... as provided below – kclarke Feb 01 '17 at 18:23
  • My cucumber Step def looks like this ..@browser.goto "https://multi-tenant-dev-1.gridasaservice.com/login?timeout=true" – kclarke Feb 01 '17 at 18:26
  • The command line that executes the script Browser ...cucumber BS_USERNAME=kevinclarke2 BS_AUTHKEY=5AyLAPWXEESrJLd3kCM9 SELENIUM_PLATFORM=WINDOWS SELENIUM_BROWSER=CHROME – kclarke Feb 01 '17 at 18:28
  • Watir-webdriver is amog the installed gems in the project. – kclarke Feb 01 '17 at 18:31
  • Watir-Webdriver has been moved to Watir. There should be no reason to be using Watir-Webdriver. – Justin Ko Feb 01 '17 at 18:50
  • 1
    just include code present in your env.rb file in the question. – yudi2312 Feb 01 '17 at 19:01