How to find out difference behavior between chrome driver and phantomjs - ruby

When I want to have automated browser function with selenium-webdriver, I write at first with chrome driver and then make it run with phantomjs.
But sometimes the two browsers behave differently and the function fails to run with phantomjs while selenium-webdriver works fine.
Currently, to find out what is wrong I am struggling in command line. I wonder if there is a way to run phantomjs with "head" so that I can see the problem at a glance. Or maybe is there way to make chrome behave exactly like phantomjs?
I'm aware of some web site are restricted to get information by headless server, I'd give up in that case.

I faced with the same situation a time ago. In that case I used this gem to take a screenshot on each capybara failure. It doesn't answer to you what has exactly happened, but at least you can find out if page has required elements and so on.

Related

Ruby/Tk in a browser

Is there a quick and easy way to make a ruby/Tk script run in a browser? I wrote a handy-dandy little ruby/tk script to do stuff. A friend saw it and said that his friends would love to use it, but they are extremely non-technical and cannot handle installing ruby (even though I showed him how simple it is). What he wants is for me to give him a link that someone can click on a browser and magically make the tool run.
I've looked around and get the impression that it cannot be done. 'it just does not work that way'. But I have not seen a clear 'NO' . I see things on how to get ruby to run in a browser, but not the Tk part. I also looked at rubyscript2exe but get the impression that it was abandoned.
No, you can't directly run Ruby in the browser like that.
There are websites such as RubyFiddle which let you run short snippets. What they're actually doing is executing the code remotely then displaying the result.
Because this code is actually being executed remotely, there's no way of running something interactive (like a TK UI) with it. There are some services which give you a hosted Ruby environment with working Terminal, but even these aren't going to work with a TK UI.
This section of Ruby Gems https://www.ruby-toolbox.com/categories/packaging_to_executables has a good list of all the tools available to package Ruby apps for distribution though, so you might be able to send them a simple installer to allow them to use it locally?
I've had a lot of success doing this with https://github.com/larsch/ocra/ which is actively maintained.

Watir Webdriver Detection

Is there a way to detect whether someone is conducting web testing using watir-webdriver on your site? I have read somewhere that it is fairly easy to detect watir/selenium, but I never managed to get more details about it.
I have tried UserAgent detection, but that's not something very useful as far as it's easy to change it.
Right, I will make my comments into an answer as requested.
I doubt if it's possible. The idea of Selenium is to automate browsers by simulating actions like real users. You can't possibly detect it from server side, unless Selenium fails to simulate (e.g. click really fast, but if the Selenium code is written deliberately to simulate a real user in a slow fashion, then I'd say it will be difficult to detect).
On the other hand, User Agent approach won't work if someone runs it using common browsers with default UA.

Selenium hanging and timing out on basic page interactions on OWA.

I'm using Selenium with a local FireFox browser to access live.com's spam box and read the email. For testing purposes, I've been using "binding.pry" to interact with my script and see where the problems are.
When I try to find the element representing an inbox message:
driver.find_element(:css,"#messageListContentContainer .ia_hc")
I get this error after 60 seconds:
Timeout::Error: execution expired
from /usr/lib/ruby/1.8/timeout.rb:64:in `rbuf_fill'
But, as I'm in Pry, I can quickly repeat the same command. After about 5 or 10 seconds, it finds the element.
Obviously I can get around the problem by putting a before, rescue, retry block around the call, but that means I'll have to wait 70-80 seconds to click a single email. Does anyone have any idea why find_element is taking so long that it times out, or why it doesn't time out the second time? Is it because the live.com (called "Outlook Mail" on the website) has a huge ammount of elements to search through? Is it something with the JavaScript they are using?
I've been able to duplicate this issue with both Firefox and PhantomJS
UPDATE:: I've found this is happening with all of the calls after any page refresh. I can call driver.page_source and I have the same problem. It seems selenium can't interact with the browser for a certain period of time after the page has refreshed. Could it be that selenium is having trouble reading everything off of the web page?
I have seen this happen in my own tests, but on an intermittent basis, and never completely reproducible. What seems to happen is that Selenium WebDriver just becomes blocked and unresponsive.
I know that I have just had to resort to rescuing the error, logging, and retrying in my code. After a few retrys, Selenium WebDriver seems to become responsive again and I'm able to continue on in my tests from there.
I have contacted the maintainer of the Ruby WebDriver gem, and he needs a reproducible test to be able to do some solid debugging. If you are able to provide a reproducible test case, please share it with us so that we can look into this issue. You can use this gist as a starting point to share with the community.
The problem just magically disappeared. It's not happening anymore and I can't duplicate it. Best of luck to the selenium crew finding it, it seems to come and go randomly.

How to change Opera's proxy settings from Watir-Webdriver?

(This question is loosely related to my previous question)
Hello there.
I have been using Watir-Webdriver with Mozilla FireFox for a week now, and I am quite pleased with it. However, since I am making a test wich tries to connect to some websites multiple times using different proxies, I found that using FireFox was extremely slow. Firefox's starting time is (at least on my computer) about 15 seconds(if you're lucky) so I am looking to find something to speed the thing up. This made me look into other browsers and their start up times. It seems Opera is quite fast. However, since it is 'new' in Selenium Webdriver and thus also in Watir-webdriver there is not much documentation about it.
Enough talking, time for the question:
How can I, using watir-webdriver(or Selenium-webdriver directly), change the proxy that Opera uses for connections?
I'm not quite sure I understand the use case, but as a hack/workaround you can change any Opera setting from OperaWatir by loading opera:config and running JS in it to set preferences. In other words,
browser.goto('opera:config')
browser.execute_script( 'opera.setPreference("Proxy", "HTTP Server", "127.0.0.1:8888")' )
browser.execute_script( 'opera.setPreference("Proxy", "Use HTTP", "1")' )
should work without restart or anything. The opera:config page itself shows you the options you can set.

Is there something similar to the selenium grid when using cucumber/capybara?

So I'm trying to get an environment set up that acts like a selenium grid in that:
1) It runs the tests in parallel across a distributed set of clients
2) I can specify tests to run on specific clients (which are running on different OS's, with different browsers), or tests to run once on all the clients or any combination thereof.
The problem is that capybara actually currently uses WebDriver, not selenium, so as far as I know I can't specify a selenium grid for the tests to hook up to and have it work.
I've looked into things such as DeepTest and Testjour, but neither scratches both itches above. I'd love for there to be a way I can tag a cucumber feature with what browsers I want it run on, and it just does it, like selenium grid currently does. Is there an easy way I can do this without a lot of hackery on my part, or do I need to wait for Selenium 2 to be released?
Oh and I should add I've love to keep capybara's ability to swap out web drivers at will - running on selenium (or WebDriver I guess I should say), htmlunit, etc.
There is currently a version of grid for webdriver under development.
You can find info about it here
So one potential solution I'm digging into here is Hydra. It seems to work for parallel execution of cucumber scenarios across multiple machines simply using ssh, thus scratching itch #1 above. I've set it up and have it running properly on two macs and a windows VM, and things are running smoothly. However, itch #2 remains unscratched. So I forked it, and my first pass is to simply set up a way to run all features on all machines in a parallel manner, ensuring that all features get tested on every supported browser we have. My next pass may be to hack in a way to to be able to specify which features run on which machines, if time permits and the need is great enough. We'll see how it goes.

Resources