-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added waitForPageToLoad function #57
Changes from 17 commits
e0113a3
2cad97b
15b4188
13ab29a
377ee6f
5e3c0e9
e323c9b
5d262b4
2942a0b
fa124c4
0828574
7cb8cd9
9bb36e3
7a127c2
c0d1f18
81bbe4e
46c7cc9
d1fed7e
21ce939
475207b
bfdd711
32073a5
ad08727
09d9d3b
fd00403
0e4594a
c535e88
032f67e
8fe45b3
a6d411a
07437d0
493fab5
d551cbd
9b9cbff
e53491e
d0b0266
f906ad9
297edb9
96bfce4
3883fac
352a59b
821262f
c6f9593
61bc704
069847e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"cucumberautocomplete.steps": [ | ||
"src/steps/*.js" | ||
], | ||
"cucumberautocomplete.syncfeatures": "test/features/*feature", | ||
"cucumberautocomplete.strictGherkinCompletion": true, | ||
"cucumberautocomplete.smartSnippets": true, | ||
"cucumberautocomplete.stepsInvariants": true, | ||
"cucumberautocomplete.customParameters": [ | ||
{ | ||
"parameter":"(_r(", | ||
"value":"(" | ||
}, | ||
{ | ||
"parameter":"${dictionaryObject}", | ||
"value":"([a-zA-Z0-9_-]+ from [a-zA-Z0-9_-]+ dictionary|\"[^\"]*\")" | ||
}, | ||
{ | ||
"parameter":"${pageObject}", | ||
"value":"([a-zA-Z0-9_-]+ from [a-zA-Z0-9_-]+ page)" | ||
} | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const waitForPageToLoad = require('./wait.for.page.to.load'); | ||
|
||
module.exports = function applyCommands () { | ||
browser.addCommand('waitForPageToLoad', waitForPageToLoad); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* global stepsConfig */ | ||
|
||
module.exports = function waitForPageToLoad (callback) { | ||
/** | ||
* Wait for page to get fully loaded | ||
* @param {callback} callback - A callback to run | ||
*/ | ||
const timeout = 100; | ||
const finishedLoadingConditions = stepsConfig.finishedLoadingConditions; | ||
|
||
// If loading of the page was finished - launch callback function | ||
// TODO - add some waiter here | ||
if (finishedLoadingConditions()) { | ||
callback(); | ||
} | ||
|
||
// If loading of the page was not finished - relaunch finishedLoadingConditions() each 100 ms | ||
const interval = setInterval(function () { | ||
if (finishedLoadingConditions()) { | ||
clearInterval(interval); | ||
callback(); | ||
} | ||
}, timeout); | ||
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const defaultFinishedLoadingConditions = (loaderSelectors) => { | ||
// Check if jQuery is present on the page and if any XMLHttpRequests (AJAX) are in progress | ||
if (typeof $ !== 'undefined' && $.active) { | ||
return false; | ||
} | ||
|
||
// Check if any loaders are still present on the page | ||
return !loaderSelectors.some((selector) => browser.execute((s) => document.querySelector(s), selector)); | ||
}; | ||
|
||
const defaultIdGenerator = () => (new Date()).getTime(); | ||
|
||
module.exports = function ({ | ||
loaderSelectors = [], // <string>[] - array of xpath selectors, that will be used by finishedLoadingConditions. | ||
finishedLoadingConditions = defaultFinishedLoadingConditions, // <(loaderSelectors) => <boolean>>. | ||
pages = {}, // <{[key: string]: {[key: string]: <string>}}> - object, that contains "key" -> "Page object" pairs. | ||
defaultIdValue = '', // Default value of steps config Id. | ||
idGenerator = defaultIdGenerator, // <() => <string|number>> - function, that will return new generated id. | ||
objectsProcessor = {} // objectsProcessor childs could be previded here - see objects.processor.js for more details. | ||
}) { | ||
const id = { | ||
value: defaultIdValue || idGenerator.call(this), | ||
getId: () => this.value, | ||
regenerate: () => { | ||
this.value = idGenerator.call(this); | ||
} | ||
}; | ||
|
||
return { | ||
loaderSelectors, | ||
finishedLoadingConditions: finishedLoadingConditions.bind(this, loaderSelectors), | ||
pages, | ||
id, | ||
objectsProcessor | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
let e = {}; | ||
const e = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This object is being changed in the next line, so it looks like it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it is still better to use |
||
|
||
e.txtTimeout = '500'; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
let e = {}; | ||
const e = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This object is being changed (extended with additional properties) in the next 2 lines, so it looks like it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it is still better to use |
||
|
||
e.txtHeader = '//*[@id="header"]'; | ||
e.txtNewHeader = '//*[@id="new-header"]'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Array of selectors for loaders that appear when page is loaded or XHR/AJAX requests are done | ||
const loaderSelectors = [ | ||
'div:not([style*="display: none"])[class*="test-loader"]', | ||
'div:not([style*="visibility: hidden"])[class*="test-loader"]' | ||
]; | ||
|
||
// Object that contains pathes to all page objects used for tests | ||
const pages = { | ||
main: require('./features/page_objects/main'), | ||
values: require('./features/dictionary_objects/values') | ||
}; | ||
|
||
module.exports = { | ||
loaderSelectors, | ||
pages | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should rename this file to something like
steps.helper.functions.js
(because it looks more like a file with logic then config and we also have a second file with the same name intest/steps.conf.js
- and it looks like a real config file more)?