How to run a specific test case from a test suite using InternIO - testing

Currently, I have a few test suites. To avoid running an entire test suite - how can I run just a single test case from a suite. My current workaround is to comment out test cases I don't want.
My intern.js file:
define({
environments: [
{ browserName: 'chrome'},
],
useSauceConnect: false,
//functionalSuites: ['tests/projects/projectA/main.js'],
tunnel: 'NullTunnel',
excludeInstrumentation: /./
});
The following is my main.js file:
define([
'intern',
'intern!object',
'intern/chai!assert'
],
function (intern, registerSuite, assert) {
registerSuite(function () {
var someLib;
return {
setup: function () {
},
'TC001 - Functionality 1': function () {
},
'TC002 - Functionality 2': function() {
},
'TC003 - Functionality 3': function() {
},
};
});
});
I am running this by using the command-line: To run - I issue the following command:
$ node_modules/.bin/intern-runner config=tests/intern functionalSuites=tests/projects/projectA/main.js
Is there a way to run say only "TC001 - Functionality 1" and other selected test cases without commenting out the other tests cases from the suite?

You can use the grep command line option. The grep option specifies a regular expression that filters on test ID (test IDs that match are run), giving you a lot of flexibility when specifying which tests will run. At it's simplest, you can just provide a short string, and Intern will run any tests with IDs containing that string:
$ node_modules/.bin/intern-runner config=tests/intern functionalSuites=tests/projects/projectA/main grep=TC001

Related

How to run Playwright in headless mode?

I created a new Vue app using npm init vue#latest and selected Playwright for e2e tests. I removed firefox and webkit from projects in the playwright.config.ts file, so it will only use chromium.
Running npm run test:e2e works fine, the process exists with a success code.
When forcing the tests to fail by modifying the ./e2e/vue.spec.ts file the output is
but the process does not exit with an error code, it still opened browser windows and so CI environments would freeze.
I searched the docs for a specific flag e.g. "headless" and tried --max-failures -x but that didn't help.
How can I tell Playwright to run in headless mode and exit with an error code when something failed?
Since playwright.config.ts already makes use of process.env.CI I thought about replacing reporter: "html", with reporter: [["html", { open: !process.env.CI ? "on-failure" : "never" }]],
but which arguments should I add to the script "test:e2e:ci": "playwright test", to ensure process.env.CI is set?
Update
I tried to run the script inside my CI environment and it seems to work out of the box ( I don't know how it sets the CI environment flag but the pipeline did not freeze )
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Check if e2e tests are passing
run: npm run test:e2e
If any test fails it exists with an error code
It's serving the html report and asking to press 'Ctr+C' to quite.You can disable it using below configuration.
// playwright.config.ts
import { PlaywrightTestConfig } from '#playwright/test';
const config: PlaywrightTestConfig = {
reporter: [ ['html', { open: 'never' }] ],
};
export default config;
Refer - Report Doc
Issue - https://github.com/microsoft/playwright/issues/9702
To add to the answer above, you can set headless: true in the 'use' block of the config which is above the projects block. Anything set at that level will apply to all projects unless you specifically override the setting inside a project specific area:
// playwright.config.ts
import { PlaywrightTestConfig } from '#playwright/test';
const config: PlaywrightTestConfig = {
reporter: [ ['html', { open: 'never' }] ],
use: {
headless: true,
},
projects: [
{
name: 'chromium',
use: {
browserName: 'chromium',
},
},
},
};
export default config;

How to skip protractor+jasmine tests specific to browsers

Assume that I've automated 25 tests and executing in multiple browsers like chrome, firefox, IE, Edge & Safari. All tests (25) are executing well on Chrome. In Firefox, Only 20 tests are running fine due to few protractor APIs are not supported. Similarly IE can execute only 23 tests.
I would like to skip the test only for browsers, which are not supported for particular test? Is there any way available?
You can create protracotr.conf file for each browser with specific suites where will be specified what tests should run. And execute in one time all protractor.conf files.
//protractor.chrome.conf
export let config: Config = {
...
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 1
},
SELENIUM_PROMISE_MANAGER: false,
specs: [
'../test/chrome/**/*.js'
]
};
and
//protractor.ie.conf
export let config: Config = {
...
capabilities: {
browserName: 'internet explorer',
shardTestFiles: true,
maxInstances: 1
},
SELENIUM_PROMISE_MANAGER: false,
specs: [
'../test/ie/**/*.js'
]
};
in your package.json:
{
...
"scripts": {
"test:all": "npm run test:chrome && test:ie",
"test:chrome": "protractor ./config/protractor.chrome.conf.js",
"test:ie": "protractor ./config/protractor.ie.conf.js",
...
},
...
}
With jasmine2 you can filter tests using a regular expression. Maybe you can add something like #chrome, #ie to your tests and then only run those ones by passing the grep flag:
it('should do stuff #ie #chrome', function() {
...
});
Then run protractor passing the grep flag:
protractor conf.js --grep='#ie'

Webdriver.io test runner - exclude suite from specific capability

