Failed to create session. unknown error: Chrome failed to start: was killed. (unknown error: DevToolsActivePort file doesn't exist) - node.js

I'm executing an automated test with Electron by using Selenium by using the following code:
const webdriver = require('selenium-webdriver');
var Application = require('spectron').Application;
var assert = require('assert');
const driver = new webdriver.Builder()
// The "9515" is the port opened by chrome driver.
.usingServer('http://localhost:9515')
.withCapabilities({
'goog:chromeOptions': {
// Here is the path to your Electron binary.
binary: 'C:/Program Files/Google/Chrome/Application/chrome.exe',
},
})
.forBrowser('electron') // note: use .forBrowser('electron') for selenium-webdriver <= 3.6.0
.build();
describe('Application launch', function () {
var app;
jest.setTimeout(30000);
beforeEach(function () {
app = new Application({
path: 'node_modules/.bin/electron',
args: ['--headless', '--no-sandbox', '--disable-dev-shm-usage'],
});
return app.start();
});
afterEach(function () {
if (app && app.isRunning()) {
return app.stop();
}
});
it('click a button', function* () {
yield driver.sleep(5000);
});
});
But I'm obtaining the following error:
yarn run v1.22.19
warning package.json: License should be a valid SPDX license expression
warning ..\..\..\package.json: No license field
$ jest --NODE_ENV=test
FAIL src/__test__/App.spec.jsx (10.623 s)
Application launch
× click a button (6564 ms)
● Application launch › click a button
Failed to create session.
unknown error: Chrome failed to start: was killed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Users\vipul\appname\src\node_modules\spectron\lib\launcher.bat is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
at startWebDriverSession (src/node_modules/webdriver/build/utils.js:72:15)
at Function.newSession (src/node_modules/webdriver/build/index.js:58:45)
at Object.remote (src/node_modules/webdriverio/build/index.js:73:22)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 11.878 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I've tried to add even the args suggested by several answers in other stackoverflow questions like --headless or --no-sandbox but even those not worked.

Try this file
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--no-sandbox");
options.add_argument("--headless")
options.add_argument("--disable-setuid-sandbox")
options.add_argument("--remote-debugging-port=9222") # this
options.add_argument("--disable-extensions")
#options.add_argument("--headless")
options.add_argument("--disable-gpu")
options.add_argument("enable-automation")
options.add_argument("--disable-infos")
options.add_argument("--disable-dev-shm-usage")
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://www.google.com/")
element_text = driver.page_source
print(element_text)

Related

Synology NodeJS Selenium - Server terminated early with status 127

I read a lot of similar issue but nothing indicate works ...
I'm on Synology - DSM 7.1 (Debian) and my code is
const chrome = require('selenium-webdriver/chrome');
const chromedriver = require('chromedriver');
const webdriver = require('selenium-webdriver');
//const path = require('chromedriver').path;
const {By, until, Builder} = require('selenium-webdriver');
exports.getInfoFromUrl = async(url) => {
// Lancement du webdriver pour scrapper Bet Assistant
//let service = new chrome.ServiceBuilder().build();
//chrome.setDefaultService(service);
//var driver = new webdriver.Builder(path).withCapabilities(webdriver.Capabilities.chrome()).build();
const options = new chrome.Options();
options.addArguments(
'--no-sandbox',
'headless',
'disable-gpu',
'--disable-dev-shm-usage'
);
var driver = new webdriver.Builder(chromedriver.path)
//.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(options)
.build();
/*chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());
var driver = new webdriver.Builder(chromedriver.path)
.setChromeOptions(new chrome.Options().addArguments(['--no-sandbox','-headless', '--disable-dev-shm-usage']))
.build();
*/
driver.get(url);
}
When I execute this code with "node script.js" I get this error :
/volume1/web/betassistant/node_modules/selenium-webdriver/remote/index.js:248
reject(Error(e.message))
^
Error: Server terminated early with status 127
at /volume1/web/betassistant/node_modules/selenium-webdriver/remote/index.js:248:24
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I try several sample or code to run webdriver but nothing works. I see some of user install "default-jre" (How do I solve "Server terminated early with status 127" when running node.js on Linux?) but I don't have "apt-get" and I think JRE don't be need on DSM.
Some help will be appreciate :)

