My test is getting failed when i try to execute on "Linux/XP/etc" platforms using Selenium Grid - node.js

i'm new to this Selenium grid.. my node is default registered on Win10 platform.. so it is executing the script without any issue. But when i tried to run on Other than Win10 it is getting failed. can someone please help me how to resolve this. i reviewed all the solutions available in internet but i'm not able to resolve it.
Code
baseURL = "http://demo.guru99.com/test/guru99home/";
nodeURL = "http://192.168.1.4:4444/wd/hub";
ChromeOptions options=new ChromeOptions();
DesiredCapabilities cap=DesiredCapabilities.chrome();
cap.setPlatform(Platform.LINUX);
options.merge(cap);
driver = new RemoteWebDriver(new URL(nodeURL), options);
Error
15:02:08.893 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, platform: LINUX, version: }
15:02:08.912 INFO [RequestHandler.process] - Error forwarding the new session cannot find : Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, platform: LINUX, version: }
org.openqa.grid.common.exception.CapabilityNotPresentOnTheGridException: cannot find : Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, platform: LINUX, version: }
at org.openqa.grid.internal.ProxySet.verifyAbilityToHandleDesiredCapabilities(ProxySet.java:153)
at org.openqa.grid.internal.DefaultGridRegistry.addNewSessionRequest(DefaultGridRegistry.java:217)
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:111)
at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:85)
at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:865)
at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
at org.seleniumhq.jetty9.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1242)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.seleniumhq.jetty9.server.Server.handle(Server.java:503)
at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:364)
at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:260)
at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:103)
at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
Node.Json file
{
"capabilities":
[
{
"browserName": "firefox",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "internet explorer",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
if i need to add the capabilities for the other platforms where i have to add those capabilities.

This one solved my problem.
java -jar "C:\Users\DELL\Desktop\Selenium Grid\selenium-server-standalone-3.141.5.jar" -role node -hub http://*.*.*.*:PortNumber/grid/register -port 5557 -browser "browserName=chrome,platform=LINUX"
note: Place your Ip address in place of " * "
and also check the node URL Port number.

Related

Prtractor Error with Gitlab CI/CD Pipeline

We have a secured network and Protractor test suite runs locally. But when running the Gitlab CI/CD pipeline with headless chrome it returns network errors
This is my conf.js
exports.config = {
framework : "jasmine2",
multiCapabilities : [
{
browserName: "chrome",
chromeOptions: {
args: [
"--incognito",
"--headless",
"--no-sandbox",
"--disable-gpu",
"--window-size=1920,1080",
"--disable-dev-shm-usage",
"--allow-insecure-localhost"
],
},
},
],
specs: [
'./tests/sample.ts',
],
seleniumServerJar: '../node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar',
seleniumAddress: 'http://localhost:4444/wd/hub',
chromeDriver: './node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_98.0.4758.102',
directConnect: true,
onPrepare: function(){
void browser.manage().timeouts().implicitlyWait(10000);
void browser.waitForAngularEnabled(false);
require("ts-node").register({
project: require("path").join(__dirname, "./tsconfig.json"),
})
},
plugins: [{
package: 'protractor-screenshoter-plugin',
screenshotPath: './outputJS/reports/e2e',
screenshotOnExpect: 'failure+success',
takeScreenshots:'true',
withLogs: 'true',
writeReportFreq: 'asap',
imageToAscii: 'none',
clearFoldersBeforeTest: true
}]
}
Error appears
$ npm run e2e-headless-run
> e2e#1.0.0 e2e-headless-run /var/gitlab-runner/-8xgu1of/0/team-iron/ebba/pco-front-end/e2e
> node node_modules/protractor/bin/protractor ./headless_conf.js
[09:46:36] W/driverProviders - Using driver provider directConnect, but also found extra driver provider parameter(s): seleniumAddress, seleniumServerJar
[09:46:37] I/launcher - Running 1 instances of WebDriver
[09:46:37] I/direct - Using ChromeDriver directly...
Activated Protractor Screenshoter Plugin, ver. 0.10.3 (c) 2016 - 2022 [object Object] and contributors
Started
Creating reporter at ./outputJS/reports/e2e/
FF
Failures:
1) Google Sample Test loading web page
Message:
Expected '**Network Error**' to contain 'PCO'.
Stack:
Error: Failed expectation
at helper.verifyPageTitle (/var/gitlab-runner/-8xgu1of/0/team-iron/ebba/pco-front-end/e2e/helper/helper.ts:151:36)
at loginPage.verify_page_title (/var/gitlab-runner/-8xgu1of/0/team-iron/ebba/pco-front-end/e2e/pages/loginpage.ts:55:23)
I tried adding webDriverProxy and proxy. But same result appears.

How to configure Nightwatch.js with geckodriver to install metamask on browser startup

So we are trying to configure NightWatch so that the resulting opened firefox browser window, comes pre-installed with a extension (MetaMask) - so that tests can use Metamask to test out simple wallet transactions.
I'm fairly certain this is possible using geckodriver.
Our current nightwatch.conf.js file is:
const pathToGeckoDriver = require('geckodriver').path;
module.exports = {
src_folders: ['src/tests'],
page_objects_path: ['src/pages'],
custom_commands_path: ['src/custom-commands'],
webdriver: {
start_process: true,
server_path: pathToGeckoDriver,
},
test_settings: {
default: {
launch_url: 'https://some-website.com',
end_session_on_fail: false,
desiredCapabilities: {
browserName: 'firefox',
acceptInsecureCerts: true,
javascriptEnabled: true,
firefoxOptions: {
args: ['-profile', 'nightwatch'], // tried making a "nightwatch" profile for firefox and setting this profile at startup. no luck. :(
add_extension: ['metamask-10.2.2-an+fx.xpi'], // tried various versions of this line, no luck. :(
},
},
},
},
};
We have downloaded the extension XPI file and placed it in the same dir as the nightwatch.conf.js file.
Has anyone managed to get geckodriver to boot with an extension installed via Nightwatch config?

Appium Webdriverio Setup

I need help understanding how to set up a testing framework to using Appium, Webdriverio, Node.js, Jasmine. I have the wdio.conf.js file set up:
host: '127.0.0.1',
port: 4723,
path: '/wd/hub',
....
specs: [
'./spec/wdtest/test.js'
],
....
capabilities: [
{
automationName: "appium",
browserName: 'iOS',
commandTimeout: '7200',
sessionOverride: true,
debugLogSpacing: true,
platformVersion: '10.1',
platformName: 'iOS',
showIosLog: true,
deviceName: 'iPhone 6s',
nativeInstrumentsLib: true,
isolateSimDevice: true,
autoLaunch: true,
app: '/Users/fodgerl/Library/Developer/Xcode/...../Debug-iphonesimulator/myapp.app'
}
],
....
services: ['appium'],
appium: {
args: {
address: '127.0.0.1',
commandTimeout: '7200',
sessionOverride: true,
debugLogSpacing: true,
platformVersion: '10.1',
platformName: 'iOS',
deviceName: 'iPhone 6s',
showIosLog: true,
nativeInstrumentsLib: true,
isolateSimDevice: true,
app: '/Users/fodgerl/Library/...../Products/Debug-iphonesimulator/myapp.app'
}
},
framework: 'jasmine',
My package.json file has:
"scripts": {
"test": "wdio wdio.conf.js"
},
And I have a test js file that has this:
describe('test', function() {
it('test', function () {
//how do I interact with the app?
console.log("HEREEEEE");
});
});
When I run npm test, the simulator launches and the app launches within it. What I don't know is where to go to next? How do I open app/interact with elements/etc.
I have seen examples like:
var client = webdriverio.remote({
port: 4723,
logLevel: 'verbose',
desiredCapabilities: {
platformName: 'iOS',
platformVersion: '8.4',
deviceName: 'iPhone 6',
app: webviewApp
}
});
But do I need to do that if I already have the simulator up and running from the stuff in the conf file? I was trying to find some documentation on what .remote(), init(), etc does. Also, I looked in the Launcher for webdriverio but I couldn't determine where/how it was being used in the example here: https://github.com/webdriverio/webdriverio/blob/master/examples/wdio/runner-specs/jasmine.spec.js
Any help would be appreciated to get me started!! Thanks!
On running $ npm test, it executes $ ./node_modules/.bin/wdio wdio.conf.js. So you have the wdio test runner up and running.
Now, as mentioned in The Browser Object subsection:
If you use the wdio test runner you can access the webdriver instance through the global browser object. The session is initialized by the test runner so you don’t need to call init command. The same goes for ending the session. This is also done by the test runner process.
That's it! You can access the driver instance via the global variable browser as illustrated in the aforementioned example.
Hope that helps!
webdriver.io is just for running the tests. Not interacting with the app. Use appium to app/interact with elements/etc. Appium will record the step and elements path/s. From here you can create your test cases which can be run using wedriver.io

Starting Selenium Server with Nightwatch.js

I was using selenium-webdriver and wanted to try out nightwatch.js to see if it is easier to use. I followed the instructions here. I decided to let Nightwatch automatically start the selenium server for me so I did what I thought was the proper configuration based on the linked provided above. I get an error that I can't figure out and the output says:
Starting selenium server... started - PID: 1760
[Test] Test Suite
=================
Running: demoTestGoogle
Error retrieving a new session from the selenium server
Error: connect ECONNREFUSED 127.0.0.1:8080
at Object.exports._errnoException (util.js:856:11)
at exports._exceptionWithHostPort (util.js:879:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1053:14)
Connection refused! Is selenium server started?
Process finished with exit code 1
The selenium debug log file says this
13:43:03.394 INFO - Launching a standalone Selenium Server
13:43:03.474 INFO - Java: Oracle Corporation 25.73-b02
13:43:03.474 INFO - OS: Windows 7 6.1 amd64
13:43:03.483 INFO - v2.52.0, with Core v2.52.0. Built from revision 4c2593c
13:43:03.530 INFO - Driver class not found: com.opera.core.systems.OperaDriver
13:43:03.530 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
13:43:03.536 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform VISTA
13:43:03.665 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
13:43:03.665 INFO - Selenium Server is up and running
This is my nightwatch.json file
{
"src_folders": [ "tests" ],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "",
"selenium": {
"start_process": true,
"server_path": "./bin/selenium-server-standalone-jar/jar/selenium-server-standalone-2.52.0.jar",
"start_session" : true,
"log_path": "",
"host": "",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "",
"webdriver.ie.driver": ""
}
},
"test_settings": {
"default": {
"launch_url": "http://localhost",
"selenium_port": 8080,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": false,
"path": ""
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
Edit: Added demoTestGoogle, I have a nightwatch.js file in which I run and then it runs the demoTestGoogle function.
nightwatch.js which runs demoTestGoogle
require('nightwatch/bin/runner.js');
demoTestGoogle function in separate JS file
this.demoTestGoogle = function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'The Night Watch')
.end();
};
As suggested by this great guide to Nightwatch, dwyl-learn-nightwatch, you can replace your nightwatch.json file with a .js file to add features like variables, globals and even requiring in Selenium so Nightwatch can see it and run it.
Here's a simple example I modified from that GitHub source to start selenium with its tests. Make sure to install the dependencies in the project, first:
npm install --save-dev nightwatch chromedriver selenium-server
Then replace that JSON file with a .js one, perhaps named nightwatch.conf.js and notice the config options under the selenium key in the config file:
nightwatch.conf.js
const seleniumServer = require("selenium-server");
const chromedriver = require("chromedriver");
const SCREENSHOT_PATH = "./screenshots/";
module.exports = {
"src_folders": [
"tests/e2e"
],
"output_folder": "./reports",
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": seleniumServer.path,
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": {
"webdriver.chrome.driver" : chromedriver.path
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": SCREENSHOT_PATH // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // set a (default) timeout period, maybe 5s
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true
}
}
}
}
function padLeft (count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/
return count < 10 ? '0' + count : count.toString();
}
var FILECOUNT = 0; // "global" screenshot file count
/**
* The default is to save screenshots to the root of your project even though
* there is a screenshots path in the config object above! ... so we need a
* function that returns the correct path for storing our screenshots.
* While we're at it, we are adding some meta-data to the filename, specifically
* the Platform/Browser where the test was run and the test (file) name.
*/
function imgpath (browser) {
var a = browser.options.desiredCapabilities;
var meta = [a.platform];
meta.push(a.browserName ? a.browserName : 'any');
meta.push(a.version ? a.version : 'any');
meta.push(a.name); // this is the test filename so always exists.
var metadata = meta.join('~').toLowerCase().replace(/ /g, '');
return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_';
}
module.exports.imgpath = imgpath;
module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;
And the command I use to run this is this, using the locally installed nightwatch version:
nightwatch --config nightwatch.conf.js
Hope that helps!
Goodluck and good on your for testing your code.

