Skip to content

Commit

Permalink
Wdio cucumber (testomatio#65)
Browse files Browse the repository at this point in the history
* upd wdio test script

* add wdio-cucumber

* add wdio cucumber

* upd wdio cucumber
  • Loading branch information
olexandr13 authored Apr 10, 2024
1 parent 1c5e931 commit 7d34bd0
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 2 deletions.
1 change: 1 addition & 0 deletions wdio/cucumber/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions wdio/cucumber/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Prepare
`npm i`

### Run
`npm test`
13 changes: 13 additions & 0 deletions wdio/cucumber/features/addNumbers.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@Sad520f3c
Feature: Add number
I want to check if two numbers can be added

@some-tag1 @Tf37e0731
Scenario: Add two positive numbers
When I add two numbers 2 and 3
Then return the sum of 2 and 3 as 5

@some-tag2 @T6e4a0318
Scenario: Should fail
When I add two numbers 2 and 3
Then return the sum of 2 and 3 as 6
34 changes: 34 additions & 0 deletions wdio/cucumber/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"author": "Oleksandr Pelykh",
"license": "MIT",
"name": "wdio-cucumber-example",
"version": "0.0.1",
"description": "Boilerplate project to run WebdriverIO tests with Cucumber and report to Testomat.io",
"scripts": {
"test": "wdio run wdio.conf.ts"
},
"devDependencies": {
"@testomatio/reporter": "file:../../../reporter/testomatio-reporter-1.3.0.tgz",
"@types/chai": "^4.3.14",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"@wdio/cli": "^8.32.2",
"@wdio/config": "^8.32.2",
"@wdio/cucumber-framework": "^8.32.2",
"@wdio/globals": "^8.32.2",
"@wdio/local-runner": "^8.32.2",
"@wdio/spec-reporter": "^8.32.2",
"@wdio/static-server-service": "^8.32.2",
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-wdio": "^8.24.12",
"npm-run-all": "^4.1.5",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"webdriverio": "^8.32.2"
},
"dependencies": {
"chai": "^5.1.0"
}
}
3 changes: 3 additions & 0 deletions wdio/cucumber/src/steps/script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function addTwoNumbers(a: number, b: number) {
return a + b;
}
8 changes: 8 additions & 0 deletions wdio/cucumber/src/steps/then.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Then } from '@cucumber/cucumber';
import { addTwoNumbers } from './script';
import assert from 'assert';

// result should correspond to the sum of the two numbers
Then(/^return the sum of (\d+) and (\d+) as (\d+)$/, (num1: number, num2: number, result: number) => {
assert(addTwoNumbers(num1, num2) === result, 'The result is not correct');
});
7 changes: 7 additions & 0 deletions wdio/cucumber/src/steps/when.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { When } from '@cucumber/cucumber';
import { addTwoNumbers } from './script';

When(
/I add two numbers (\d+) and (\d+)/,
addTwoNumbers
);
75 changes: 75 additions & 0 deletions wdio/cucumber/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"target": "es2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
// "lib": [], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */

/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
"types": [
"node",
"@wdio/globals/types",
"@wdio/cucumber-framework",
"expect-webdriverio"
], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}
176 changes: 176 additions & 0 deletions wdio/cucumber/wdio.conf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import type { Options } from '@wdio/types'
// const testomatio = require('@testomatio/reporter/lib/adapter/wdio-cucumber');
const testomatio = require('@testomatio/reporter/lib/adapter/webdriver');

