Protractor will not run with selenium grid - selenium

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?

Related

Getting Chromedriver logs from standalone Selenium Chrome instance

Summary: How do I extract Chromedriver logs when running Selenium standalone Chrome instance? I.e. interacting via Selenium API commonly on port 4444.
Details:
We are using Protractor to connect to a container running the Docker image selenium/standalone-chrome Selenium "grid". Connection info is specified via the HUB_PORT_4444_TCP_ADDR environment variable. The connection URL ends up being http://localhost:4444/wd/hub. This works fine and our tests are running successfully in Jenkins.
For completeness I'd like to extract the Chromedriver logs and attach them to the build in case we need more info for debugging test failues. How can that be done?
This question seemed like a close match but they are running Chromedriver directly. I need to ask Selenium to provide them somehow.
Log properties of standalone chrome container can be configured using JAVA_OPTS.
You can add JAVA_OPTS environment variable to standalone chrome container
name: JAVA_OPTS
value: "-Dwebdriver.chrome.logfile=<Path to log file, with file name>"
We had a shared volume mounted, and gave path to that folder for putting log file.
Used yaml file for creating container template so used in above mentioned way.
If you are using CLI to launch container, same can be passed through CLI too.

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"

How to run Protractor test when spec is remote

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,
...
}

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

Running Selenium tests in Jenkins

I have recorded some simple selenium tests by Selenium IDE. Now I want to run those tests in Jenkins.
Which plugin to Jenkins do I need to do that? And how to run the tests step by step? Help is appreciated.
you can use recorded selenium IDE script and selenium-server.jar file to run it from Jenkins
Here is steps:
Go to SeleniumHQ page and download Selenium Server file
Eg: selenium-server-standalone-2.33.0.jar
Repair html test suite Use Selenium IDE to record then save as
html test case and test suite then put them in a same folder
eg: TestCase.html, TestSuite.html
In jenkins
Plugin Seleniumhq
Configure Selenium runner file
Manage Jenkins > Configure System > Selenium Remote Control: htmlSuite Runner = path to file u have download in step 1
Configure Job to run
In Build field click " Add build step" then select "seleniumhq htmlSuite Run"
browser: *firefox or *iexploer ....
startURL: http://www.google.com or ...
suiteFile: Input absolutely path to TestSuite.html file saved in step 2
resultFile: Input absolutely path to a file that results will be saved
Hope this help!
I did the same but the following error occurred:
Unable to find the HTML runner. This is normally because you have not downloaded
or made available the 'selenium-leg-rc' jar on the CLASSPATH. Your test will
not be run.
Download the Selenium HTML Runner from http://www.seleniumhq.org/download/ and
use that in place of the selenium-server-standalone.jar for the simplest way of
running your HTML suite.