Unable to execute nightwatch tests on chrome using Linux

Here's the bit in question from my nightwatch.json file :
"selenium" : {
"start_process" : true,
"server_path" : "lib/selenium-server-standalone.jar",
"log_path" : "test_logs"
},
"test_settings" : {
"jenkins" : {
"launch_url" : "url not disclosed",
"selenium_port" : 4444,
"selenium_host" : "jenkins.undisclosed-cloud.com",
"cli_args" : {
"webdriver.chrome.driver" : "/usr/local/bin/chromedriver"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"platform" : "LINUX"
}
}
}
If I change the browserName to firefox then the test runs fine in the specified linux server, which is running on a DOCKER CONTAINER.
But when i choose chrome, i am getting the error:
Connection refused! Is selenium server started?
I've seen this error before on my local machine and managed to fix it by adding chromedriver to the path. I thought it would be the same issue on this linux server but it did not resolve it. I went on to the linux box and verified I can start the chromedriver directly in
"/usr/local/bin/chromedriver"
By the way I have verified I'm on 64-bit linux machine and the symlinks are all set.
Linux version: Linux 3.11.0-26-generic | v2.43.1 | r5163bce
ERROR LOG AFTER RUNNING TEST WITH --verbose
INFO Request: POST /wd/hub/session
- data: {"desiredCapabilities": {"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform": "LINUX","name":"Free Resource Download Test"}}
- headers: {"Content-Type":"application/json; charset=utf-8","Content- Length":151}
ERROR Response 500 POST /wd/hub/session{ status: 13,
sessionId: null,
value:
{ message: 'chrome not reachable\n
So, this is a docker container and a problem is within Chrome&Docker.
you have 2 options, either run add "--privileged" parameter to a Docker or run Chrome with "--no-sandbox" argument.

Resources