Given the following file structure, how can you run a basic protractor test? - node.js

I have been trying to follow a tutorial given HERE. However, when I try to start the protractor test given, no tests seem to run at all. My webdriver-manager seems to run perfectly however. Basically nothing happens.
I have tried the following:
node protractor conf.js
node node_modules/protractor conf.js
node node_modules/protractor node_modules/protractor/conf.js
node node_modules/protractor node_modules/protractor/tests/conf.js
None of these work, and the first one throws an error. I've tried putting copies of the files in multiple directories, but none of those seem to work either. I'm no exactly sure what the issue is, but this is how much files are setup.
ui_directory/ <-- This is the overall directory for my web projects
ui_directory/conf.js
ui_directory/todo-spec.js
ui_directory/node_modules/
ui_directory/node_modules/protractor/
ui_directory/node_modules/protractor/conf.js
ui_directory/node_modules/protractor/todo-spec.js
ui_directory/node_modules.protractor/tests/
ui_directory/node_modules.protractor/tests/conf.js
ui_directory/node_modules.protractor/tests/todo-spec.js
What exactly is the proper command to run the tests from the tutorial? All todo-spec.js and conf.js files are the same.
My conf.js file contains the following:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js']
};

Please follow the below steps to run basic protractor Test.
Create a Folder, Say example in Desktop (Folder name is protractor)
Create a config and Spec file with .js extension
Make sure both the files are in Same Location / Folder
Open Command Prompt, And Navigate to project Folder (protractor)
Once navigated to project folder, Type as in bracket:
[protractor config.js] // This will execute protractor Test
Example of Basic Protractor Config File is given as
exports.config = {
//The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
//Here we specify the name of the specs files.
framework: 'jasmine',
specs: ['Protractor_spec.js'],
jasmineNodeOpts: {
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 1440000
},
}

Related

I have 4 test cases added in conf.js file inside spec[] and I have to run 2 test cases from them without removing any test case from conf.js file

there are 4 test cases in my application and I will have to run 2 tests from them, without removing any file from conf.js
Here is the conf.js:
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
// specs: ['spec.js']
specs: ['spec1.js', 'spec2.js', 'spec3.js', 'spec4.js']
}
From the command line, you can then easily switch between running one or two tests. The command will run the spec2 and the spec3:
--specs option expects a comma-separated list of files to test --specs spec2.js,spec3.js.
For instance:
protractor conf.js --specs spec2.js,spec3.js

How can I get jasmine-ts to execute my specs with a specific seed?