My webdriver.io test runner is organized into suites, and I want to exclude a suite from a specific capability.
For example, I have a suite called suite1:
//
suites: {
suite1: [
'./test/spec/*.js',
],
},
//
And I want to exclude this suite from the Safari capability:
//
{
'tunnelIdentifier' : sltunnel,
'browserName': 'safari',
'version': '10',
'platform': 'OS X 10.12',
'screenResolution': '1600x1200',
'exclude': [
suite1,
],
},
//
Is there a way to achieve this?
Of course there are multiple ways to do this, but at the end of the day it's all up to you.
You can drag your entire suite logic outside of your wdio.conf.js file into a separate config file (I'm sure you might already have one for your environments: test, prod, w/e) and then import it (via require into your wdio.conf.js file):
So let's say you have suites.conf.js file:
module.exports.suites = {
// 1 => run the suite
// 0 => don't run it
"chrome": {
"0": [
"<yourSuiteName-001>.js"
"<yourSuiteName-003>.js"
"<yourSuiteName-005>.js"
],
"1": [
"<yourSuiteName-002>.js"
"<yourSuiteName-004>.js"
]
},
"safari" : {
"0": [
"<yourSuiteName-002>.js"
"<yourSuiteName-004>.js"
"<yourSuiteName-005>.js"
],
"1": [
"<yourSuiteName-001>.js"
"<yourSuiteName-003>.js"
]
}
// <etc>
}
Then you import it into your wdio.conf.js file (var suites = require(./<pathToSuitesConfig>/suites.conf.js);), cycle with a forEach through all your suites and based on your browserName, create a buffer in which you store the runable suites as they match your condition, then add them into the config file. This logic will go in your wdio.conf.js header section and you can update the exportable config via the results.
I just thought of this in like 5 minutes, so I'm sure there's multiple cleaner ways to achieve this.
Alternatively, you can look at other test-runners that are easy to plug into WebdriverIO and which have tagging:
Cucumber has a great tagging mechanism (due to Gherkin syntax);
Mocha has something similar called, you guessed it tagging.

How to pass arguments from grunt to node.js app using grunt-express-server

I met an issue where I need to start my express server with arguments using grunt-express-server. How could I do that?
I tried to use the option "args" but it seems it doesn't work for me. Here are some simple codes for this issue.
In my Gruntfile.js, I just did this:
grunt.initConfig({
pkg: grunt.file.readJSON('proxy.json'),
express: {
dev: {
options: {
script: 'testServer.js',
background: false,
args: ['test.json'], // I assume it may run "node testServer.js test.json"
}
}
})
And in my testServer.js file, I just want to print out the arguments:
var m = require('./startServer.js');
process.argv.forEach(function (val, index, array) {
console.log(array);
});
m.start();
However, everytime when I run "grunt express:dev", the server could be started, however, it always prints out
[ 'node', '/usr/local/bin/grunt', 'express:dev' ]
instead of something like
[ 'node', 'testServer.js', 'test.json' ]
Do you have any idea how I could solve this issue?

Protractor pointing to Sauce Labs Selenium Server

I'm trying to integrate Protractor with Sauce Labs from Travis. I can get the sauce_connect server running correctly but am unable to get Travis to point to that particular remote server.
Travis will get to the point where it initiates sauce_connect but when I run "protractor:analytics" it doesn't point to the correct server and fails.
Travis.yml:
language: python
python:
- 3.2_with_system_site_packages
branches:
only:
- develop
before_install:
- sudo apt-get update -qq
- sudo apt-get install python-numpy
install:
- cd lib && python setup.py install
- cd .. && pip install -r requirements/travis_requirements.txt
- npm install
script:
- grunt karma:single
- grunt protractor:analytics
env:
global:
- secure: <string>
- secure: <string>
sauce_connect: true
Gruntfile:
protractor: {
options: {
configFile: './webapp/static/test/e2e/protractor.conf.js',
keepAlive: true
},
singlerun: {},
analytics: {
options: {
//debug : true,
args:{
specs: ['./webapp/static/test/e2e/analytics_spec.js']
}
}
},
},
Protractor Conf:
exports.config = {
chromeOnly: false,
seleniumArgs: [],
// If sauceUser and sauceKey are specified, seleniumServerJar will be ignored.
// The tests will be run remotely using SauceLabs.
sauceUser: process.env.SAUCE_USER,
sauceKey: process.env.SAUCE_KEY,
baseUrl: 'http://localhost:8000',
specs: [
'./*_spec.js',
],
// Patterns to exclude.
exclude: [],
multiCapabilities: [],
// ----- More information for your tests ----
//
// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
baseUrl: process.env.SN_BASE_URL,
// Selector for the element housing the angular app - this defaults to
// body, but is necessary if ng-app is on a descendant of <body>
rootElement: 'body',
// A callback function called once protractor is ready and available, and
// before the specs are executed
// You can specify a file containing code to run by setting onPrepare to
// the filename string.
onPrepare: function() {
// At this point, global 'protractor' object will be set up, and jasmine
// will be available. For example, you can add a Jasmine reporter with:
// jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter(
// 'outputdir/', true, true));
},
// The params object will be passed directly to the protractor instance,
// and can be accessed from your test. It is an arbitrary object and can
// contain anything you may need in your test.
// This can be changed via the command line as:
// --params.login.user 'Joe'
params: {
login: {
user: process.env.SN_TEST_USERNAME,
password: process.env.SN_TEST_PASSWORD
}
},
framework: 'jasmine',
// ----- Options to be passed to minijasminenode -----
//
// See the full list at https://github.com/juliemr/minijasminenode
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: false,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 30000
},
onCleanUp: function() {}
};
If I did understand well : Sauce connect tool is not used by protractor/selenium when running a test suite.
Well I had this problem, travis requires sauce credentials and protractor requires those credentials and a tunnel id:
.travis.yml:
addons:
sauce_connect:
username: xxx
access_key: xxx
protractor.conf.js:
exports.config = {
...
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,
capabilities: {
...
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
}
}