how to update already running selenium RC test from a Java client? - java

How to approach the following scenario?
Say a test is already running in selenium rc node on a remote server using RemoteWebDriver.
The test encounters a missing element (slightest xpath change across different pages).
User provides the correct xpath for that element (this part is done in the Java application running on the user's computer) and selenium test searches for the element again and continues with rest of the test.
First thing that comes to mind is that Selenium server is using Jetty server. How would I communicate between by client java application and this server? can Jetty be ignored and somehow make the client communicate directly with the running selenium test?

When the element can not be located by a given xpath the webdriver will throw an exception which will bubble back to where you are running your test. As long as you catch this exception you will have the chance to check different xpaths.

i guess you are looking for , halt the execution in the browser and continue that execution from where ever you want (from previous statement ), instead of the browser responding back to selenium RC and to client program.
-- you want to completely stop the browser response to the request made by the selenium RC
if this is correct can you please confirm, may be i can help you.

Related

Arquillian Drone + Selenium Grid 2.0: Keep unused Browser alive

I am using Arquillian Drone + Graphene (standalone) for driving automated Browser Tests on a Selenium Grid 2.0 hosted on another machine. The tests are run via Arquillian in client mode (the server to be tested is already running)
Some of my tests require using two browsers at once, therefore i added a second Browser according to the Graphene Documentation.
So far everything is working.
The Problem:
Running a test which has both browsers injected has both of them started up before any test of the class is run. As there may be a few tests before the second browser is used, it most likely has already timed out.
Of course i could set the Selenium Grid Settings to never (or very late) close the browser via timeout, but that cannot be the solution.
Is there a way to check if the WebDriver is still up and restart it via Drone?
Without Drone i simply could check if the driver quit (e.g. like this) and create a new instance. But i want to have it injected via Drone.
In the best case i would like to be able to define when Drone should open the browser or even better keep it open until the test is finished.
If thats not possible a way to restart it would be sufficient.
I solved the Problem by directly injecting the WebDriver into the test method.
public void test(#Drone #Browser2 WebDriver webdriver){...}
I am still not completely happy with this solution but it does work.

How can I stop, or extend the browser timeout while in a breakpoint for Selenium?

When debugging a Selenium test I'll set a breakpoint, and usually run off to look at the DOM, and test xpaths. The problem is the browser times out after 90 seconds and goes away. How can I extend or disable this browser timeout so it stays open for long enough for me to do actual work in it?
I'm using the Java version of the API.
I do not want the browser to close simply because I'm sitting on a breakpoint and no commands are being sent to it.
update
we are using vaadin-testbench-standalone-4.0.3.jar hub/node scripts to run? selenium. Given comments I think this may be what's killing the browser. I see the hub output emitting this
13:58:02.152 INFO - Session 97ae07ab-ca71-4aa9-a2b1-9a75859f6c9b deleted due to client timeout

Selenium Hub incorrectly believes CLIENT_STOPPED_SESSION has happened

I am running parallel automated tests against a Selenium Grid.
Sometimes, a test with fail with;
Session [c1d99cc1-c689-4053-b68d-51c3682c13c4] was terminated due to CLIENT_STOPPED_SESSION (org.openqa.grid.common.exception.GridException)
[remote server] org.openqa.grid.internal.ActiveTestSessions(ActiveTestSessions.java):105:in `getExistingSession'
The Selenium documentation says;
CLIENT_STOPPED_SESSION The session was stopped using an ordinary call to stop/quit on the client. Why are you using it again??
However, I know that the client has not attempted to stop/quit. I am using parallel rspec so each thread is actually it's own Ruby instance, so there is no issue test side.
Also, if I directly query the Node using http://{node_ip}:5556/wd/hub/static/resource/hub.html, I can see the session is still open. If quit/stop had been issued then, this session would have been deleted.
It would appear that it is only the Session Registry in the Selenium Grid Hub that thinks this session has been stopped. There is no evidence of the session being stopped anywhere else.
Is there a known issue with Grid where the incorrect session has been marked as stopped?
Please follow the blog and try the step, and let us know if that link doesn't help
https://seleniummonk.blogspot.in/p/selenium-grid.html

For Selenium, do I need to start the java server?

$pip install selenium
$sudo apt-get install firefox xvfb
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get("http://www.yahoo.com")
This is what I have so far, for Selenium. It seems to work, except it says, "Error: no display specified"
My question is: Do I need to run the selenium jar? It doesn't seem to matter whether I run it or not...
First let me define for you client mode and server mode:
Client mode: where the language
bindings connect to the remote
instance. This is the way that the
FirefoxDriver and the RemoteWebDriver
client normally work.
Server mode:
where the language bindings are
responsible for setting up the
server, which the driver running in
the browser can connect to. The
ChromeDriver works in this way
In the current trunk all of the browsers can run in client mode although you must specify the ChromeDriver.exe path. Server mode can be used to do the same thing. You can set up the jar to run to act as a server for a particular browser. You then connect to that server. If you do this you'll see a Jetty server being set up and it handling requests. If this is not happening then you are not using server mode. As I can see from your code you are currently using client mode so there is no need to run the jar unless you want the extra remote functionality of it.
Running the jar is useful if you want to run tests on a remote machine in which case you run the jar there then connect to it from your local machine. The jar will then deal with launching browsers on the machine it is running on and forwarding actions to it.
I believe in the past with the Selenium RC API, it was necessary to always run the jar but with WebDriver this is not the case.
No, you don't need to run Selenium RC server. You can also use the Webdriver method instead, the preferred method for functional testing, which is a "direct" control of the browser as far as I can tell.
I think the server method "Selenium RC server" is more useful for load testing or multiple user testing, especially in the context of using it with Selenium Grid .

Filtering javascript XHR calls in selenium RC

I've got a mad problem with an application I test with Selenium RC
At the end of the page, several calls are made by a javascript script to an analytics webservice which takes literally minutes to respond
Selenium wait for these calls to end before going to the new page, though their response is unrelated to the good execution of the process
Eventually, Selenium throws a TimeOut Exception (timeout is set to 4 minutes)
I'm using selenium-RC 1.0.1 along with Firefox 3.5.16
First ,what I can't do :
- change the application (i have no control over it)
- change my Firefox version (several production machines are involved, and I need this version)
- using WebDriver/Selenium 2 (for the reason above)
I think that blocking javascript calls would be the thing to do, but I can't figure out How to do that.
- I'm trying, with a selenium.runScript and a selenium.getEval to set the javascript variables to null, but it's too late when they're set
- I'm using Gecko's Object.watch method to see when values are changed, but with no success
I would like to know if there is a way to filter content via Selenium before the Dom is created. I think it would be possible via a Firefox extension, but that would be the last thing I want to do
Or, perhaps it's possible to recognize all active XHR in the page and abort it
I'm open to a bunch of new ideas
Thanks for reading
Grooveek
Sorry to hear that changing the application isn't an option - when I ran into a similar situation (external analytics service called through ajax), I wrote a mock in JavaScript for the service and had the version of my application that I run unit tests against use the mock. (In that case it wasn't speed of page load we were worried about, it was junking up the analytics data with automated test runs) That allowed me to avoid hitting the external site, yet still verify in my selenium tests that I was calling the right calls in the analytics site's javascript library at the appropriate times.
What I would suggest for your case is that you write a small HTTP proxy (you may find this question's answers useful, though if I were doing it I'd do it in Perl or Python, because that's pretty fast to write) that takes requests headed out to the external site, and responds immediately with an empty document or whatever's appropriate in your situation. (but handling all requests not aimed at the analytics site normally)
In other words, don't try to prevent the javascript from executing directly or by filtering the DOM, but just intercept the slow external requests and respond quickly. I suggest this because intercepting an entire request is significantly easier than filtering content.
Then, when you start the selenium RC server, point it at your http proxy as the upstream proxy. Browsers started by the selenium server will use the RC server as their proxy, and it'll then filter everything through your proxy.
With this approach, you basically get to pretend that the external site is whatever you want.

Categories