failed reason or exception is not getting displayed when working with Protractor Cucumber - protractor

i am trying to work with protractor-cucumber framework and when i executing the script.. even though the script is fine still script is failing and it is not giving the failure reason or exception
Same thing is working fine with Jasmine but when it comes to protractor-cucumber it is working like this
My Config File
exports.config = {
//seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
directConnect:true,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('C:\\...\\node_modules\\protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
ignoreUncaughtExceptions:true,
// Spec patterns are relative to this directory.
specs: [
'./learnFramework/utility/test.feature'
],
cucumberOpts: {
require: './learnFramework/TestCases/spec.js',
tags: false,
profile: false,
'no-source': true
},
onPrepare: function () {
browser.ignoreSynchronization=true;
}
};
My Spec file
module.exports=function(){
this.Given(/^Open the browser$/,async function(){
browser.ignoreSynchronization=true;
});
this.Given(/^Load the URL$/,async function(){
browser.get("https://google.com");
console.log(await browser.getTitle());
})
}
When i executing the script it is opening the chrome browser and loading the url also but don't know why it is getting failed and it is not even giving the result of the test
Execution Result
I want to use this template for my feature file
Scenario: Title of your scenario
✓ Given Open the browser
✖ And Load the URL
Failures:
[09:15:48] I/launcher - 0 instance(s) of WebDriver still running
[09:15:48] I/launcher - chrome #01 failed 1 test(s)
[09:15:48] I/launcher - overall: 1 failed spec(s)
[09:15:48] E/launcher - Process exited with error code 1
And I'm using the grunt file for execution..
so someone please help me to come out from this issue

await browser.get("https://google.com");
You need to await for the broswer to go to google.

Related

Specs not found in using scripts tag in package.json for Protractor

In pretest command "tsc" i have used so that file should convert to js. This command changes ts code to js. Now in config js file specs extension remains TS example- file "testspec.ts" not js. extension is not changing. Due to this i am facing specs not found. Extension should also change in configuration.js of specs file.How can i resolve this, so that i just have to give command npm run test and my testcase executes.
Code of package.json
{
"name": "protractortypescriptcucumberframework",
"version": "1.0.0",
"description": "cucumberframework",
"main": "index.js",
"scripts": {
"test": "protractor JSFiles/configuration.js",
"pretest": "tsc",
"protractor":"./node_modules/protractor/built/cli.js",
"webdriver-update":"./node_modules/.bin/webdriver-manager update"
},
"author": "ak",
"license": "ISC",
"dependencies": {
"protractor": "^7.0.0",
"typescript": "~3.9.6",
"jasmine": "~3.5.0",
"#types/jasmine": "~3.5.11",
"#types/jasminewd2": "~2.0.8",
"ts-node": "~8.10.2",
"#types/node": "~14.0.23"
}
}
Error i face is below after command > npm run test
> protractortypescriptcucumberframework#1.0.0 pretest C:\Users\Admin\Eclipse Protractor JavaScript\ProtractorTypeScriptCucumberFramework
> tsc
> protractortypescriptcucumberframework#1.0.0 test C:\Users\Admin\Eclipse Protractor JavaScript\ProtractorTypeScriptCucumberFramework
> protractor JSFiles/configuration.js
[13:49:25] I/launcher - Running 1 instances of WebDriver
[13:49:25] I/direct - Using ChromeDriver directly...
DevTools listening on ws://127.0.0.1:49802/devtools/browser/9a9f6b17-da99-4aec-993c-a265017ee716
> protractortypescriptcucumberframework#1.0.0 test C:\Users\Admin\Eclipse Protractor JavaScript\ProtractorTypeScriptCucumberFramework
> protractor JSFiles/configuration.js
[13:49:25] I/launcher - Running 1 instances of WebDriver
[13:49:25] I/direct - Using ChromeDriver directly...
DevTools listening on ws://127.0.0.1:49802/devtools/browser/9a9f6b17-da99-4aec-993c-a265017ee716
Started
No specs found
Finished in 0.218 seconds
[13:49:49] I/launcher - 0 instance(s) of WebDriver still running
[13:49:49] I/launcher - chrome #01 passed
Config file code.
import {Config} from "protractor";
// An example configuration file
export let config: Config = {
// The address of a running selenium server.
//seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect:true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'chrome'
},
// Spec patterns are relative to the configuration file location passed
// to protractor (in this example conf.js).
// They may include glob patterns.
specs: ['testspec.ts'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
}
};
I figured out the error.
In config file of ts extension need to pass spec with js extension only. scripts tag will not automatically change spec extension. It has to be passed by user in config ts file.

How to use Protractor for Chrome, FF, IE?