export const config: Options.Testrunner = {
//
// ====================
// Runner Configuration
// ====================
// WebdriverIO supports running e2e tests as well as unit and component tests.
runner: 'local',
autoCompileOpts: {
autoCompile: true,
tsNodeOpts: {
project: './tsconfig.json',
transpileOnly: true
}
},

//
// ==================
// Specify Test Files
// ==================
// Define which test specs should run. The pattern is relative to the directory
// of the configuration file being run.
//
// The specs are defined as an array of spec files (optionally using wildcards
// that will be expanded). The test for each spec file will be run in a separate
// worker process. In order to have a group of spec files run in the same worker
// process simply enclose them in an array within the specs array.
//
// The path of the spec files will be resolved relative from the directory of
// of the config file unless it's absolute.
//
specs: [
'./features/**/*.feature',
],
// Patterns to exclude.
exclude: [
// 'path/to/excluded/files'
],
//
// ============
// Capabilities
// ============
// Define your capabilities here. WebdriverIO can run multiple capabilities at the same
// time. Depending on the number of capabilities, WebdriverIO launches several test
// sessions. Within your capabilities you can overwrite the spec and exclude options in
// order to group specific specs to a specific capability.
//
// First, you can define how many instances should be started at the same time. Let's
// say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have
// set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec
// files and you set maxInstances to 10, all spec files will get tested at the same time
// and 30 processes will get spawned. The property handles how many capabilities
// from the same test should run tests.
//
maxInstances: 5,
//
// If you have trouble getting all important capabilities together, check out the
// Sauce Labs platform configurator - a great tool to configure your capabilities:
// https://saucelabs.com/platform/platform-configurator
//
capabilities: [{
browserName: 'chrome',
'goog:chromeOptions': {
args: ['headless', 'disable-gpu']
}
}],

//
// ===================
// Test Configurations
// ===================
// Define all options that are relevant for the WebdriverIO instance here
//
// Level of logging verbosity: trace | debug | info | warn | error | silent
logLevel: 'warn',
//
// Set specific log levels per logger
// loggers:
// - webdriver, webdriverio
// - @wdio/browserstack-service, @wdio/devtools-service, @wdio/sauce-service
// - @wdio/mocha-framework, @wdio/jasmine-framework
// - @wdio/local-runner
// - @wdio/sumologic-reporter
// - @wdio/cli, @wdio/config, @wdio/utils
// Level of logging verbosity: trace | debug | info | warn | error | silent
// logLevels: {
// webdriver: 'info',
// '@wdio/appium-service': 'info'
// },
//
// If you only want to run your tests until a specific amount of tests have failed use
// bail (default is 0 - don't bail, run all tests).
bail: 0,
//
// Set a base URL in order to shorten url command calls. If your `url` parameter starts
// with `/`, the base url gets prepended, not including the path portion of your baseUrl.
// If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
// gets prepended directly.
// baseUrl: 'http://localhost:8080',
//
// Default timeout for all waitFor* commands.
waitforTimeout: 10000,
//
// Default timeout in milliseconds for request
// if browser driver or grid doesn't send response
connectionRetryTimeout: 120000,
//
// Default request retries count
connectionRetryCount: 3,
//
// Test runner services
// Services take over a specific job you don't want to take care of. They enhance
// your test setup with almost no effort. Unlike plugins, they don't add new
// commands. Instead, they hook themselves up into the test process.
// services: [],
//
// Framework you want to run your specs with.
// The following are supported: Mocha, Jasmine, and Cucumber
// see also: https://webdriver.io/docs/frameworks
//
// Make sure you have the wdio adapter package for the specific framework installed
// before running any tests.
framework: 'cucumber',

cucumberOpts: {
backtrace: false,
requireModule: [],
failAmbiguousDefinitions: true,
failFast: false,
ignoreUndefinedDefinitions: false,
names: [],
snippets: true,
source: true,
profile: [],
require: [
'./src/steps/then.ts',
'./src/steps/when.ts',
],
scenarioLevelReporter: false,
order: 'defined',
snippetSyntax: undefined,
strict: true,
tagExpression: 'not @Pending',
tagsInTitle: false,
timeout: 20000,
} as WebdriverIO.CucumberOpts,

//
// The number of times to retry the entire specfile when it fails as a whole
// specFileRetries: 1,
//
// Delay in seconds between the spec file retry attempts
// specFileRetriesDelay: 0,
//
// Whether or not retried spec files should be retried immediately or deferred to the end of the queue
// specFileRetriesDeferred: false,
//
// Test reporter for stdout.
// The only one supported by default is 'dot'
// see also: https://webdriver.io/docs/dot-reporter
reporters: ['spec',
[testomatio, {
apiKey: `${process.env.TESTOMATIO}`
}]
],

// Options to be passed to Mocha.
// See the full list at http://mochajs.org/
mochaOpts: {
ui: 'bdd',
timeout: 60000
},
}
3 changes: 1 addition & 2 deletions wdio/v8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "Example project for Testomat.io with WebdriverIO v8",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wdio": "wdio run ./wdio.conf.ts"
"test": "npx start-test-run -c 'wdio run ./wdio.conf.ts'"
},
"author": "Oleksandr Pelykh / Testomat.io",
"license": "ISC",
Expand Down

0 comments on commit 7d34bd0

Please sign in to comment.