I am running unit tests using jasmine-ts version 0.3.0.
The previous version worked fine, but the moment I upgraded, I'd get the output:
No specs found
I found a github issue (and this one) where someone commented:
All arguments passed to jasmine-ts need to have one of these in that argument argv.config || process.env.JASMINE_CONFIG_PATH || "spec/support/jasmine.json";
Indeed, creating a jasmine.json file solved the "No specs issue":
{
"spec_dir": "../src/**/specs",
"spec_files": [
"**/*[sS]pec.ts"
],
"stopSpecOnExecutionFailure": false,
"random": true
}
Running my tests randomly, I discovered that I had some failures, so I wanted to seed the jasmine execution with a specific seed to reproduce the issue.
I tried adding a "seed": 123 config to my jasmine.json, but that didn't work. I found some docs describing what jasmine.json is supposed to look like, and it didn't contain any mention of a seed config.
What did mention seed was the section about command-line options here.
So I tried:
jasmine-ts --seed=123 --config="./jasmine.json"
(Remember, the config file is apparently required - or at least I didn't see any option for specifying where my specs are without using it)
This however did not work as jasmine logged:
Randomized with seed 94263
The config file that I provide apparently overrides the command-line options. I can see this by specifying the option --random=false, but the output still says Randomized with seed ..., since my jasmine.json contains "random": true.
So... I can't specify seed in jasmine.json, and specifying --seed=... has no effect.
How can I set the seed using jasmine-ts 0.3.0 in that case?
Ran into the same problem with regular Jasmine and found that it doesn't copy that in loadConfig for some reason, but there is a method on the jasmine object you create if running it from your own script:
const jasmine = new Jasmine();
jasmine.seed(1234);
As of jasmine-ts version 0.3.2 (here's the closed issue), command line arguments now get forwarded to jasmine, so given a package.json like:
{
...
"scripts": {
"test": "jasmine-ts.cmd --config=jasmine.json"
}
}
You can run npm run test -- --seed=1234 from command line.
Was running into this issue while upgrading to angular 12. I had a particular seed that was failing due to the order of some async tests that weren't properly resolved between executions.
I was able to get a specific seed to run by updating the karma.conf.js file:
client:{
captureConsole: true,
clearContext: false, // leave Jasmine Spec Runner output visible in browser
jasmine: {
seed: 19224, // set value to here and comment out when done
random: false // set this to false while running the seed and switch back to true for normal builds.
}
Doing this was a simple way for me to run a specific jasmine seed.

How to set rootDir as process.cwd() + '/..'

My application was setup as a mono repo. This is the structure:
\mono-repo
|--core
|--app1
|--app2
I run jest at app2. But I also want to run all tests from core. So here is my config
{
rootDir: process.pwd() + '/..',
roots: [ 'core', 'app2' ],
}
But it didn't work.
Could you give me any idea for this case?
Using process.cwd() works for me. It looks like you're using a JSON file rather than a JS file, so it's not interpreting the command. You can also add --showConfig to the jest command for further debugging.

How to parameterise specs in conf.js of Protractor Framework?

I am new to protractor framework,working on parameterising specs in conf.js...seeked help,googled but didn't get a solution...if any one is aware kindly help me...
If you want to run multiple files in protractor better use the naming conventions.
For example if there are two files :
todo-spec.js
log.js
If both files are in D:/Folder
Better name it in following way:
todo-spec.test.js
log.test.js
And for the spec file use the following way:
exports.config ={ specs: ['D:/Folder/*test.js']};
These will make sure that all your files containing test.js as a part of file name will run.
So keep a habit of writing test after every file.
I hope you are clear now. :-)
You can use multicapabilities , if you can:
exports.config = {
specs: [
// keep this blank
],
multiCapabilities: [{
'browserName': 'chrome',
'specs': ['todo-spec.js']
}, {
'browserName': 'chrome',
'specs': ['log.js']
}, {
'browserName': 'chrome',
'specs': ['test.js']
}],
};
I'm not sure if you are familiar with tools like Grunt and Gulp but it sounds to me like you will probably need one of them to do this. If I had the same requirements as you I would setup a Gulp task that opened your excel/csv file and put the file names of the tests you want to run into a list. Then you can use that same gulp task to kick off your protractor tests by using a package like gulp-protractor to run the tests. You will need to work out the logic to get your list of files on your own but here is an example of how to use a gulp task to do this:
gulp.task("e2e", function() {
//logic to get list of spec files here
gulp.src([<array/list of spec files>])
.pipe(protractor({
configFile: "test/protractor.config.js"
}))
.on('error', function(e) { throw e })
})

In nightwatch framework difference nightwatch.conf.BASIC.js vs nightwatch.conf.js

What is the difference between nightwatch.conf.BASIC.js and
nightwatch.conf.js in nightwatch framework.
And what is basic requirement for setup nightwatch framework with
node js and selenium
There is no differences between nightwatch.conf.BASIC.js and nightwatch.conf.js.
You have just to know 5 things:
You can name your config file as you want (nightwatch.conf.BASIC.js, nightwatch.json, nightwatch.conf.js or anything.json or anything.js)
You can have more than 1 config file per project.
When you put your Nightwatch configuration in a file named nightwatch.json or nightwatch.conf.js you don't need to say which configuration file should be used since
A nightwatch.conf.js file or a nightwatch.json file will also be loaded by default, if found.
Just keep in mind that:
The nightwatch.conf.js always takes precedence over
nightwatch.json if both are present.
In this case, you can launch your tests like this:
$> nightwatch
When you put your Nightwatch configuration in an other file, you must tell Nightwatch where are the configurations to use. In this case you need to write your tests like this (for example in Node.js):
module.exports = (function(settings) {
//....
})(require('path/to.your/config/file'));
or
var config = require('path/to.your/config/file');
module.exports = {
//....
};
In this case, you need to specify which configuration file to take when launching tests:
$> nightwatch --config path/to.your/config/file
Since naming your config file nightwatch.conf.js or nightwatch.json doesn't change anything to Nightwatch, is there a reason to choose one and not the other?
Answer: Yes!
Why?: Sometimes you need to write a JavaScript code in your configuration file. In this case your file should be a .js file and not a .json file.
Example of use? When you have many environments to test, maybe you don't want to update many lines to change the same information. So you write a nightwatch.conf.js (The objective is to just change one line when you want to deactivate video instead of going to each environment in a .json file and make changes):
nightwatch_config = {
src_folders : [ "a/file/to/test" ],
selenium : {/*...*/},
common_capabilities: {/*...*/},
test_settings: {
default: {},
chrome: {desiredCapabilities: {browser: "chrome"}},
firefox: {desiredCapabilities: {browser: "firefox"}},
safari: {desiredCapabilities: {browser: "safari"}},
ie: {desiredCapabilities: {browser: "internet explorer"}}
}
};
for(var i in nightwatch_config.test_settings){
var config = nightwatch_config.test_settings[i];
for(var j in nightwatch_config.common_capabilities){
config['desiredCapabilities'][j][browserstack.video] = true;
}
}
module.exports = nightwatch_config;

Resources