Skip to content

Commit

Permalink
Merge pull request #21 from revjet-qa/wait_not_present_steps
Browse files Browse the repository at this point in the history
"Wait" and "is not present" steps are added
  • Loading branch information
alexkrechik authored Jan 29, 2018
2 parents b253334 + fd5d79b commit 764413c
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ downloads
*~
.idea
.vscode
errorShots/
14 changes: 13 additions & 1 deletion src/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ const _r = function (str, flags) {
return new RegExp(escapeRegExp(str), flags);
};

/**
* Will look for integers in received string and returns them
* @param {string} str - dictionaryObject
* @returns {integer}
*/
const getInteger = function (str) {
const int = parseInt(str.replace(/\D+/g, ''), 10);

return int;
};

module.exports = {
escapeRegExp,
_r
_r,
getInteger
};
8 changes: 8 additions & 0 deletions src/steps/then.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ module.exports = function () {

browser.$(locator).waitForExist();
});
Then(_r(`^${pageObject} should not be present$`), (object) => {
/**
* The element should not be present
* @type {PageObject}
*/
const locator = getPageObject(object);

browser.$(locator).waitForExist(null, true);
});
});
};
23 changes: 23 additions & 0 deletions src/steps/when.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint new-cap: 0 */

const { defineSupportCode } = require('cucumber');
const { dictionaryObject, getDictionaryObject } = require('../helpers/objects.processor');
const { _r, getInteger } = require('../helpers/utils');


module.exports = function () {
defineSupportCode(({ When }) => {

When(_r(`I wait ${dictionaryObject} ms$`), (timeObject) => {
/**
* Wait in milliseconds
* @type {String}
*/
const timeValue = getDictionaryObject.call(this, timeObject);
const time = getInteger(timeValue);

browser.pause(time);
});

});
};
5 changes: 3 additions & 2 deletions test/demo-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
<html lang="en">
<head>
<title>DEMO APP FOR THE WDIO-STEPS</title>
<link rel="stylesheet" href="styles/styles.css">
<script src="inc/script.js"></script>
<link rel="stylesheet" href="styles/style.css">
<script src="scripts/script.js"></script>
</head>
<body>
<div id="header">Header</div>
<div id="div_timeout">This div disappears after 5000 ms</div>
</body>
</html>
5 changes: 5 additions & 0 deletions test/demo-app/scripts/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var timeout = 5000;

setTimeout(function () {
document.getElementById('div_timeout').remove();
}, timeout);
4 changes: 4 additions & 0 deletions test/demo-app/styles/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#div_timeout {
color: red;
display: block;
}
5 changes: 5 additions & 0 deletions test/features/dictionary_objects/values.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let e = {};

e.txtTimeout = '500';

module.exports = e;
1 change: 1 addition & 0 deletions test/features/page_objects/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let e = {};

e.txtHeader = '//*[@id="header"]';
e.divTimeout = '//*[@id="div_timeout"]';

module.exports = e;
17 changes: 17 additions & 0 deletions test/features/show.hide.timeout.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@Fast

Feature: Present / Not present
In order to check steps with appearing/disappearing elements
As a developer
I want to check that certain value is present and not present after time

Scenario: Check I write method
Given I open "http://localhost:9000"
Then txtHeader from main page should be present
Then divTimeout from main page should be present
When I wait "5000" ms
Then divTimeout from main page should not be present
Then txtHeader from main page should be present
Then I wait txtTimeout from values dictionary ms
Then divTimeout from main page should not be present
Then txtHeader from main page should be present
3 changes: 2 additions & 1 deletion test/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ exports.config = {
global.should = chai.should();

global.pages = {
main: require('./features/page_objects/main')
main: require('./features/page_objects/main'),
values: require('./features/dictionary_objects/values')
};

global.id = {
Expand Down

0 comments on commit 764413c

Please # to comment.