Pass a process ID to start selenium in - selenium

How can I pass a chrome process ID to selenium to force it to start an existing browser? I tried passing arguments to capabilities but they did not help.
Thanks
Any help is appreciated.
capabilities.setCapability( "pid", pid ); //$NON-NLS-1$
ChromeDriver driver = new ChromeDriver(capabilities);

Answering straight, No, you can't pass a Chrome Process ID [PID] to Selenium to force it to start an existing browser.
Similarly, even if you are able to extract the Session ID and other session attributes from the previous Browsing Session still you won't be able to pass those attributes as a HOOK to the WebDriver.

Related

How to get Selenoid session ID

I would like to clarify how can I use Selenoid API to check downloaded files.
According the documentation to get downloaded file from container I need to call
http://selenoid-host.example.com:4444/download/f2bcd32b-d932-4cdc-a639-687ab8e4f840/myfile.txt
where f2bcd32b-d932-4cdc-a639-687ab8e4f840 is a Selenoid Session ID
So, the question is "How can I get this session ID?"
Value, returned by getSessionId from RemoteWebDriver doesn't look like correct one.
UPD. My bad. Session ID, that I can get from RemoteWebDriver instance, is correct.
The problem was I didn't wait enough to get a file exactly downloaded into container. That's why I got 404 error on attempt to get a file via API
Thats depends on your client bindings that you use for tests.
For example in java:
WebDriver driver = new FirefoxDriver();
SessionId session = ((FirefoxDriver)driver).getSessionId();
System.out.println("Session id: " + session.toString());
If you want to get list of active sessions with their IDs outside of tests: use selenoid /status endpoint
Pleas notice, if you use GGR - it modifies session id -
every new browser session in Selenium automatically obtains an ID
called session ID. According to Selenium JSONWire protocol this ID is
always passed to request. GridRouter appends information about
selected Selenium Hub to this session and returns enriched session ID
to user.
https://hackernoon.com/selenium-testing-a-new-hope-7fa87a501ee9

How to `executeScript` before page load by WebDriver in selenium?

I want to use webdriver in nodejs to control a website which use ajax very heavy, especially it always have http request to server.
When I use driver.executeScript , I found the promise returned almost never resovled.
I checked the website, found that it use a keep-alive http request loop to communicate with server. That means, it will always have at least one live connection to server for 30s, then another connection for another 30s, again and again. which cause document.readyState keep interactive instead of completed, and then driver.executeScript almost be blocked forever.
I had tried driver.manage().timeouts().pageLoadTimeout(PAGE_LOAD_TIMEOUT_MS) but it only throws a exception after timeout.
I also tried to stop the connections by press ESC on the browser window. after that, it seems driver.executeScript can run immediately. But I didn't find any function like window.stop() in WebDriver API.
so is there have a way to resolve this problem? Either should be ok like:
run executeScript right now, regardless of whether page is loaded;
a webdriver api like driver.browser.stop() could stop all live connections in page.
Nodejs code to re-produce this problem:
const WebDriver = require('selenium-webdriver')
const driver = new WebDriver.Builder()
.withCapabilities(
WebDriver.Capabilities.firefox()
.set('webdriver.load.strategy', 'unstable')
).build()
driver.get('https://wx.qq.com/')
driver.executeScript('return "99% will be blocked, 1% luck to return"')
.then(function (ret) {console.log(ret)})
thanks!
UPDATE:
I found maybe set webdriver.load.strategy to unstable in firefox will be help.
FirefoxProfile fp = new FirefoxProfile();
fp.setPreference("webdriver.load.strategy", "unstable"); WebDriver
driver = new FirefoxDriver(fp);
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4993
https://w3c.github.io/webdriver/webdriver-spec.html#page-load-strategies-1
Links from others got same problem:
http://grokbase.com/t/gg/webdriver/1263dbyws6/how-to-click-stop-button-or-equivalent
I think that if you don't use Implicit time the driver won't wait till it's loaded so you'll be able to execute your script.
If this don't work you can try to use your own timer. Check if doc state is ready, if it's not ready after some timeout then stop it manually (by JS) and run your script.
By using Thread.sleep(secs);. For example, we want to load a page in 3 secs means we write thread.sleep(30000);.

RESTAssured and WebDriver: get and use a session id from browser

I'm trying to use WebDriver to get the session ID from the browser being tested so that I can pass that ID in through the given().session(string) functionality in RESTAssured. The browser will go through a normal login to create the session ID. Any ideas how to capture it?
You can get your session id by casting the driver object to RemoteWebDriver like this
String session = ((RemoteWebDriver) driver).getSessionId().toString();
Maybe you could just read it from cookie. Or I don't understand the problem.
Here is similar problem Get cookies in Webdriver how?

Migrating to Webdriver from Selenium RC

I am migrating from RC to webdriver.
In my existing project I use methods from the Selenium Class like
selenium.click()
selenium.type()
etc.
Do I need to change these to the equivalent webdriver commands, or is there a way i can still use these commands?
I use firefox 12, Eclipse IDE
There is the WebDriverBackedSelenium. Essentially this is a bridge between the RC API and WebDriver API. This will do what you are after, there will be some modification to code, but majority will still be the same. It gives you the flexibility of the WebDriver itself, while keeping old code the same.
It is highly recommended to fully convert your solution to use the WebDriver API directly.
The WebDriver API is constantly being updated, worked on and supported.
The RC API and the "RC-WebDriver-Bridge" (WebDriverBackedSelenium) won't be.
Page on WebDriverBackedSelenium exists here:
http://seleniumhq.org/docs/03_webdriver.html#alternative-back-ends-mixing-webdriver-and-rc-technologies
Sample usage to create a new instance of Firefox:
var driver = new FirefoxDriver();
var selenium = new WebDriverBackedSelenium(driver, baseUrl);
selenium.open("http://www.google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");
selenium.stop();
After creating a WebDriverBackedSelenium instance with a given Driver, one does not have to call start() - as the creation of the Driver already started the session. At the end of the test, stop() should be called instead of the Driver's quit() method.
This is more similar to WebDriver's behaviour - as creating a Driver instance starts a session, yet it has to be terminated explicitly with a call to quit().

what is the difference between selenium.click and driver.click

I have recorded a scenario in Selenium IDE and exported it as a Junit4 Webdriver backed code.
There is a command which uses selenium object and the same thing could be done by driver object.
So I am not able to understand which one to use and when
E.g :
selenium.click("id=gen_info") can also be implemented by
driver.findElement(By.id("gen_info")).click();
Yes I do have a option to have a driver object of specific web browser but then the same thing could be done by using selenium object also.
I suppose that by selenium click u mean something like this:
WebDriver driver = new FirefoxDriver();
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
WebDriverBackedSelenium allows those who have test suites using the Selenium-RC to migrate to WebDriver. However it doesn't implement all methods.
In this particular case it should work the same, though WebDriverBacked may be slower