Attaching test to a previously started browser (by a WebDriver)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Attaching test to a previously started browser (by a WebDriver)

Tamas Deak
Hi everyone, I believe that my expectations are high, so I'm not even sure it can wor. I found some older links where it said it is not possible, but I feel like I'm close to the solution and since those answers (2011) it may have changed:

My configuration:
  • Selenium version: 3.8
  • I have up to dated drivers (just downloaded them)
  • I tried with Chrome and Firefox
  • Testing on Windows 10 Pro
What I want:

1.
I start browser in my app (basically Chrome, but after many unsuccessful tries I also tried it with Firefox):
new ChromeDriver(options)
in case of Firefox:
new FirefoxDriver(options)

2.
After it starts I get the port where it runs and SessionId, I write them to file.

3.
In my tests, I would like to connect to this browser and use it.
var uri = new Uri("http://localhost:" + portItRuns); // if I concat "/wd/hub"  or "/hub" it still doesn't work.
var webDriver = new RemoteWebDriver(uri, options) // or new RemoteWebDriver(uri, DesiredCapabilities.Chrome())

What happens:

1.
Browser = Chrome, Uri = http://localhost:port
Starts a new browser with the previously created driver.

2.
Browser = Chrome, Uri = http://localhost:port/hub or Uri = http://localhost:port/wd/hub
OpenQA.Selenium.WebDriverException: Unexpected error. unknown command: hub/session

3.
Browser = Firefox, Uri = http://localhost:port
OpenQA.Selenium.WebDriverException: Session is already started

4.
Browser = Firefox, Uri = http://localhost:port/wd/hub or http://localhost:port/hub
System.InvalidOperationException: POST /wd/hub/session did not match a known command

What I have also tried:

Override the SessionId: in the Execute method like it writes in the article (link below)
With this, I could create a browser and then attach to to it. But the browser was created in the Test project, and it was a CustomRemoteWebDriver.
If I change the SessionId to the one I passed from the program, instead of the one in this article, it doesn't work:
No exception occurs, the test continues, but if I debug my test, put a breakpoint to after my CustomRemoteWebDriver was instantiated, checking its properties, it says: InvalidOperandExceptions as the values.
My navigation events also doesn't make any effect, but the test continues 

What I'm looking for:
After this long struggling I would like a solution how I could attach to my running browser. Is it even possible with Selenium? Any other solution - without Selenium (the driver is running, so it may be remotable)? 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/35f9ae0a-45f0-49f2-84f0-a15791dd00b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Attaching test to a previously started browser (by a WebDriver)

Tamas Deak
Solved the problem!

I just messed up the code. Be careful, and use the solution in the article. I set the SessionId in the constructor, but the base class's constructor was running before I set the SessionId, so the overrided Execute method was working wrong.
This code also works with Firefox.

2017. december 14., csütörtök 3:57:32 UTC időpontban Tamas Deak a következőt írta:
Hi everyone, I believe that my expectations are high, so I'm not even sure it can wor. I found some older links where it said it is not possible, but I feel like I'm close to the solution and since those answers (2011) it may have changed:

My configuration:
  • Selenium version: 3.8
  • I have up to dated drivers (just downloaded them)
  • I tried with Chrome and Firefox
  • Testing on Windows 10 Pro
What I want:

1.
I start browser in my app (basically Chrome, but after many unsuccessful tries I also tried it with Firefox):
new ChromeDriver(options)
in case of Firefox:
new FirefoxDriver(options)

2.
After it starts I get the port where it runs and SessionId, I write them to file.

