How to run Protractor test when spec is remote - selenium

Here's the situation:
machineA has Protractor, Selenium, WebDriver, etc. installed.
machineB has all source code including tests and server running source code, but no Protractor, Selenium, etc
environment is Linux on both machines
How can I run the Protractor command on machineA so that it points to the spec on machineB?
ie. How to get a local Protractor command to point to a remote spec?

You need to provide seleniumAddress in your config file and make sure directConnect option is commented or value should be false.
Start webdriver on machineA through webdriver-manager start
exports.config = {
baseUrl: 'http://example.com/',
seleniumAddress: 'https://<machineA IP addess>:4444/wd/hub',
//directConnect:true,
...
}

Related

WebDriver IO fails to create chrome browser sessions when using in Botium

I have installed Botium-Binding and prepared my machine to have installed with selenium-standalone server as per the documentation in https://github.com/codeforequity-at/botium-connector-webdriverio.
Once everything is setup i have added below capabilites to the botium.json file in samples/custom scripts folder.
"WEBDRIVERIO_OPTIONS": {
"capabilities": {
"browserName": "chrome",
}
}
Then i have run the command npm install && npm run mocha to trigger the runner.
All i could see is that the Webdriver session is being created and terminated with the error below:
WebdriverIO Plugin Sample
Starting ChromeDriver 92.0.4515.107 (87a818b10553a07434ea9e2b6dccf3cbe7895134-refs/branch-heads/4515#{#1634}) on port 44325
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
1) "before each" hook for "contractcancellation"
0 passing (9s)
1 failing
1) WebdriverIO Plugin Sample
"before each" hook for "contractcancellation":
Error: WebDriver error on startup: Failed to create session.
Make sure to connect to valid hostname:port or the port is not in use.
If you use a grid server
Make sure to add vendor prefix like "goog:", "appium:", "moz:", etc to non W3C capabilities.
See more https://www.w3.org/TR/webdriver/#capabilities
tried adding Hostname, port, platform to the capabilities but of no use. Looking for some help on this to get me unblocked.
You have to follow the instructions to install a chromedriver version that matches your Chrome version (as pcalkins wrote above).
It this doesnt help I recommend to enable verbose logging to get more insights on whats happening. You may post the log output here for further investigation.

Python Selenium Remote Webdriver(Chrome Webdriver via Selenium Grid), created but does not open browser

I have the following setup:
A Selenium server hub running at "http://localhost:hubPortNum" (a service with the Jar file selenium-server-standalone-3.141.5.jar with parameter -role hub).
A Selenium Node at running "http://localhost:nodePortNum' (the service with Jar file with parameters: -Dwebdriver.chrome.driver=ChromeWebdriverPath -role node -port :nodePortNum).
I checked the URL for the hub and node instances to be sure they are working.
Whenever I try to create Remote Webdriver via Python script:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
desiredCapabilities = DesiredCapabilities.CHROME.copy()
chromeOptionsRemote = webdriver.ChromeOptions()
chromeOptionsRemote.add_argument("--start-maximized")
chromeOptionsRemote.add_argument("--disable-session-crashed-bubble")
initRemoteDriver = webdriver.Remote(options=chromeOptionsRemote, command_executor='http://127.0.0.1:<nodePortNum>/wd/hub', desired_capabilities=desiredCapabilities)
print(initRemoteDriver.current_url)
The last line does print the current URL(which is "data:,"), that means Webdriver is created.
But the browser does not open on my local machine, that is it is running in the background and I don't know how to make it visible although it has worked in the past.
The troubleshooting steps I have made:
Reinstall latest selenium python package.
Re-Download latest Selenium server jar file.
Updating chrome.
adding chromeOptionsRemote.add_argument("--no-sandbox")
Making sure local Webdriver does open:
That is the line:
self.localDriver = webdriver.Chrome(options=chromeOptionsLocal,
desired_capabilities=desiredCapabilities)
does open the browser locally(the Chromedriver is in the path).
After I made these troubleshooting steps, I have tried the same configuration on a remote server and got the same result(browser not visible), so I think this is probably by design.
what configuration should I create for the browser to be visible?
Any help would be appreciated.
I was running the jar file by Always-Up: https://www.coretechnologies.com/products/AlwaysUp/
The problem was related to session 0 isolation: https://stackoverflow.com/a/26752251/2710840
in order to not run the application under session 0, I have enabled the Autologon feature:
defined the user under the application run as my user:
and executed the application from the context menu with the option to: "restart in this session"

Starting protractor execution from a selenium session

How can we use protractor with an existing selenium browser session rather than always create a new one. If I have started up a selenium browser session, run some tests in there, and exported the session ID into the environment conf file in protractor or in some other way made it available, it would be nice to be able to configure protractor in the normal way (e.g. using an option in the protractor configuration file) to access this session.
I would need to start a protractor execution in the middle of a selenium execution, do some test, and come back to selenium execution. Something like pseudo-code snippet would really help.
You'll need to session id from the launched browser. You should be able to get it from the http://localhost:4444/wd/hub/static/resource/hub.html. So let's say this session id is '12345', you have two options, you could pass it as a command line or via the configuration file.
command line
protractor protractor.conf.js --seleniumSessionId=12345
configuration file
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumSessionId: '12345',
...
}
After you have set the selenium session id, you should be able to use the browser session. An example of this being exercised is: https://github.com/angular/protractor/blob/master/scripts/driverProviderAttachSession.js
If you would like to read more about it, I also have a medium post about this feature that I might have worked on: https://medium.com/#cnishina/attaching-a-protractor-test-to-an-existing-selenium-session-931196936ae2

Protractor will not run with selenium grid

I want to use the protractor to run the tests on the selenium grid, which runs on :
http://<ip_address>:4444/
In my config file I have:
seleniumAddress: "http://32.14.98.73:4444/wd/hub",
When I run the test, they are run locally and start the browser on the local system. ? Anything else is needed for this to work ?
In logs I have:
[18:20:05] I/direct - Using ChromeDriver directly...
[18:20:05] I/launcher - Running 1 instances of WebDriver
Change your config file for object directConnect to directConnect:false. For detailed understanding on directConnect and seleniumAddress refer the below link Difference running Protractor with/without Selenium?

Protractor overriding selenium address?

Protractor is starting a selenium server itself when I tell it to use on on a different url? I have selenium server running on a Windows virtual machine and I am trying to run my tests through it:
multiCapabilities: [
{
'selemiumAddress': 'http://10.1.41.56:4444/wd/hub',
'browserName': 'internet explorer'
}
],
If I go to http://10.1.41.56:4444/wd/hub on my primary machine I can create a new internet explorer instance and it will have a internet explorer browser popup on the VM but when I run my protractor config file it just gives me a error:
UnknownError: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable; for more information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded from http://phantomjs.org/download.html
You have a typo in your capabilities:
'selemiumAddress': 'http://10.1.41.56:4444/wd/hub',
selemiumAddress should probably be seleniumAddress (N vs M)