playwright firefox.launchPersistentContext timeout

I want to open a context using playwright firefox based on an session dir, on my pc, it work perfectly, but on 3 diffrent remote desktop connection pc (vps windows server) there are an error. The browser is open after 30s it say the error :
browserType.launchPersistentContext: Timeout 30000ms exceeded.
=========================== logs ===========================
<launching> C:\Users\Administrator\AppData\Local\ms-playwright\firefox-1322\firefox\firefox.exe -no-remote -wait-for-browser -foreground -profile ./browser_data/thread-test -juggler-pipe about:blank
<launched> pid=924
[pid=924][out]
[pid=924][out] Juggler listening to the pipe
[pid=924][err] IPDL protocol Error: Received an invalid file descriptor
[pid=924][err] IPDL protocol Error: Received an invalid file descriptor
[pid=924][err] IPDL protocol Error: Received an invalid file descriptor
============================================================
at async C:\Users\Administrator\Desktop\gen\index.js:128:23 {
name: 'TimeoutError'
}
error image
The code that I use :
const {firefox} = require('playwright')
const context = await firefox.launchPersistentContext('./browser_data/thread-test', {headless:false,});
I think there is an error on connect browser to playwright step but I don't know how to fix...
Thank you for your help !
import { rm } from 'fs';
import { firefox } from 'playwright';
rm('/context/sessionstore-backups', () => {});
rm('/context/sessionCheckpoints.json', () => {});
rm('/context/sessionstore.jsonlz4', () => {});
context = await firefox.launchPersistentContext(
'/context',
{ headless: false }
);
page = context.pages()[0];
Acctually, we need to remove sessionstore-backups and sessionstore.jsonlz4 in the userDataDir folder

Protractor error : BUG: launcher exited with 1 tasks remaining for my simple first test

I run the below simple config/step and feature file for my first protractor test which is trying to recognize my feature file and console output.
I am getting the error BUG: launcher exited with 1 tasks remaining.
I am not sure what is going on here. Some help is appreciated.
Feature file
Feature: Verify the Test Room Javascript application
Scenario: Check the input text field
Given I go to Test Run Application TC001
When I enter text on the Input field TC001
Step file
module.exports = function (){
this.Given(/^I go to Test Run Application TC001$/, function(){
browser.ignoreSynchronization = true;
browser.get("https://www.thetestroom.com/jswebapp/");
browser.sleep(8000);
console.log("The testroom application opened");
callback();
});
this.When(/^I enter text on the Input field TC001$/, function() {
console.log("Trying to find the input field");
});
and my config file:
exports.config = {
chromeDriver: '/usr/local/lib/node_modules/protractor/selenium/chromedriver',
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'cucumber',
capabilities: {
browserName: 'chrome'
},
specs: ['testrun.feature'],
cucumberOpts: {
require: ['testrun_steps.js'],
}
}
I get the below error when I run the testrun_conf.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
Feature: Verify the Test Room Javascript application
Scenario: Check the input text field # testrun.feature:3
The testroom application opened
[launcher] BUG: launcher exited with 1 tasks remaining
Make sure you are not using something like:
this.AfterFeatures(function() {
browser.close(); // not required
});

How run two Chrome driver for one profile with Selenium Webdriver Nodejs?

I write tests, and for the speed, i want, that user has already been authenticated (+ loaded data in local store).
import * as webdriver from 'selenium-webdriver';
import * as Chrome from 'selenium-webdriver/chrome';
var options = new Chrome.Options();
options.addArguments('--user-data-dir=C:\\profilepath');
var driver = new webdriver.Builder().withCapabilities(options.toCapabilities()).build();
driver.get("http://site.ru/").then(() => {
console.log('Opened');
}, (err) => {
console.log('Err', err);
});
var driver2 = new webdriver.Builder().withCapabilities(options.toCapabilities()).build();
driver2.get("http://site.ru/").then(() => {
console.log('Opened');
}, (err) => {
console.log('Error', err);
});
The first driver works good, opens the page, the second just hanging initial screen without any errors. Same for starts them in different processes ...
You have two entities working at cross-purpose here: Chrome and Selenium.
If you run Chrome from the command line and start it twice with the same profile, the second time you start it, Chrome is going to detect that there is already a Chrome instance running with the profile you selected and will instruct this Chrome instance to open a new window. I don't know what you'd see on the console on Windows but on Linux, the second time you try to start Chrome, you get this on the console:
Created new window in existing browser session.
So although it looks like you have a different Chrome instance, in fact you just have one instance with two windows. I do not believe it is possible to force Chrome to spawn a second instance with the same profile.
Then you have Selenium. When you use Builder to create a new Selenium instance, Selenium executes Chrome but as you already know from what I explained above, the 2nd time you do it, Chrome just opens a new window in the first Chrome instance you started. Selenium does not detect this but tries to connect to the browser to control it. However, Selenium already connected to the browser when you asked it to spawn the first Chrome instance, and it cannot connect again to the same instance. If you wait long enough, a timeout will occur and Selenium will report:
Error { [UnknownError: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.13.307649 (bf55b442bb6b5c923249dd7870d6a107678bfbb6),platform=Linux 4.0.0-2-amd64 x86_64)]
code: 13,
state: 'unknown error',
message: 'unknown error: Chrome failed to start: exited abnormally\n (Driver info: chromedriver=2.13.307649 (bf55b442bb6b5c923249dd7870d6a107678bf
6_64)',
name: 'UnknownError',
[...]
If your profile contains the credentials you need before you start your Selenium script, what you could do is just copy the profile to a new location for your second Chrome instance. It could look like this:
import * as webdriver from 'selenium-webdriver';
import * as Chrome from 'selenium-webdriver/chrome';
import * as fs_extra from 'fs-extra';
// Copy the profile to a new location for the new instance.
fs_extra.copySync("/tmp/t6/foo", "/tmp/t6/foo2");
var options = new Chrome.Options();
options.addArguments('--user-data-dir=/tmp/t6/foo');
var driver = new webdriver.Builder().withCapabilities(options.toCapabilities()).build();
driver.get("http://google.com/").then(() => {
console.log('Opened');
}, (err) => {
console.log('Err', err);
});
var options2 = new Chrome.Options();
options2.addArguments('--user-data-dir=/tmp/t6/foo2');
var driver2 = new webdriver.Builder().withCapabilities(options2.toCapabilities()).build();
driver2.get("http://example.com/").then(() => {
console.log('Opened');
}, (err) => {
console.log('Error', err);
});

