I'm building a distributed system with websockets. Browser clients can connect to each other directly or to a central server. I would like to test a few distributed use cases end-to-end.
Example 1:
Open Browser A and connect to my site
Open Browser B and connect to my site
Browser A sends a chat message to Browser B
Confirm that Browser B received the message
Example 2:
Open Browser A and connect to my site
Open Browser B and connect to my site
Browser A sends a chat message to Browser B
On Browser B, a "disconnect" button is clicked
Confirm that Browser B does not receive the message
On Browser B, a "reconnect" button is clicked
Confirm that Browser A received the message
How can I do this? I've seen selenium running in parallel, but I haven't seen anything that allows you to coordinate the interaction between browsers.
Your test can open many webdriver instances.
If you open 2 instances in your test, one can represent browser A and the other browser B.
Call methods on these objects to simulate the scenario you discuss in your post.
To achieve this you need to use RemoteWebDriver. If all hosted locally, you will get two unconnected browsers on your computer. If you use a Grid, then you will get 2 browsers somewhere on your grid, probably on different machines.
If you want complete control, you could just start Selenium instances on two remote machines and use these hard coded machine names for A and B. In this scenario there would be no Grid.
Word of warning though. If you try to host all browsers locally, you cannot use IE as multiple IE all share common data where as Chrome are completely separate
Related
I'm trying to understand the performance impacts of things like WebDriver.findBy(...). For example if I was using Selenium to drive a local Chrome instance:
WebElement betty = webDriver.findBy(By.id("betty"));
Does the Selenium library
a) have the DOM within the JVM to evaluate?
b) go to the local Chrome driver binary to evaluate?
c) go to the browser instance to evaluate?
And does the answer change for a Grid situation?
I found a nice technical guide that explains this.
The browser driver uses an HTTP SERVER which waits continuously for
new Selenium commands.
It has the following purposes:
read HTTP requests coming from the client (client = computer that executes the test automation scripts)
determines the series of steps needed for implementing the Selenium command
sends the implementation steps to the browser
gets the execution status from the browser
send the execution status back to the client
For each Selenium command of the automation script, a http request with a specific path is created.
When the automation script is executed, the first http request generates a new session that is specific to the browser where the automation scripts run.
The session id will be used for the http requests that correspond to all other
Selenium commands from the automation script.
I was asked a question :
Assume I have 4 machines and I need to execute a script in all the machines across all the browsers. How will I achieve that.
I told him the concept of Selenium Grid, where in we could set up a machine which acts like a hub, configure 3 more machines which would act like a node.
Using Desired Capabilities among others we could choose a browser type and version type in that and write a script.
But he asked me two things :
IN all the node machines how do you configure the Windows username and Password if the machine is locked. Can you write windows Authentication in the script.
Can I achieve testing different browser versions of same browser type in a single node?
Can I pass as a the browser type and browser version as a parameter
from hub to the node?
Can someone throw some light on these as I was unable to answer. Thanks.
Question 1: Is it really necessary for the machine to be unlocked for the test to start? The selenium node is a background process that listens for commands, and executes them on the browser, so I do not think this is necessary. If it is necessary due to your specific windows settings however, then no, you cannot do this from the selenium script obviously.
Question 2: Yes, you can test different browser versions of the same type on the same node. You can pass the browser name and version to the node. However, keep in mind that the node cannot know the location of the different browser versions, so you will also have to supply the path to the browser executable for your requested version
We have are planning to design a system where we are planning to invoke the Selenium test that is present in a remote machine with url for testing. The selenium program should open 3 browsers for example IE, FF and Chrome and open the page and take a screenshot of it. Later These screenshots should be sent from this machine to the java application.
Is it possible to achieve this functionality ? If so could you please guide me on how to do this ?
Yes, you need to start a Selenium Grid/Node server on the remote machine that is configured to run all 3 browser types. That configuration isn't easy but it involves launching the grid from a .json config file. Then, your local program needs to just run the 3 tests either in 3 simultaneous threads, or one at a time using typical Selenium code.
Each test needs to define a Selenium Augmenter to get screenshots. There are lots of examples on Google.
I'm trying to test a scenario where two separate users are logged in. As the question states, is this possible with Selenium? I don't if it's browser dependent, but I'm using Chrome.
Selenium (web driver) allows to open several browser windows (e.g. 3 Firefox windows or 1 IE + 1 Firefox +1 Chrome).
In you code you have API to select the desired window (depending how on how you opened it).
Regarding the session handling: that depends on the browser type. Firefox will share the session across multiple windows because it's using a single process. AFAIK IE and Chrome if opened as new processes will not share it, but this of course depends also on how the server is setting the cookie policy for the session.
Access to cookie values in the browser however is domain dependent, so a persistent cookies or local storage can share information even across sessions, so it really depends on how the web application is implemented (or what framework is using - that mostly takes care of such stuff).
If you want complete separation, then take a look at Selenium Grid;https://code.google.com/p/selenium/wiki/Grid2
This would allow you to have the browsers open on different computers while running the test on one machine
We have pages where we occasionally see compromised SSL certificate because of third party scripts that load non HTTPS resources (Initially they're fine but they occasionally change). We would like to test those pages for broken SSL every day.
We have tried one approach, attempting to catch a pop-up message that would indicate that we have insecure content on the page. However, we have been unsuccessful in simulating the pop-up message through selenium. It appears that selenium has automatically disabled any popups. While we have identified a Selenium method to disable the suppression of the pop-ups(disable-popup-handler) but we have not been able to successfully see the popup even using this method.
Has anyone found a way to detect broken SSL pages using Selenium?
You need to load a browser profile (with WebDriver) that doesn't have the setting for popup blocker enabled (using the Profile class and giving it the right properties). Then, you will get the Windows popup message concerning the SSL cert. If , for some reason, you cannot control the popup using WebDriver (because its limited to Action control only within the browser content window) then you can use Sikuli API to handle the dialog and export the cert to the "Downloads" dir and then copy the file to expected location for inspection. Unfortunately, if you use Sikuli, that will make your automation script sequential and not work via a RemoteWebDriver grid server and so you wont be able to run parallel tests. Hopfully, WebDriver gives you access to the dialog and so you will be able to run with RemoteWebDriver because that is the best way to go when running scripts, even if you run a browser locally.