UI Test Using Vyper
how to run
-
JDK
-
Node.js
-
OpenSSL: It is required when it comes to measure the coverage.
Cloning the Vyper Master-Branch
GithubRepo: https://github.wdf.sap.corp/sProcurement/vyperForAll
After cloning, make sure to run the setup file (Setup.vbs or Setup.sh).
Create a file named protractor.bat with content shown below and add it as your system environment variable.
folder:VyperForAllmaster… 工具
folder:vyper… case and config
command:
node VyperForAllmaster/protractor/bin/protractor vyper/config.js
Recording
Enabling the UI5 Inspector
Vyper uses the UI5 Inspector as UI5-Control locator and is also responsiable for the recoring of vyper scripts.
To add the Vyper-UI5-Inspector to your chrome please do the following:
- Open the Vyper directory
- You’ll find a folder called “Chrome Extension” with a sub-folder called “Vyper_ChromeExtension”.
- Open your extension management page in Chrome and drag the “Vyper_ChromeExtension” folder to your chrome extension area.
- Enable the UI5-Inspector extension.
vyper/config.js
// An example configuration file.
exports.config = {
directConnect: true,
// restartBrowserBetweenTests: false,
// Capabilities to be passed to the webdriver instance [1]
capabilities: {
browserName: 'chrome',
chromeOptions: {
// args: ['--headless']
}
},
params: {
auth: {
// settings for the authorizations and the test type E2E/UI-Component Test [2]
formType: 'plain'
// formType: 'fiori-form',
// username: 'username',
// password: 'password'
},
// settings for the coverage [3]
coverage: false,
maximizeWindow: true
},
SELENIUM_PROMISE_MANAGER: false,
// url for script execution [4]
/* eslint-disable sap-no-hardcoded-url */
// baseUrl: 'http://localhost:8083/index.html',
baseUrl:
'https://security-self-billing-approuter-qa.internal.cfapps.sap.hana.ondemand.com/cp.portal/site#Shell-home',
// baseUrl:
// 'https://security-self-billing-approuter.cfapps.sap.hana.ondemand.com/cp.portal/site#Shell-home',
// Framework to use. Jasmine is recommended.
framework: 'jasmine2',
// Spec patterns are relative to the current working directory when [5]
// protractor is called.
// specs: ['test.spec.js'],
//<- you have to change the name of the spec ofc.,
specs: ['login.spec.js', 'test.spec.js'],
// specs: ['testa.spec.js'], //<- you have to change the name of the spec ofc.
// Options to be passed to Jasmine.
getPageTimeout: 3000000,
allScriptsTimeout: 3000000,
jasmineNodeOpts: {
showColors: false,
// silent: true,
defaultTimeoutInterval: 3000000
},
onPrepare: function() {
//html reporter
// jasmine.getEnv().addReporter(
// new Jasmine2HtmlReporter({
// savePath: './reporter/html',
// takeScreenshots: true,
// takeScreenshotsOnlyOnFailures: true,
// filePrefix: 'index',
// fileNameDateSuffix: true,
// cleanDestination: false
// })
// );
// //console
// jasmine.getEnv().addReporter(
// new SpecReporter({
// spec: {
// displayStacktrace: true
// }
// })
// );
return browser.get(browser.baseUrl);
}
};
vyper/test.spec.js
describe('script', function() {
it('step1:click on sap.m.GenericTile', async function() {
//----------------------- Block for sap.m.GenericTile - Perform Click -----------------------
var ui5ControlProperties = {
elementProperties: {
metadata: 'sap.m.GenericTile',
mProperties: {
header: 'Manage Self-Billing',
sizeBehavior: [{ path: '/properties/sizeBehavior' }],
wrappingType: [{ path: '/properties/wrappingType' }]
}
},
parentProperties: {
metadata: 'sap.ui.core.mvc.JSView',
mProperties: {
viewName: 'sap.ushell.components.tiles.cdm.applauncher.StaticTile'
}
},
prevSiblingProperties: {},
nextSiblingProperties: {},
childProperties: {
metadata: 'sap.m.Text',
mProperties: { text: 'Manage Self-Billing' }
}
};
await ui5.common.userInteraction.click(ui5ControlProperties);
});
});
webdriver
http://v4.webdriver.io/api.html
https://github.com/webdriverio/webdriverio/tree/master/examples
wdio.conf.js
const constant = require('./tests/data/common/constant');
const default_BASE_URL = constant.BASE_URL;
const defaultCapabilities = [
{
maxInstances: 5,
browserName: 'chrome',
'goog:chromeOptions': {
args: ['--window-size=1920,1200']
}
}
];
const defaultSpecs = ['./features/**/SB_UI_MNG_TLRC_GRP.feature'];
// const defaultSpecs = ['./features/**/SB_UI_MNG_SB_CHK_SD.feature'];
// const defaultSpecs = ['./features/**/LICENSE_RELEVANT_USAGE.feature'];
process.env.LOCAL = true;
exports.config = {
//
// ====================
// Runner Configuration
// ====================
//
// WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or
// on a remote machine).
runner: 'local',
//
// ==================
// Specify Test Files
// ==================
// Define which test specs should run. The pattern is relative to the directory
// from which `wdio` was called. Notice that, if you are calling `wdio` from an
// NPM script (see https://docs.npmjs.com/cli/run-script) then the current working
// directory is where your package.json resides, so `wdio` will be called from there.
//
specs: defaultSpecs,
// 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: 10,
//
// If you have trouble getting all important capabilities together, check out the
// Sauce Labs platform configurator - a great tool to configure your capabilities:
// https://docs.saucelabs.com/reference/platforms-configurator
//
capabilities: defaultCapabilities,
//
// ===================
// Test Configurations
// ===================
// Define all options that are relevant for the WebdriverIO instance here
//
// Level of logging verbosity: trace | debug | info | warn | error | silent
logLevel: 'info',
//
// Set specific log levels per logger
// loggers:
// - webdriver, webdriverio
// - @wdio/applitools-service, @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/sync, @wdio/utils
// Level of logging verbosity: trace | debug | info | warn | error | silent
// logLevels: {
// webdriver: 'info',
// '@wdio/applitools-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: default_BASE_URL,
//
// Default timeout for all waitFor* commands.
waitforTimeout: 120 * 1000,
//
// Default timeout in milliseconds for request
// if browser driver or grid doesn't send response
connectionRetryTimeout: 120 * 1000,
//
// 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: ['selenium-standalone'],
// Framework you want to run your specs with.
// The following are supported: Mocha, Jasmine, and Cucumber
// see also: https://webdriver.io/docs/frameworks.html
//
// Make sure you have the wdio adapter package for the specific framework installed
// before running any tests.
framework: 'cucumber',
//
// 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 specfiles 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.html
reporters: ['spec'],
//
// Options to be passed to Mocha.
// See the full list at http://mochajs.org/
// mochaOpts: {
// ui: 'bdd',
// timeout: 60000
// }
cucumberOpts: {
require: ['./tests/steps/**/*.js'], // <string[]> (file/dir) require files before executing features
backtrace: false, // <boolean> show full backtrace for errors
requireModule: [], // <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
dryRun: false, // <boolean> invoke formatters without executing steps
failFast: false, // <boolean> abort the run on first failure
format: ['pretty'], // <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable)
colors: true, // <boolean> disable colors in formatter output
snippets: true, // <boolean> hide step definition snippets for pending steps
source: true, // <boolean> hide source uris
profile: [], // <string[]> (name) specify the profile to use
strict: false, // <boolean> fail if there are any undefined or pending steps
tagExpression: '', // <string> (expression) only execute the features or scenarios with tags matching the expression
timeout: 120 * 1000, // <number> timeout for step definitions
ignoreUndefinedDefinitions: false // <boolean> Enable this config to treat undefined definitions as warnings.
},
//
// =====
// Hooks
// =====
// WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
// it and to build services around it. You can either apply a single function or an array of
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
// resolved to continue.
/**
* Gets executed once before all workers get launched.
* @param {Object} config wdio configuration object
* @param {Array.<Object>} capabilities list of capabilities details
*/
// onPrepare: function (config, capabilities) {
// },
/**
* Gets executed before a worker process is spawned and can be used to initialise specific service
* for that worker as well as modify runtime environments in an async fashion.
* @param {String} cid capability id (e.g 0-0)
* @param {[type]} caps object containing capabilities for session that will be spawn in the worker
* @param {[type]} specs specs to be run in the worker process
* @param {[type]} args object that will be merged with the main configuration once worker is initialised
* @param {[type]} execArgv list of string arguments passed to the worker process
*/
// onWorkerStart: function (cid, caps, specs, args, execArgv) {
// },
/**
* Gets executed just before initialising the webdriver session and test framework. It allows you
* to manipulate configurations depending on the capability or spec.
* @param {Object} config wdio configuration object
* @param {Array.<Object>} capabilities list of capabilities details
* @param {Array.<String>} specs List of spec file paths that are to be run
*/
// beforeSession: function (config, capabilities, specs) {
// },
/**
* Gets executed before test execution begins. At this point you can access to all global
* variables like `browser`. It is the perfect place to define custom commands.
* @param {Array.<Object>} capabilities list of capabilities details
* @param {Array.<String>} specs List of spec file paths that are to be run
*/
before: function (capabilities, specs) {
require('./tests/commands');
const Opa = require('./opa-e2e/Opae2e');
Opa.init(browser, {
waitForOptions: {
timeout: 60
}
});
}
/**
* Runs before a WebdriverIO command gets executed.
* @param {String} commandName hook command name
* @param {Array} args arguments that command would receive
*/
// beforeCommand: function (commandName, args) {},
/**
* Hook that gets executed before the suite starts
* @param {Object} suite suite details
*/
// beforeSuite: function (suite) {
// },
/**
* Function to be executed before a test (in Mocha/Jasmine) starts.
*/
// beforeTest: function (test, context) {
// },
/**
* Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
* beforeEach in Mocha)
*/
// beforeHook: function (test, context) {
// },
/**
* Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
* afterEach in Mocha)
*/
// afterHook: function (test, context, { error, result, duration, passed, retries }) {
// },
/**
* Function to be executed after a test (in Mocha/Jasmine).
*/
// afterTest: function(test, context, { error, result, duration, passed, retries }) {
// },
/**
* Hook that gets executed after the suite has ended
* @param {Object} suite suite details
*/
// afterSuite: function (suite) {
// },
/**
* Runs after a WebdriverIO command gets executed
* @param {String} commandName hook command name
* @param {Array} args arguments that command would receive
* @param {Number} result 0 - command success, 1 - command error
* @param {Object} error error object if any
*/
// afterCommand: function (commandName, args, result, error) {
// },
/**
* Gets executed after all tests are done. You still have access to all global variables from
* the test.
* @param {Number} result 0 - test pass, 1 - test fail
* @param {Array.<Object>} capabilities list of capabilities details
* @param {Array.<String>} specs List of spec file paths that ran
*/
// after: function (result, capabilities, specs) {
// },
/**
* Gets executed right after terminating the webdriver session.
* @param {Object} config wdio configuration object
* @param {Array.<Object>} capabilities list of capabilities details
* @param {Array.<String>} specs List of spec file paths that ran
*/
// afterSession: function (config, capabilities, specs) {
// },
/**
* Gets executed after all workers got shut down and the process is about to exit. An error
* thrown in the onComplete hook will result in the test run failing.
* @param {Object} exitCode 0 - success, 1 - fail
* @param {Object} config wdio configuration object
* @param {Array.<Object>} capabilities list of capabilities details
* @param {<Object>} results object containing test results
*/
// onComplete: function(exitCode, config, capabilities, results) {
// },
/**
* Gets executed when a refresh happens.
* @param {String} oldSessionId session ID of the old session
* @param {String} newSessionId session ID of the new session
*/
//onReload: function(oldSessionId, newSessionId) {
//}
};
…