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

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
});

Related

Is there any way to get a hook or event in Electron JS when a new application is launched

I'm new to Electron JS. Trying to build a cross-platform desktop application to watch user activities.
My requirement is when a user moves out of my application and opens some other application like a browser/ calculator, is there any way that can be monitored from my application?
Please advice. Thanks
You can use this electron api:
let spawn = require("child_process").spawn;
let bat = spawn("cmd.exe", [
"/c", // Argument for cmd.exe to carry out the specified script
"D:\test.bat", // Path to your file
"argument1" // Optional first argument
]);
bat.stdout.on("data", (data) => {
// Handle data...
});
bat.stderr.on("data", (err) => {
// Handle error...
});
bat.on("exit", (code) => {
// Handle exit
});
Make sure to put the correct path to your batch file (here is an example to find notepad):
tasklist | find /i "notepad.exe" && echo true || echo false
Make sure to handle only false, because true will log notepad.exe info, too.
P.S.: The batch script works only for Windows, I don't know how to create the bash version.

output the cypress browser log messages when running headless in CI

I am using cypress-io and cypress-axe to run browser tests and check if a page has accessibility violations.
I have this task:
function reportA11yViolations(violations: Result[]) {
const errors: string[] = [];
violations.forEach((v: Result) => v.nodes.forEach((node: NodeResult) => {
errors.push(node.failureSummary);
}));
cy.log(errors.join("\n"));
}
Cypress.Commands.add("checkA11yAndReportViolations", (context, options) => {
cy.checkA11y(context, options, reportA11yViolations);
});
I can see all the browser log messages when running through the nice browser app.
But what about when I am running in headless in the ci environment?
Is there anyway I can display these errors anywhere or write them to a file?
You can output the cypress logs to a file
cy.writeFile('accessibilityReport.txt', `${node.failureSummary} \n`, { flag: 'a+' });
a+ will append the result to the file. The build artifacts of the jenkins pipeline should have the report thus created.

PerfJankie:Error: The environment you requested is not available

I am trying to run PerfJankie(wrapper over Browser-Perf) to measure performance of my app.
perfjankie({
suite: 'X',
url: 'http://localhost:8081',
name: job.component,
run: job.version,
prescript: function (browser) {
browser.driver.manage().window().maximize();
},
time: new Date().getTime(),
callback: function (err, res) {
if (err) {
//console.error(err);
throw err;
}
runQueue(i + 1);
},
repeat: 1,
selenium: 'http://localhost:4444/wd/hub',
couch: COUCH,
browsers: [{ // This can also be a ["chrome", "firefox"] or "chrome,firefox"
browserName: 'chrome',
chromeOptions: {
}
}],
actions: function (browser) {
//some actions
}
});
It gives the following error signature:
C:\Users\...\node_modules\perfjankie\node_modules\q\q.js:155
throw e;
^
Error: [init({"browserName":"chrome","chromeOptions":{"perfLoggingPrefs":{"traceCategorie
s":",blink.console,disabled-by-default-devtools.timeline,benchmark"}},"loggingPr
efs":{"performance":"ALL"}})] The environment you requested was unavailable.
My attempts of isolation:
Expected result: this should launch Chrome and validate my app
Observation: Does not launch chrome
Isolation:
This launches firefox(if I specify browser:firefox) but not chrome
or PhatomJS(chrome is my default browser).
Tried specifying binary path for Chrome(as it was suggested in some link i goggled)
Selenuim version: 2.20.0(Below: 2.34.0- i read some link that showed the issue gets resolved below these versions)
Not sure what am I missing.
P.S. I am not sure what tags to add. If someone could help update right tags, that would be great.
I was having a similar issue, try adding this to the capabilities enablePerformanceLogging: true.
This was related to webdriver-manager installation under node modules. I deleted the entire repo, created a fresh copy and this seems to work.
Also perf jankie does not work with protractor-perf

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);
});

Using grunt to run a node server and do cleanup after

So basically this is what I want to do. Have a grunt script that compiles my coffee files to JS. Then run the node server and then, either after the server closes or while it's still running, delete the JS files that were the result of the compilation and only keep the .coffee ones.
I'm having a couple of issues getting it to work. Most importantly, the way I'm currently doing it is this:
grunt.loadNpmTasks("grunt-contrib-coffee");
grunt.registerTask("node", "Starting node server", function () {
var done = this.async();
console.log("test");
var sp = grunt.util.spawn({
cmd: "node",
args: ["index"]
}, function (err, res, code) {
console.log(err, res, code);
done();
});
});
grunt.registerTask("default", ["coffee", "node"]);
The problem here is that the node serer isn't run in the same process as grunt. This matters because I can't just CTRL-C once to terminate JUST the node server.
Ideally, I'd like to have it run in the same process and have the grunt script pause while it's waiting for me to CTRL-C the server. Then, after it's finished, I want grunt to remove the said files.
How can I achieve this?
Edit: Note that the snippet doesn't have the actual removal implemented since I can't get this to work.
If you keep the variable sp in a more global scope, you can define a task node:kill that simply checks whether sp === null (or similar), and if not, does sp.kill(). Then you can simply run the node:kill task after your testing task. You could additionally invoke a separate task that just deletes the generated JS files.
For something similar I used grunt-shell-spawn in conjunction with a shutdown listener.
In your grunt initConfig:
shell: {
runSuperCoolJavaServer:{
command:'java -jar mysupercoolserver.jar',
options: {
async:true //spawn it instead!
}
}
},
Then outside of initConfig, you can set up a listener for when the user ctrl+c's out of your grunt task:
grunt.registerTask("superCoolServerShutdownListener",function(step){
var name = this.name;
if (step === 'exit') process.exit();
else {
process.on("SIGINT",function(){
grunt.log.writeln("").writeln("Shutting down super cool server...");
grunt.task.run(["shell:runSuperCoolJavaServer:kill"]); //the key!
grunt.task.current.async()();
});
}
});
Finally, register the tasks
grunt.registerTask('serverWithKill', [
'runSuperCoolJavaServer',
'superCoolServerShutdownListener']
);

Resources