Testing with Webdriver with remote HTMLUnit having gmail login issues

For some reason, after entering a site like gmail, htmlunit does not work. It cannot find html elements.

Below is a very simple ruby ​​script that shows the problem, note that it is assumed that the webdriver server is running on the same computer on which it is running:

require 'rubygems'
require 'watir-webdriver'
require 'rspec/expectations'

##
## THE FOLLOWING TWO WAYS WORK
#
#browser = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => :firefox)
#browser = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => :internet_explorer)

##
## THIS WAY FAILS
##
capabilities = Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true)
browser = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)

#Login to gmail
browser.goto "http://gmail.com"
browser.text_field(:id,'Email').set 'roberttestingstuff041'
browser.text_field(:id,'Passwd').set 'k4238chsj55983w'
browser.button(:id,'signIn').click

sleep 5.0  #sleep shouldnt be needed, but just to be sure we are waiting long enough for log in to complete

frame = browser.frame(:id,'canvas_frame')
#It fails on the next line when using htmlunit
frame.link(:text, 'Sign out').exist?.should == true
frame.link(:text, 'Sign out').visible?.should == true
frame.div(:id, 'guser').exist?.should == true
frame.div(:text,'Compose mail').exist?.should == true

Please note: if I create a browser object using firefox or IE, this simple test works.

It seems to be stuck on redirects that occur during the login process. The site I'm really trying to check follows a very similar pattern, so I installed this simplified example using gmail, which seems to show the same problem.

- ? , Celerity, HTMLUnit, , - ?

, webdriver, , :

12:31:16.321 INFO - WebDriver remote server: INFO: Executing: [find element: By.xpath: .//a[normalize-space()='Sign out'
] at URL: /session/1297704604365/element)
12:31:17.996 WARN - WebDriver remote server: WARN:
org.openqa.selenium.NoSuchElementException: Unable to locate a node using .//a[normalize-space()='Sign out']
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_21'
Driver info: driver.version: EventFiringWebDriver
        at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByXPath(HtmlUnitDriver.java:699)
        at org.openqa.selenium.By$6.findElement(By.java:205)
        at org.openqa.selenium.htmlunit.HtmlUnitDriver$4.call(HtmlUnitDriver.java:1133)
+3
2

, Gmail ( HtmlUnit Rhino) JavaScript.

Gmail

 browser.button(:id,'signIn').click

, "JavaScript "

p browser.text
 "<style> #loading {display:none} </style> <font face=arial>JavaScript must be enabled in order for you to use Gmail in standard view. However, it seems JavaScript is either disabled or not supported by your browser. To use standard view, enable JavaScript by changing your browser options, then <a href=\"\">try again</a>. <p>To use Gmail basic HTML view, which does not require JavaScript, <a href=\"?ui=html&zy=c\">click here</a>.</p></font><p><font face=arial>If you want to view Gmail on a mobile phone or similar device <a href=\"?ui=mobile&zyp=c\">click here</a>.</font></p> \n Loading tim.koops@gmail.com\342\200\246 \n\n\n\n Loading standard view | Load basic HTML (for slow connections)"

Gmail HTML, , , , , . webdriver .

, , Gmail!

+3

javascript HtmlUnit. . HTMLUNITWITHJS HTMLUNIT. Python, , Ruby - .

0

Source: https://habr.com/ru/post/1792057/


All Articles