How to use already opened browser active session in webdriver - java

Is there any way to inherit a session into webdriver? I did lot of search and know it that selenium does not support connecting to already opened browser. It would be better if i could. But now I have thought about some work around. Actually my application starts with a shortcut file which launch firefox, hit the application URL, made the log in, go to the dashboard and leave for the user to use it. In that case i do not need to work on that opened browser, if i can get that active session only and set it while opening the webdriver with selenium then my purpose is solved. Even its possible manually also. As selenium always open incognito webdriver window, i am unable to get that session there. Can any one tell me how to get that session from already opened browser and use it in webdriver? Any help or suggestion would be highly appreciated.

Selenium is just a server which accepts http requests using the json wire protocol. https://code.google.com/p/selenium/wiki/JsonWireProtocol
It's an http API.
Each call in the json wire protocol adds a sessionId parameter to the request.
So if you start a session using a driver, you can save that session ID and then instantiate a new driver object and give it the sessionId from before.
If the selenium server is still running that session, then it has no idea which driver object you are using when you send in a request. Feel free to have 100 drivers all with the same sessionID at the same time! :D

Related

Certificate authentization while using WebSampler in JMeter

I am trying to handle the following issue while trying to automate login process with JMeter WebDriver Sampler to our web app, which requests an authoriaztion certificate for a user to log in.
After filling credentials and clicking the Login button, the following window is called:
dialog window. I assume this is an OS window that cant be aimed by Selenium/WebDriver Sampler script - or is it possilbe?
EDIT: I found some solution e.g. https://sqa.stackexchange.com/questions/7640/how-to-select-security-certificate-from-security-dialog bit I am kind of afraid of implement the recommended code to the script - isnt there another solution then via Selenium script?
I tried to set a certificate in jmeter's system.properties file:
system.properties keystore setting.
I supposed it makes SOMETHING, e.g. some error after launching script, but it ends on the exactly same step - dialog window with Certificate choosing offer. So I assume this is wrong place to set user authentication certificate.
How is it possible to handle this kind of login process? I guess it is necessary to set a default certificate that is paired with the user's credentials I am sending in the previous step in my script, but I dont know where.
What you set in JMeter's "system.properties" file only affects the client certificates for HTTP Request samplers.
WebDriver Sampler is a different beast, it uses Selenium libraries to automate the real browser hence you need to follow your browser documentation to learn how to automate the certificate selection process.
For example for
Chrome on Windows it's in registry
for Chrome on Linux/Unix it's under /etc/chromium/policies/managed folder
More information: AutoSelectCertificateForUrls

WinAppDriver based automation stops working on windows 10 VM when I close the RDP connection

I am doing all the work remotely on my Windows 10 Virtual Machine (Via RDP). Whenever I am logged in to the server, I can see my automation running fine but when I close my RDP connection, the WinAppDriver can't find the elements on the desktop application and thus it stops working.
How can I solve it?
Please let me know If I am missing something.
Thanks
When you disconnect the RDP session windows knows it doesn't have the render the gui, so it doesn't.
The trick is to disconnect a different way. Terminate your connection from the remote sever with this:
%windir%\System32\tscon.exe RDP-Tcp#NNN /dest:console
where RDP-Tcp#NNN is the ID of your current Remote Desktop session, for example, RDP-Tcp#5. You can see it in the Windows Task Manager on the Users tab, in the Session column.
If you need more info have a look at this site https://support.smartbear.com/testcomplete/docs/testing-with/running/via-rdp/keeping-computer-unlocked.html
The link is for test complete not selenium but the steps are sound.

connecting to the opened web browser using java selenium

Due to some reason ... i need to open the browser window manually and do some steps before running the script.
after running the script i want it to connect with that window only (manually opened).
p.s-since its manually opened .. cant pass the object of the WebDriver.
how can i direct my script to use that specific window.
somewhere found this-
driver = new RemoteWebDriver(newURL("http://10.0.1.10:4444"), new DesiredCapabilities());
Q1.how can found the this url "http://10.0.1.10:4444" which will work for me.
Q2. how will this driver know to go to firefox only and not chrome or IE. and to connect with particular tab and not the any other tab.
:- though i can keep only only one tab open in firefox.. Q2,second part for knowledge purpose only.
any kind of help will be highly appreciated.
Thanks
As you can see here
It is not currently possible to connect to a browser which is not opened by selenium.
What you can do is start the browser via selenium and then wait until you're done with your actions before continuing. Something like the following:
Start browser
Wait until element visible with long timeout
//Perform manual actions on browser
//Open page to test manually
//Testscript now executes because element at step 2 is found
WebDriver spawns its on own browser instance, it cannot work on already open browser window.
If you can mention what steps you have to manually do before starting the webdriver script then help can be provided on that.

Selenium webdriver not responsive after click

I am trying to login to web outlook of test exchange server. Using selenium webdriver I am able to input the username , password and then click on the sign in button in web outlook. But after clicking there is no response in selenium neither throwing exception.No actions beyond the click will be performed.
But same scenario if I am running with HTTP instead of HTTPS, everything works fine.
Does it has to do something with IE settings? I have unchecked 'Warn about certificate address mismatch *" in Advanced section of Internet Options. This is done to bypass the SSL certificate error.
There may be few reasons.
1)Element may be out of focus. try focusing the element by using sendKeys(Keys.CONTROL).
2)There may be a page refresh happening or AJAX call when you are trying to click element. try using implicit wait until ajax call completes.
3)Website which you are trying to automate may be Siebel application(containing Active X Control)

Communicate with a specific browser

I've created a website in JSP with Servlets.
Users can login and they all get a session attribute with their userid.
I created a page with a textbox and button where I can fill in an userid.
Upon clicking the button I want to open a popup (url) on the browser of the specific user with the session userid equals to the userid filled in the textbox. The popup should appear immediately an not require a page request to get shown.
What kind of things I should use for this?
I googled, but couldn't find anything usefull.
Writing a chat client can be quite tricky because you have to send data from the server to the client when a message is sent by another user. WebSockets allows you to do this but it is a pretty new technology which does not work with IE versions below 10. Chrome, Firefox and Safari do support it.
The group of technologies that allow you to use javascript to communicate with the server instead of requiring browser page refreshes is called AJAX.
A library like DWR makes it very easy to do AJAX between Javascript and Java. It also has a feature called Reverse AJAX that allows you to write Java code that executes javascript code on the client. http://directwebremoting.org/dwr/documentation/reverse-ajax/index.html
With DWR you can write this to show a popup on all connected clients:
Container container = ServerContextFactory.get().getContainer();
ScriptSessionManager manager = container.getBean(ScriptSessionManager.class);
System.out.println("sessions: " + manager.getAllScriptSessions().size());
for (ScriptSession scriptSession : manager.getAllScriptSessions()) {
System.out.println("Sending script to session " + scriptSession);
ScriptBuffer script = new ScriptBuffer("window.alert('hello from reverse ajax server');");
scriptSession.addScript(script);
}
When you need the popup to appear immediately and you can't wait for a page-request, you need some kind of communication channel from server to client which allows pushing messages.
A good tool for this are Javascript WebSockets. A WebSocket is a bidirectional connection between browser and server which is open while the page is open and which can be used by both sides to send data whenever they want.
On every page you need to create a websocket and connect it to a WebSocket Servlet. While the client has the page open, that servlet is able to send a message to the client whenever it wants. You can then handle that message in Javascript to implement a real-time chat application.

Categories

Resources