Timeout error while using watir webdriver with Ruby - ruby-on-rails

I am new to watir webdriver with ruby and I am trying out a few examples. I am getting a timeout error "Net::ReadTimeout: Net::ReadTimeout" for the following code -
b = Watir::Browser.new
b.goto "http://www.quora.com"
b.text_field(:name => 'email').set 'someone#gmail.com'
b.text_field(:name => 'password').set 'somepassword'
b.button(:class => 'submit_button').click
When I run the above code in console, firefox gets launched and quora main page comes up. But after that it doesn't do anything until it times out. I inspected the elements for username and password and they are right.
I ran the same code for gmail.com with the corresponding fields and it runs just fine.
Can someone please help?
Ameya

This is a known issue with quora.com.
Currently I'm not aware of any solutions, one possibility is to disable JavaScript when you login, but in this case you can't do much else after login. Maybe you can create a ticket in Selenium issue tracker.
See similar questions asked before.
Selenium code doesn't terminate
Why am I not able to login to Quora using an automation package like Selenium or Watir?
How to add JS on a page when it has been turned off initially by Selenium?
Is Selenium slow, or is my code wrong?

Related

Running Capybara tests against Internet Explorer via Browserstack

I have a Rails app with a suite of Cucumber tests that run via Capybara on a headless Chrome browser. I'd like to find a way of running these tests (or at least a subset of them) on IE11, and have turned to Browserstack as it seems they offer the means to do this.
I've successfully configured Browserstack to tunnel into my machine and run my tests but they fail on the one browser I care about - IE11.
My suite is currently falling over at the login page. I'm able to do a screenshot and establish that the page is in fact rendered. I'm able to execute:
fill_in 'Email', with: 'mr.jones#example.com'
without error, although a screenshot then shows nothing to have been filled in. Executing
click_on 'Sign in'
yields:
'Selenium::WebDriver::Error::ElementNotInteractableError: Received a JavaScript error
attempting to click on the element using synthetic events. We are assuming this is
because the element isn't displayed, but it may be due to other problems with executing
JavaScript.'
I briefly experimented with send_keys to try and fill in the form, but to no avail. In short, it seems I can navigate to pages and find elements, but I can't interact with them.
Does anyone know of a way to achieve what I'm attempting here? I'm hoping there's e.g. some setting on the driver that will make it work.
I only need to be able to test a few key workflows against IE, so even if a radically different approach is needed in my testing, I won't need to rewrite the entire suite.
Here is my current Capybara configuration:
caps = Selenium::WebDriver::Remote::Capabilities.new
caps['browser'] = 'IE'
caps['browser_version'] = '11.0'
caps['os'] = 'Windows'
caps['os_version'] = '10'
caps['resolution'] = '1024x768'
caps['browserstack.local'] = 'true'
Capybara.register_driver :browserstack_ie do |app|
Capybara::Selenium::Driver.new(
app,
:browser => :remote,
:url => "http://#{ENV['BROWSERSTACK_USER']}:#{ENV['BROWSERSTACK_KEY']}#hub-cloud.browserstack.com/wd/hub",
:desired_capabilities => caps
)
end
Capybara.javascript_driver = :browserstack_ie
UPDATE:
I found some useful information here
It sounds like the issue may be that Selenium is clicking in the wrong place, and that it can be fixed by changing the zoom settings in IE. Not clear to me how I would do this on a browser running in Browserstack though.
I also discovered my Browserstack subscription doesn't support more than 100 minutes of automated testing time per month, which was a bit of a blow, so I can't immediately do anything further with this.
I think I may end up running my own IE instance on a Windows machine on my local network and hook my tests up to that instead. I will update this card if/when I discover anything useful.
Finally, I'd invite anyone who reads this to consider how many hours of their life they have wasted on supporting the many incarnations of IE. It is a blight upon the industry and Microsoft should be ashamed of it.

How to perform ctrl+j in ruby for chrome browser. I am using RubyMine and WatirWebdriver