How do I Run Chrome, FF, IE browsers for test execution?
I have been using directConnect: true for Chrome and FF; and I'm aware that if this is set when I try and run IE, then it will throw and error. From what I understand, I need to have directConnect: true in order to use Chrome and FF.
I've been trying to figure the conf.js file with multiCapabilities for all 3 browsers, but cant seen to figure how to get all 3 of then to run the test.
multiCapabilities : [
{
'browserName' : 'chrome'
}, {
'browserName': 'internet explorer',
'platform': 'ANY',
'version': '11',
},
{ 'browserName': 'firefox'
}
],
Any suggestions please?
You can use separate conf.js files for different browsers.
Also I have separate folder for reporting and run them one after another.
This is one approach. Other is to run them in parallel using selenium server.

AngularCLI Karma tests not running on circle CI

I am running karma tests using following Angular script but I get error karma start ./karma.conf.js ERROR [config]: Error in config file! Unexpected token =]
The file runs fine on my windows local machine but gives error when I put it on Bitbucket and run it using Circle CI (continuous Integration)
I do notice that when I change karma.conf.js and put it on bitbucket, I get following warning
C:\Users\Manu\Documents\manu\programs\web\angular\dw-ng2-app>git add --all
warning: LF will be replaced by CRLF in karma.conf.js.
The file will have its original line endings in your working directory.
Karma file is
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '#angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('#angular/cli/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
the problem seemed to be in the config file I created for CircleCI. See npm install fails in circle ci (angular cli project)

Protractor-CucumberJS - Tagged scenarios - Browser Launched for Scenarios not Tagged

We have a Protractor-CucumberJS framework using BDD feature files and need to create a suite of sanity tests by tagging the relevant scenarios as '#sanity' in feature files and run only the scenarios with this tag.
With this setup, Protractor launches the browser for each feature file one by one, checks if it contains the '#sanity' tag and closes the browser if tag not found and so on.
This will take up a lot of time as there are close to 200 feature files and hence we want the the browser to launch only if the feature file contains the required tag and not otherwise.
Is there a way to achieve that.
Config file -
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
specs: [../features/*.feature]
cucumberOpts: {
require: [
'../step-definitions/**/*_Steps.js',
'generateJsonReport.js'
],
format: 'pretty',
tags: ['#sanity'],
},
multiCapabilities: [{
browserName: 'chrome',
shardTestFiles: true,
}
],
onPrepare: function () {
browser.driver.manage().window().setSize(1600, 800);
}
};
This is not possible due to the fact that you are using the option shardTestFiles:true, see the config.
If you disable it, or remove it, it will first search all the files (without parsing all files and opening a browser for it) for your specific tag and only run the featurefiles that have that tag.
Use tags:'#sanity', in Conf file, This will call only Sanity features

How to run particular protractor test case from command prompt

I am successfully able to run the protractor scripts. Below is the protractor.config.js file which I am using to run the protractor scripts.
var Jasmine2Reporter = require('protractor-jasmine2-screenshot-reporter');
var HtmlReporter = require('protractor-html-screenshot-reporter');
var jReporter=new Jasmine2Reporter({
dest: './protractor-result',
fileName: 'protractor-demo-tests-report.html'
});
var reporter=new HtmlReporter({
baseDirectory: './protractor-result', // a location to store screen shots.
docTitle: 'Protractor Demo Reporter',
docName: 'protractor-demo-tests-report.html'
});
exports.config = {
allScriptsTimeout: 11000,
specs: [
'testCaseOne.spec.js' // Hardcoded to run single script.
'*.spec.js' // to run all scripts.
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8000/app/',
framework: 'jasmine2',
};
I am successfully able to run the protractor scripts. Below is the protractor.config.js file which I am using to run the protractor scripts
To run above file, I used below command.
$ npm run protractor
My Expectation:
Now, I would like to run the single protractor script from command prompt. How this can be achieved? This will be useful when I will try to run the protractor test cases from any test management tool.
Can anyone please help me on this.
Try this:
protractor protractor.conf.js --specs='specs/run-just-this-spec.js'
If you want to run a specific test you need use jasmine2 and pass the grep option. https://github.com/angular/protractor/blob/19139272d190dd9c1888d9c3fc2f480f7c6c8edb/docs/jasmine-upgrade.md
Additionally to the given answers, you can use suites, which are sets of specs:
You can have suites which consist only of one spec.
You can run particular spec like this:
protractor --suite=my-suite-name
Also you can temporarily exclude suite or spec in Jasmine using xdescribe and xit (just type x before describe or it).
Also you can focus on particular suite or spec in Jasmin using fdescribe and fit (just type f before describe or it).
Use the node.js process.env object.
var w00t = process.env.TESTED || '*';
exports.config = {
allScriptsTimeout: 11000,
specs: [
w00t + '.spec.js'
],
Prepend TESTED=testCaseOn when you start protractor to execute the desired spec. To execute all scripts add nothing so that *.spec.js will be called.