Selenium grid2: how to close and open browser on remote - selenium

I have a test where I need to do a login, close browser and open it again then check something on the page.
How can I do this when running webdriver with remote hub setup? or do i have to run this without remote?
Test is something like this:
Open browser
Login
Close browser
Open browser again
Check login is remembered

The process to accomplish this is going to be very similar to that of a solution in a non-grid environment. Note that the following code is written for Java, but I can't imagine C# being much different.
WebDriver driver = new RemoteWebDriver("hubURL", desiredCapabilities);
driver.manage().deleteAllCookies();
driver.get("http://path/to/page");
//login to application
driver.quit(); //This will close the browser on the remote machine
//Now to try it again
driver = new RemoteWebDriver("hubURL", desiredCapabilities);
driver.get("http://path/to/page");
Assert.assertTrue(some element that is not on the login page but is on the page after is present);
driver.quit();

Presumably you're testing some cookie stuff. Unfortunately, there's no guarantee any particular node will execute any request, unless you constrain it properly. You need to have a node advertise a unique capability that the client then requests, ensuring the hub will route to that node every time. But, naturally, if that node goes down, you won't have any others that could service the request.

Related

Selenium browser persists after a test is finished

I am using Firefox and the Selenium IDE plugin. I have a test for the login of my application. After the end of the test the browser stays logged in and the session gets reused. Can this be avoided ?
You need to invoke driver.quit() method within the tearDown() {}. Invoking quit() DELETEs the current browsing session through sending "quit" command with {"flags":["eForceQuit"]} and finally sends the GET request on /shutdown EndPoint.
References
You can find a couple of relevant detailed discussions in:
Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?
PhantomJS web driver stays in memory

Where does Selenium store the DOM, if at all?

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.

How to Force Selenium Webdriver to Use and Keep Cookies?

I'm testing a website which uses cookies for security. Every time a user logs in with a different device or browser they must go through an intensive (email and phone keys) identity verification process. My backup/restore process uses a Firefox addon and works for manual testing.
However when I run Selenium I get triggered to go through the ID process every time. So either Selenium is not using the cookies, or is being given a different browser ID for some reason.
I set a breakpoint to check my cookies are loaded in the Selenium Firefox browser window, but my addon is not available in Selenium Firefox instances.
Selenium documentation is very slim on cookie use:
http://www.seleniumhq.org/docs/03_webdriver.jsp
So any info much appreciated.

Selenium Golang binding without server

There are many selenium webdriver binding package of Golang.
However, I don't want to control browser throught server.
How can I control browser with Golang and selenium without selenium server?
You can try github.com/fedesog/webdriver which says in its documentation:
This is a pure go library and doesn't require a running Selenium driver.
I would characterize the Selenium webdriver as a client rather than a server. Caveat: I have used the Selenium webdriver (Chrome version) from .Net and I am assuming it is similar for Go.
The way Selenium works is that you will launch an instance of it from within code, and it creates a live version of the selected browser (i.e. Chrome) and your program retains control over it. Then you write code to tell the browser to navigate to a page, inspect the response, and interact with the browser by filling out form data, clicking on buttons, etc. You can see what is happening on the browser as the code runs, so it is easy to troubleshoot when the interaction doesn't go as planned.
I have used Selenium to upload tens of thousands of records to a website that has no API and only a graphical user interface. Give it a chance.

Run Selenium tests in one browser while using a second browser window

I am running Selenium automation test in one browser, but at the same time, I want to open the browser in another window and do something like checking mail, googling email then active mode or focus is coming to the current working window, not the automation test run browser.
Is it possible to work on the browser while automation test is run?
In general, when doing UI automation, you cannot use the test machine to do any other tasks that involve using the keyboard or mouse.
Since WebDriver automation performs keyboard and mouse input, such as typing text and clicking items, you will be constantly interfering by taking focus away from the WebDriver instance of the browser and doing your own mouse and keyboard interaction in other applications.
This will adversely affect both you and the automation, with neither being able to do what they want to do!
You should either use a separate test machine, or setup a virtual machine using software such as VirtualBox (free).
Did you try doing that?
Selenium uses WebDriver to communicate with a specific instance of a browser, not the currently focused window. So you should be able do continue to use other instances of browser windows. The best thing to do would be try.
If it isn't working, I would recommend getting a VM up and running and using that as your test environment. Generally that is the way I work to keep everything separate.
I ran my tests on Firefox and then used chrome on the side. Otherwise, run your tests on a remote machine.
You can do 2 things
1. Use a third tool to run test cases like Jenkins. so that test will run in memory.
2. If you are using firefox you can create a seperate firefox profile so that if you use firefox at the same time there should be any issue.
To Create new FF profile use below code:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(false);
profile.setAssumeUntrustedCertificateIssuer(true);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(dc);