3.
In my tests, I would like to connect to this browser and use it.
var uri = new Uri("<a href="http://localhost" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Flocalhost\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFGqUkBFzjtaT7Ud2VcduaSq6JAfQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Flocalhost\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFGqUkBFzjtaT7Ud2VcduaSq6JAfQ&#39;;return true;">http://localhost:" + portItRuns); // if I concat "/wd/hub"  or "/hub" it still doesn't work.
var webDriver = new RemoteWebDriver(uri, options) // or new RemoteWebDriver(uri, DesiredCapabilities.Chrome())

What happens:

1.
Browser = Chrome, Uri = http://localhost:port
Starts a new browser with the previously created driver.

2.
Browser = Chrome, Uri = http://localhost:port/hub or Uri = http://localhost:port/wd/hub
OpenQA.Selenium.WebDriverException: Unexpected error. unknown command: hub/session

3.
Browser = Firefox, Uri = http://localhost:port
OpenQA.Selenium.WebDriverException: Session is already started

4.
Browser = Firefox, Uri = http://localhost:port/wd/hub or http://localhost:port/hub
System.InvalidOperationException: POST /wd/hub/session did not match a known command

What I have also tried:

Override the SessionId: in the Execute method like it writes in the article (link below)
<a href="http://www.binaryclips.com/2016/03/selenium-webdriver-in-c-how-to-use.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.binaryclips.com%2F2016%2F03%2Fselenium-webdriver-in-c-how-to-use.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEBgiSs3s08EEpXBtEVx1hmGXfbew&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.binaryclips.com%2F2016%2F03%2Fselenium-webdriver-in-c-how-to-use.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEBgiSs3s08EEpXBtEVx1hmGXfbew&#39;;return true;">http://www.binaryclips.com/2016/03/selenium-webdriver-in-c-how-to-use.html
With this, I could create a browser and then attach to to it. But the browser was created in the Test project, and it was a CustomRemoteWebDriver.
If I change the SessionId to the one I passed from the program, instead of the one in this article, it doesn't work:
No exception occurs, the test continues, but if I debug my test, put a breakpoint to after my CustomRemoteWebDriver was instantiated, checking its properties, it says: InvalidOperandExceptions as the values.
My navigation events also doesn't make any effect, but the test continues 

What I'm looking for:
After this long struggling I would like a solution how I could attach to my running browser. Is it even possible with Selenium? Any other solution - without Selenium (the driver is running, so it may be remotable)? 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ffa9da08-21c7-4a53-9d28-b01f502e0691%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Attaching test to a previously started browser (by a WebDriver)

Xiang Dong
In reply to this post by Tamas Deak
If you just want to reuse a pre-initialized web browser, here the browser was initialized by web driver, i think it won't so complicated. You can write a browser instance pool and put the initialized web driver instance into it. Maintain web driver instance's status, such as idle, using or expired. your client can borrow web driver instance from the pool and return once the test finished. If you are running in a grid environment, it could be a little hard because you are not able to maintain the status.

--david 

From: [hidden email] <[hidden email]> on behalf of Tamas Deak <[hidden email]>
Sent: Thursday, December 14, 2017 4:25 AM
To: Selenium Users
Subject: [selenium-users] Attaching test to a previously started browser (by a WebDriver)
 
Hi everyone, I believe that my expectations are high, so I'm not even sure it can wor. I found some older links where it said it is not possible, but I feel like I'm close to the solution and since those answers (2011) it may have changed:

My configuration:
  • Selenium version: 3.8
  • I have up to dated drivers (just downloaded them)
  • I tried with Chrome and Firefox
  • Testing on Windows 10 Pro
What I want:

1.
I start browser in my app (basically Chrome, but after many unsuccessful tries I also tried it with Firefox):
new ChromeDriver(options)
in case of Firefox:
new FirefoxDriver(options)

2.
After it starts I get the port where it runs and SessionId, I write them to file.

3.
In my tests, I would like to connect to this browser and use it.
var uri = new Uri("http://localhost:" + portItRuns); // if I concat "/wd/hub"  or "/hub" it still doesn't work.
var webDriver = new RemoteWebDriver(uri, options) // or new RemoteWebDriver(uri, DesiredCapabilities.Chrome())

What happens:

1.
Browser = Chrome, Uri = http://localhost:port
Starts a new browser with the previously created driver.

2.
Browser = Chrome, Uri = http://localhost:port/hub or Uri = http://localhost:port/wd/hub
OpenQA.Selenium.WebDriverException: Unexpected error. unknown command: hub/session

3.
Browser = Firefox, Uri = http://localhost:port
OpenQA.Selenium.WebDriverException: Session is already started

4.
Browser = Firefox, Uri = http://localhost:port/wd/hub or http://localhost:port/hub
System.InvalidOperationException: POST /wd/hub/session did not match a known command

What I have also tried:

Override the SessionId: in the Execute method like it writes in the article (link below)
With this, I could create a browser and then attach to to it. But the browser was created in the Test project, and it was a CustomRemoteWebDriver.
If I change the SessionId to the one I passed from the program, instead of the one in this article, it doesn't work:
No exception occurs, the test continues, but if I debug my test, put a breakpoint to after my CustomRemoteWebDriver was instantiated, checking its properties, it says: InvalidOperandExceptions as the values.
My navigation events also doesn't make any effect, but the test continues 

What I'm looking for:
After this long struggling I would like a solution how I could attach to my running browser. Is it even possible with Selenium? Any other solution - without Selenium (the driver is running, so it may be remotable)? 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/35f9ae0a-45f0-49f2-84f0-a15791dd00b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/HKXPR03MB02481D7BBA6A68C7AA47993E900A0%40HKXPR03MB0248.apcprd03.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.