Error Message : Unable to find element with xpath in phantomsJS

I am using simple NodeJS script for testing google.com. phantomJS browser is used.
var webdriver = require('selenium-webdriver');
var assert = require('assert');
var driver = new webdriver.Builder().
withCapabilities({
browserName : "phantomjs"
}).
usingServer('http://127.0.0.1:4444/wd/hub').build();
//driver.manage().timeouts().implicitlyWait(60000);
driver.get('http://www.google.com');
driver.findElement(webdriver.By.xpath('//*[#id="gbqf"]')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.getTitle().then(function(title) {
assert.equal("webdriver - Google Search", title);
});
driver.quit();
Running the standalone selenium server using
> java -jar selenium-server-standalone-2.35.0.jar
Running the script parallelly using node command.
I am getting the following error
> timers.js:103
> if (!process.listeners('uncaughtException').length) throw e;
> ^ UnknownError: Error Message => 'Unable to find element with xpath
> '//*[#id="gbqf"]'' caused by Request =>
> {"headers":{"Accept":"application/json,
> image/png","Connection":"Keep-Alive","Content-Length":"45","Content-Type":"application/json;
> charset=utf-8","Host":"localhost:17476"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"xpath\",\"value\":\"//*[#id=\\\"gbqf\\\"]\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/440b8b90-0fc8-11e3-8024-5bdaea20ab82/element"}
> Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12
> 15:42:01' System info: os.name: 'Linux', os.arch: 'i386', os.version:
> '2.6.18-8.el5', java.version: '1.6.0_16' Driver info: driver.version:
Is there a chance the page has not fully loaded as I know that when I go to google.com, it redirects me to my local google.co.uk site.
Strictly for debugging purposes, put a sleep of 5 seconds before the findElement command. If that then works, replace with a webdriverWait until the object appears on screen.
However, I have also noticed that you are sending the keys to the "form" element. Will this work? Do you not want to send keys to the input field?
Assert that you are actually on the URL that you expect to be on prior to calling the findElement command.

Resources