Tried below code to click ctrl+J but did not work for chrome browser.
#browser.driver.action.key_down(:control).send_keys("j").key_up(:control).perform
Also tried
#browser.driver.action.send_keys(:control,"J").perform
I read in one blog, above code would work for Firefox browser but not for Chrome.
First off,
The way you send control+j is wrong. The way to send the control+j is,you have to give control+k inside the [] like [:control,"j]
b.send_keys([:control,"j"])
Second off,
it's not possible to send the [:control,"j] via chromedriver because of the following issue
https://bugs.chromium.org/p/chromedriver/issues/detail?id=903
The exact answer lies here
This is a limitation in the way we simulate keyboard input in ChromeDriver. Keys get sent directly to the render process, bypassing the browser process. So any keyboard shortcut handlers in the browser process will not be invoked by sendKeys().

Websites detecting and blocking Selenium Chromedriver

I got a task to update a URL in a test (using Selenium, Java and Chromedriver) to a new URL. The page is the same, just at a new location. This test worked fine with the old URL.
I brought up an instance of Chrome and verified I could access the URL.
Then I changed the URL, committed to git, and ran on our Jenkins machine and it failed. The screenshot said "This site can’t be reached". I told a co-worker that I think the URL must be wrong (though it worked on my desktop without Selenium). He tried it and it loaded fine. I tried it again from a regular Chrome window and it loaded fine. I tried from Eclipse using Selenium and I got the message about the site could not be accessed.
So I ran Eclipse, stopped it right when Chrome came up but hadn't loaded a URL yet. I manually entered the URL (from copy/paste) and got "This site cannot be accessed). Then I brought up a regular Chrome window and pasted the URL in and it loaded fine.
I decided to look for differences. So in my regular Chrome window it was "Version 77.0.3865.120 (Official Build) (64-bit)". I did the same on the version running under Chromedriver and got "Version 77.0.3865.120 (Official Build) (64-bit)". So the same.
I did a search for the latest Chromedriver. It said for version 77 to please use 77.0.3865.40. This was not what I was using. So I downloaded the correct version and thought "surely this will fix it". I verified it was 77.0.3865.40 coming up. But, as you guessed it, I got the same problem after updating to the most compatible Chromedriver.
Some searches said that basically nothing would be able to tell, but there was one property that Chromedriver inserts. I don't know whether this would be enough to block a session using Chromedriver?
The only thing I can think of is that we have iBoss and possibly iBoss is blocking it? Either that or somehow the site is blocking it.
I would like to share the URL with you but I do not know whether that would be violating company policy. If I get permission, I will share the URLs.
by the way, the error is "ERR TUNNEL CONNECTION FAILED"
Got some internal help to help fix some settings

TestCafe: Clicking SSL link does not load page

In a test, I click a link (SSL Cert) link that does not actually load the expected URL page. It hangs and as far as I can tell no issues when I look at network or console. Is there a known issue with TestCafe and clicking certain kinds of links. Clicking the same link with Selenium and Robot Framework successfully takes you to the expected URL.
This information is not sufficient to reproduce the problem. Please create a separate issue in the TestCafe Github repository using the following form
I would appreciate it if you provide us with your project or url to your site and your test code. It will help us determine the cause of the issue efficiently.

Ruby - Form doesn't submit to the right page in Selenium-Webdriver

I am attempting to write some automated tests for a client my company has been working for. One of these tests is to have Selenium-WebDriver enter a username and password and login. When I do that manually as a human user, I get redirected to the right page (the base url page) and get logged in successfully. However, if I have Selenium-WebDriver do it, the page gets redirected to /users/:id and a 404 error occurs.
I have pasted the code in its most basic form below. I think the issue is due to page redirects but I can't be sure. (This is a rails project, the automated test is external.) I have tried adding delays, I've tried adding waits, and I've even tried slowing WebDriver down to solve this issue. Nothing seems to work. I don't know how to add a wait directly into the click function of the submit button. If anyone has any further ideas, that would be great.
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
driver.navigate.to ''
driver.find_element(:id, 'user_email').send_keys ''
driver.find_element(:id, 'user_password').send_keys ''
driver.find_element(:name, 'commit').click
sleep 5 # this is so my eyes have time to see if it worked
driver.quit
Thanks in advance!
It looks like it's a browser thing. It works in some browsers, but not others.
Thank you for your thoughts!

Resources