codeceptjs 4.0.0-beta.3 → 4.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -119
- package/bin/codecept.js +12 -2
- package/bin/test-server.js +53 -0
- package/docs/webapi/clearCookie.mustache +1 -1
- package/lib/actor.js +66 -102
- package/lib/ai.js +130 -121
- package/lib/assert/empty.js +3 -5
- package/lib/assert/equal.js +4 -7
- package/lib/assert/include.js +4 -6
- package/lib/assert/throws.js +2 -4
- package/lib/assert/truth.js +2 -2
- package/lib/codecept.js +141 -86
- package/lib/command/check.js +201 -0
- package/lib/command/configMigrate.js +2 -4
- package/lib/command/definitions.js +8 -26
- package/lib/command/dryRun.js +30 -35
- package/lib/command/generate.js +10 -14
- package/lib/command/gherkin/snippets.js +75 -73
- package/lib/command/gherkin/steps.js +1 -1
- package/lib/command/info.js +42 -8
- package/lib/command/init.js +13 -12
- package/lib/command/interactive.js +10 -2
- package/lib/command/list.js +1 -1
- package/lib/command/run-multiple/chunk.js +48 -45
- package/lib/command/run-multiple.js +12 -35
- package/lib/command/run-workers.js +21 -58
- package/lib/command/utils.js +5 -6
- package/lib/command/workers/runTests.js +263 -222
- package/lib/container.js +386 -238
- package/lib/data/context.js +10 -13
- package/lib/data/dataScenarioConfig.js +8 -8
- package/lib/data/dataTableArgument.js +6 -6
- package/lib/data/table.js +5 -11
- package/lib/effects.js +223 -0
- package/lib/element/WebElement.js +327 -0
- package/lib/els.js +158 -0
- package/lib/event.js +21 -17
- package/lib/heal.js +88 -80
- package/lib/helper/AI.js +2 -1
- package/lib/helper/ApiDataFactory.js +4 -7
- package/lib/helper/Appium.js +50 -57
- package/lib/helper/FileSystem.js +3 -3
- package/lib/helper/GraphQLDataFactory.js +4 -4
- package/lib/helper/JSONResponse.js +75 -37
- package/lib/helper/Mochawesome.js +31 -9
- package/lib/helper/Nightmare.js +37 -58
- package/lib/helper/Playwright.js +267 -272
- package/lib/helper/Protractor.js +56 -87
- package/lib/helper/Puppeteer.js +247 -264
- package/lib/helper/REST.js +29 -17
- package/lib/helper/TestCafe.js +22 -47
- package/lib/helper/WebDriver.js +157 -368
- package/lib/helper/extras/PlaywrightPropEngine.js +2 -2
- package/lib/helper/extras/Popup.js +22 -22
- package/lib/helper/network/utils.js +1 -1
- package/lib/helper/testcafe/testcafe-utils.js +27 -28
- package/lib/listener/emptyRun.js +55 -0
- package/lib/listener/exit.js +7 -10
- package/lib/listener/{retry.js → globalRetry.js} +5 -5
- package/lib/listener/globalTimeout.js +165 -0
- package/lib/listener/helpers.js +15 -15
- package/lib/listener/mocha.js +1 -1
- package/lib/listener/result.js +12 -0
- package/lib/listener/retryEnhancer.js +85 -0
- package/lib/listener/steps.js +32 -18
- package/lib/listener/store.js +20 -0
- package/lib/locator.js +1 -1
- package/lib/mocha/asyncWrapper.js +231 -0
- package/lib/{interfaces → mocha}/bdd.js +3 -3
- package/lib/mocha/cli.js +308 -0
- package/lib/mocha/factory.js +104 -0
- package/lib/{interfaces → mocha}/featureConfig.js +32 -12
- package/lib/{interfaces → mocha}/gherkin.js +26 -28
- package/lib/mocha/hooks.js +112 -0
- package/lib/mocha/index.js +12 -0
- package/lib/mocha/inject.js +29 -0
- package/lib/{interfaces → mocha}/scenarioConfig.js +31 -7
- package/lib/mocha/suite.js +82 -0
- package/lib/mocha/test.js +181 -0
- package/lib/mocha/types.d.ts +42 -0
- package/lib/mocha/ui.js +232 -0
- package/lib/output.js +93 -65
- package/lib/pause.js +160 -138
- package/lib/plugin/analyze.js +396 -0
- package/lib/plugin/auth.js +435 -0
- package/lib/plugin/autoDelay.js +8 -8
- package/lib/plugin/autoLogin.js +3 -338
- package/lib/plugin/commentStep.js +6 -1
- package/lib/plugin/coverage.js +10 -22
- package/lib/plugin/customLocator.js +3 -3
- package/lib/plugin/customReporter.js +52 -0
- package/lib/plugin/eachElement.js +1 -1
- package/lib/plugin/fakerTransform.js +1 -1
- package/lib/plugin/heal.js +36 -9
- package/lib/plugin/htmlReporter.js +1947 -0
- package/lib/plugin/pageInfo.js +140 -0
- package/lib/plugin/retryFailedStep.js +17 -18
- package/lib/plugin/retryTo.js +2 -113
- package/lib/plugin/screenshotOnFail.js +17 -58
- package/lib/plugin/selenoid.js +15 -35
- package/lib/plugin/standardActingHelpers.js +4 -1
- package/lib/plugin/stepByStepReport.js +56 -17
- package/lib/plugin/stepTimeout.js +5 -12
- package/lib/plugin/subtitles.js +4 -4
- package/lib/plugin/tryTo.js +3 -102
- package/lib/plugin/wdio.js +8 -10
- package/lib/recorder.js +155 -124
- package/lib/rerun.js +43 -42
- package/lib/result.js +161 -0
- package/lib/secret.js +1 -2
- package/lib/step/base.js +239 -0
- package/lib/step/comment.js +10 -0
- package/lib/step/config.js +50 -0
- package/lib/step/func.js +46 -0
- package/lib/step/helper.js +50 -0
- package/lib/step/meta.js +99 -0
- package/lib/step/record.js +74 -0
- package/lib/step/retry.js +11 -0
- package/lib/step/section.js +55 -0
- package/lib/step.js +21 -332
- package/lib/steps.js +50 -0
- package/lib/store.js +37 -5
- package/lib/template/heal.js +2 -11
- package/lib/test-server.js +323 -0
- package/lib/timeout.js +66 -0
- package/lib/utils.js +351 -218
- package/lib/within.js +75 -55
- package/lib/workerStorage.js +2 -1
- package/lib/workers.js +386 -277
- package/package.json +81 -75
- package/translations/de-DE.js +5 -3
- package/translations/fr-FR.js +5 -4
- package/translations/index.js +1 -0
- package/translations/it-IT.js +4 -3
- package/translations/ja-JP.js +4 -3
- package/translations/nl-NL.js +76 -0
- package/translations/pl-PL.js +4 -3
- package/translations/pt-BR.js +4 -3
- package/translations/ru-RU.js +4 -3
- package/translations/utils.js +9 -0
- package/translations/zh-CN.js +4 -3
- package/translations/zh-TW.js +4 -3
- package/typings/index.d.ts +197 -187
- package/typings/promiseBasedTypes.d.ts +53 -903
- package/typings/types.d.ts +372 -1042
- package/lib/cli.js +0 -257
- package/lib/helper/ExpectHelper.js +0 -391
- package/lib/helper/MockServer.js +0 -221
- package/lib/helper/SoftExpectHelper.js +0 -381
- package/lib/listener/artifacts.js +0 -19
- package/lib/listener/timeout.js +0 -109
- package/lib/mochaFactory.js +0 -113
- package/lib/plugin/debugErrors.js +0 -67
- package/lib/scenario.js +0 -224
- package/lib/ui.js +0 -236
package/lib/helper/Protractor.js
CHANGED
|
@@ -117,9 +117,7 @@ class Protractor extends Helper {
|
|
|
117
117
|
this.isRunning = false
|
|
118
118
|
this._setConfig(config)
|
|
119
119
|
|
|
120
|
-
console.log(
|
|
121
|
-
'Protractor helper is deprecated as well as Protractor itself.\nThis helper will be removed in next major release',
|
|
122
|
-
)
|
|
120
|
+
console.log('Protractor helper is deprecated as well as Protractor itself.\nThis helper will be removed in next major release')
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
_validateConfig(config) {
|
|
@@ -152,7 +150,7 @@ class Protractor extends Helper {
|
|
|
152
150
|
}
|
|
153
151
|
|
|
154
152
|
async _init() {
|
|
155
|
-
process.on('unhandledRejection',
|
|
153
|
+
process.on('unhandledRejection', reason => {
|
|
156
154
|
if (reason.message.indexOf('ECONNREFUSED') > 0) {
|
|
157
155
|
this.browser = null
|
|
158
156
|
}
|
|
@@ -288,9 +286,7 @@ class Protractor extends Helper {
|
|
|
288
286
|
if (frame) {
|
|
289
287
|
if (Array.isArray(frame)) {
|
|
290
288
|
withinStore.frame = frame.join('>')
|
|
291
|
-
return this.switchTo(null).then(() =>
|
|
292
|
-
frame.reduce((p, frameLocator) => p.then(() => this.switchTo(frameLocator)), Promise.resolve()),
|
|
293
|
-
)
|
|
289
|
+
return this.switchTo(null).then(() => frame.reduce((p, frameLocator) => p.then(() => this.switchTo(frameLocator)), Promise.resolve()))
|
|
294
290
|
}
|
|
295
291
|
withinStore.frame = frame
|
|
296
292
|
return this.switchTo(locator)
|
|
@@ -300,8 +296,8 @@ class Protractor extends Helper {
|
|
|
300
296
|
const context = await global.element(guessLocator(locator) || global.by.css(locator))
|
|
301
297
|
if (!context) throw new ElementNotFound(locator)
|
|
302
298
|
|
|
303
|
-
this.browser.findElement =
|
|
304
|
-
this.browser.findElements =
|
|
299
|
+
this.browser.findElement = l => (l ? context.element(l).getWebElement() : context.getWebElement())
|
|
300
|
+
this.browser.findElements = l => context.all(l).getWebElements()
|
|
305
301
|
return context
|
|
306
302
|
}
|
|
307
303
|
|
|
@@ -320,7 +316,7 @@ class Protractor extends Helper {
|
|
|
320
316
|
_session() {
|
|
321
317
|
const defaultSession = this.browser
|
|
322
318
|
return {
|
|
323
|
-
start: async
|
|
319
|
+
start: async opts => {
|
|
324
320
|
opts = this._validateConfig(Object.assign(this.options, opts))
|
|
325
321
|
this.debugSection('New Browser', JSON.stringify(opts))
|
|
326
322
|
const runner = new Runner(opts)
|
|
@@ -331,10 +327,10 @@ class Protractor extends Helper {
|
|
|
331
327
|
await browser.manage().window().setSize(parseInt(res[0], 10), parseInt(res[1], 10))
|
|
332
328
|
return browser.ready
|
|
333
329
|
},
|
|
334
|
-
stop: async
|
|
330
|
+
stop: async browser => {
|
|
335
331
|
return browser.close()
|
|
336
332
|
},
|
|
337
|
-
loadVars: async
|
|
333
|
+
loadVars: async browser => {
|
|
338
334
|
if (isWithin()) throw new Error("Can't start session inside within block")
|
|
339
335
|
this.browser = browser
|
|
340
336
|
loadGlobals(this.browser)
|
|
@@ -573,7 +569,7 @@ class Protractor extends Helper {
|
|
|
573
569
|
if (!els.length) {
|
|
574
570
|
els = await field.findElements(global.by.xpath(Locator.select.byValue(opt)))
|
|
575
571
|
}
|
|
576
|
-
els.forEach(
|
|
572
|
+
els.forEach(el => promises.push(el.click()))
|
|
577
573
|
}
|
|
578
574
|
|
|
579
575
|
return Promise.all(promises)
|
|
@@ -595,7 +591,6 @@ class Protractor extends Helper {
|
|
|
595
591
|
async pressKey(key) {
|
|
596
592
|
let modifier
|
|
597
593
|
if (Array.isArray(key) && ~['Control', 'Command', 'Shift', 'Alt'].indexOf(key[0])) {
|
|
598
|
-
// eslint-disable-line no-bitwise
|
|
599
594
|
modifier = Key[key[0].toUpperCase()]
|
|
600
595
|
key = key[1]
|
|
601
596
|
}
|
|
@@ -741,7 +736,7 @@ class Protractor extends Helper {
|
|
|
741
736
|
const els = await this._locate(locator)
|
|
742
737
|
|
|
743
738
|
const html = await Promise.all(
|
|
744
|
-
els.map(
|
|
739
|
+
els.map(el => {
|
|
745
740
|
return this.browser.executeScript('return arguments[0].innerHTML;', el)
|
|
746
741
|
}),
|
|
747
742
|
)
|
|
@@ -767,7 +762,7 @@ class Protractor extends Helper {
|
|
|
767
762
|
*/
|
|
768
763
|
async grabValueFromAll(locator) {
|
|
769
764
|
const els = await findFields(this.browser, locator)
|
|
770
|
-
const values = await Promise.all(els.map(
|
|
765
|
+
const values = await Promise.all(els.map(el => el.getAttribute('value')))
|
|
771
766
|
|
|
772
767
|
return values
|
|
773
768
|
}
|
|
@@ -790,7 +785,7 @@ class Protractor extends Helper {
|
|
|
790
785
|
*/
|
|
791
786
|
async grabCssPropertyFromAll(locator, cssProperty) {
|
|
792
787
|
const els = await this._locate(locator, true)
|
|
793
|
-
const values = await Promise.all(els.map(
|
|
788
|
+
const values = await Promise.all(els.map(el => el.getCssValue(cssProperty)))
|
|
794
789
|
|
|
795
790
|
return values
|
|
796
791
|
}
|
|
@@ -840,7 +835,7 @@ class Protractor extends Helper {
|
|
|
840
835
|
* {{> seeInTitle }}
|
|
841
836
|
*/
|
|
842
837
|
async seeInTitle(text) {
|
|
843
|
-
return this.browser.getTitle().then(
|
|
838
|
+
return this.browser.getTitle().then(title => stringIncludes('web page title').assert(text, title))
|
|
844
839
|
}
|
|
845
840
|
|
|
846
841
|
/**
|
|
@@ -855,14 +850,14 @@ class Protractor extends Helper {
|
|
|
855
850
|
* {{> dontSeeInTitle }}
|
|
856
851
|
*/
|
|
857
852
|
async dontSeeInTitle(text) {
|
|
858
|
-
return this.browser.getTitle().then(
|
|
853
|
+
return this.browser.getTitle().then(title => stringIncludes('web page title').negate(text, title))
|
|
859
854
|
}
|
|
860
855
|
|
|
861
856
|
/**
|
|
862
857
|
* {{> grabTitle }}
|
|
863
858
|
*/
|
|
864
859
|
async grabTitle() {
|
|
865
|
-
return this.browser.getTitle().then(
|
|
860
|
+
return this.browser.getTitle().then(title => {
|
|
866
861
|
this.debugSection('Title', title)
|
|
867
862
|
return title
|
|
868
863
|
})
|
|
@@ -873,8 +868,8 @@ class Protractor extends Helper {
|
|
|
873
868
|
*/
|
|
874
869
|
async seeElement(locator) {
|
|
875
870
|
let els = await this._locate(locator, true)
|
|
876
|
-
els = await Promise.all(els.map(
|
|
877
|
-
return empty('elements').negate(els.filter(
|
|
871
|
+
els = await Promise.all(els.map(el => el.isDisplayed()))
|
|
872
|
+
return empty('elements').negate(els.filter(v => v).fill('ELEMENT'))
|
|
878
873
|
}
|
|
879
874
|
|
|
880
875
|
/**
|
|
@@ -882,33 +877,29 @@ class Protractor extends Helper {
|
|
|
882
877
|
*/
|
|
883
878
|
async dontSeeElement(locator) {
|
|
884
879
|
let els = await this._locate(locator, false)
|
|
885
|
-
els = await Promise.all(els.map(
|
|
886
|
-
return empty('elements').assert(els.filter(
|
|
880
|
+
els = await Promise.all(els.map(el => el.isDisplayed()))
|
|
881
|
+
return empty('elements').assert(els.filter(v => v).fill('ELEMENT'))
|
|
887
882
|
}
|
|
888
883
|
|
|
889
884
|
/**
|
|
890
885
|
* {{> seeElementInDOM }}
|
|
891
886
|
*/
|
|
892
887
|
async seeElementInDOM(locator) {
|
|
893
|
-
return this.browser
|
|
894
|
-
.findElements(guessLocator(locator) || global.by.css(locator))
|
|
895
|
-
.then((els) => empty('elements').negate(els.fill('ELEMENT')))
|
|
888
|
+
return this.browser.findElements(guessLocator(locator) || global.by.css(locator)).then(els => empty('elements').negate(els.fill('ELEMENT')))
|
|
896
889
|
}
|
|
897
890
|
|
|
898
891
|
/**
|
|
899
892
|
* {{> dontSeeElementInDOM }}
|
|
900
893
|
*/
|
|
901
894
|
async dontSeeElementInDOM(locator) {
|
|
902
|
-
return this.browser
|
|
903
|
-
.findElements(guessLocator(locator) || global.by.css(locator))
|
|
904
|
-
.then((els) => empty('elements').assert(els.fill('ELEMENT')))
|
|
895
|
+
return this.browser.findElements(guessLocator(locator) || global.by.css(locator)).then(els => empty('elements').assert(els.fill('ELEMENT')))
|
|
905
896
|
}
|
|
906
897
|
|
|
907
898
|
/**
|
|
908
899
|
* {{> seeInSource }}
|
|
909
900
|
*/
|
|
910
901
|
async seeInSource(text) {
|
|
911
|
-
return this.browser.getPageSource().then(
|
|
902
|
+
return this.browser.getPageSource().then(source => stringIncludes('HTML source of a page').assert(text, source))
|
|
912
903
|
}
|
|
913
904
|
|
|
914
905
|
/**
|
|
@@ -922,7 +913,7 @@ class Protractor extends Helper {
|
|
|
922
913
|
* {{> dontSeeInSource }}
|
|
923
914
|
*/
|
|
924
915
|
async dontSeeInSource(text) {
|
|
925
|
-
return this.browser.getPageSource().then(
|
|
916
|
+
return this.browser.getPageSource().then(source => stringIncludes('HTML source of a page').negate(text, source))
|
|
926
917
|
}
|
|
927
918
|
|
|
928
919
|
/**
|
|
@@ -930,9 +921,7 @@ class Protractor extends Helper {
|
|
|
930
921
|
*/
|
|
931
922
|
async seeNumberOfElements(locator, num) {
|
|
932
923
|
const elements = await this._locate(locator)
|
|
933
|
-
return equals(
|
|
934
|
-
`expected number of elements (${new Locator(locator)}) is ${num}, but found ${elements.length}`,
|
|
935
|
-
).assert(elements.length, num)
|
|
924
|
+
return equals(`expected number of elements (${new Locator(locator)}) is ${num}, but found ${elements.length}`).assert(elements.length, num)
|
|
936
925
|
}
|
|
937
926
|
|
|
938
927
|
/**
|
|
@@ -940,10 +929,7 @@ class Protractor extends Helper {
|
|
|
940
929
|
*/
|
|
941
930
|
async seeNumberOfVisibleElements(locator, num) {
|
|
942
931
|
const res = await this.grabNumberOfVisibleElements(locator)
|
|
943
|
-
return equals(`expected number of visible elements (${new Locator(locator)}) is ${num}, but found ${res}`).assert(
|
|
944
|
-
res,
|
|
945
|
-
num,
|
|
946
|
-
)
|
|
932
|
+
return equals(`expected number of visible elements (${new Locator(locator)}) is ${num}, but found ${res}`).assert(res, num)
|
|
947
933
|
}
|
|
948
934
|
|
|
949
935
|
/**
|
|
@@ -951,7 +937,7 @@ class Protractor extends Helper {
|
|
|
951
937
|
*/
|
|
952
938
|
async grabNumberOfVisibleElements(locator) {
|
|
953
939
|
let els = await this._locate(locator)
|
|
954
|
-
els = await Promise.all(els.map(
|
|
940
|
+
els = await Promise.all(els.map(el => el.isDisplayed()))
|
|
955
941
|
return els.length
|
|
956
942
|
}
|
|
957
943
|
|
|
@@ -965,11 +951,11 @@ class Protractor extends Helper {
|
|
|
965
951
|
const cssPropertiesCamelCase = convertCssPropertiesToCamelCase(cssProperties)
|
|
966
952
|
|
|
967
953
|
const attributeNames = Object.keys(cssPropertiesCamelCase)
|
|
968
|
-
const expectedValues = attributeNames.map(
|
|
954
|
+
const expectedValues = attributeNames.map(name => cssPropertiesCamelCase[name])
|
|
969
955
|
const missingAttributes = []
|
|
970
956
|
|
|
971
957
|
for (const el of els) {
|
|
972
|
-
const attributeValues = await Promise.all(attributeNames.map(
|
|
958
|
+
const attributeValues = await Promise.all(attributeNames.map(attr => el.getCssValue(attr)))
|
|
973
959
|
|
|
974
960
|
const missing = attributeValues.filter((actual, i) => {
|
|
975
961
|
const prop = attributeNames[i]
|
|
@@ -983,9 +969,7 @@ class Protractor extends Helper {
|
|
|
983
969
|
missingAttributes.push(...missing)
|
|
984
970
|
}
|
|
985
971
|
}
|
|
986
|
-
return equals(
|
|
987
|
-
`all elements (${new Locator(locator)}) to have CSS property ${JSON.stringify(cssProperties)}`,
|
|
988
|
-
).assert(missingAttributes.length, 0)
|
|
972
|
+
return equals(`all elements (${new Locator(locator)}) to have CSS property ${JSON.stringify(cssProperties)}`).assert(missingAttributes.length, 0)
|
|
989
973
|
}
|
|
990
974
|
|
|
991
975
|
/**
|
|
@@ -996,11 +980,11 @@ class Protractor extends Helper {
|
|
|
996
980
|
assertElementExists(els, locator)
|
|
997
981
|
|
|
998
982
|
const attributeNames = Object.keys(attributes)
|
|
999
|
-
const expectedValues = attributeNames.map(
|
|
983
|
+
const expectedValues = attributeNames.map(name => attributes[name])
|
|
1000
984
|
const missingAttributes = []
|
|
1001
985
|
|
|
1002
986
|
for (const el of els) {
|
|
1003
|
-
const attributeValues = await Promise.all(attributeNames.map(
|
|
987
|
+
const attributeValues = await Promise.all(attributeNames.map(attr => el.getAttribute(attr)))
|
|
1004
988
|
const missing = attributeValues.filter((actual, i) => {
|
|
1005
989
|
if (expectedValues[i] instanceof RegExp) {
|
|
1006
990
|
return expectedValues[i].test(actual)
|
|
@@ -1012,10 +996,7 @@ class Protractor extends Helper {
|
|
|
1012
996
|
}
|
|
1013
997
|
}
|
|
1014
998
|
|
|
1015
|
-
return equals(`all elements (${new Locator(locator)}) to have attributes ${JSON.stringify(attributes)}`).assert(
|
|
1016
|
-
missingAttributes.length,
|
|
1017
|
-
0,
|
|
1018
|
-
)
|
|
999
|
+
return equals(`all elements (${new Locator(locator)}) to have attributes ${JSON.stringify(attributes)}`).assert(missingAttributes.length, 0)
|
|
1019
1000
|
}
|
|
1020
1001
|
|
|
1021
1002
|
/**
|
|
@@ -1037,28 +1018,28 @@ class Protractor extends Helper {
|
|
|
1037
1018
|
* {{> seeInCurrentUrl }}
|
|
1038
1019
|
*/
|
|
1039
1020
|
async seeInCurrentUrl(url) {
|
|
1040
|
-
return this.browser.getCurrentUrl().then(
|
|
1021
|
+
return this.browser.getCurrentUrl().then(currentUrl => stringIncludes('url').assert(url, currentUrl))
|
|
1041
1022
|
}
|
|
1042
1023
|
|
|
1043
1024
|
/**
|
|
1044
1025
|
* {{> dontSeeInCurrentUrl }}
|
|
1045
1026
|
*/
|
|
1046
1027
|
async dontSeeInCurrentUrl(url) {
|
|
1047
|
-
return this.browser.getCurrentUrl().then(
|
|
1028
|
+
return this.browser.getCurrentUrl().then(currentUrl => stringIncludes('url').negate(url, currentUrl))
|
|
1048
1029
|
}
|
|
1049
1030
|
|
|
1050
1031
|
/**
|
|
1051
1032
|
* {{> seeCurrentUrlEquals }}
|
|
1052
1033
|
*/
|
|
1053
1034
|
async seeCurrentUrlEquals(url) {
|
|
1054
|
-
return this.browser.getCurrentUrl().then(
|
|
1035
|
+
return this.browser.getCurrentUrl().then(currentUrl => urlEquals(this.options.url).assert(url, currentUrl))
|
|
1055
1036
|
}
|
|
1056
1037
|
|
|
1057
1038
|
/**
|
|
1058
1039
|
* {{> dontSeeCurrentUrlEquals }}
|
|
1059
1040
|
*/
|
|
1060
1041
|
async dontSeeCurrentUrlEquals(url) {
|
|
1061
|
-
return this.browser.getCurrentUrl().then(
|
|
1042
|
+
return this.browser.getCurrentUrl().then(currentUrl => urlEquals(this.options.url).negate(url, currentUrl))
|
|
1062
1043
|
}
|
|
1063
1044
|
|
|
1064
1045
|
/**
|
|
@@ -1073,7 +1054,7 @@ class Protractor extends Helper {
|
|
|
1073
1054
|
const stream = fs.createWriteStream(outputFile)
|
|
1074
1055
|
stream.write(Buffer.from(png, 'base64'))
|
|
1075
1056
|
stream.end()
|
|
1076
|
-
return new Promise(
|
|
1057
|
+
return new Promise(resolve => stream.on('finish', resolve))
|
|
1077
1058
|
}
|
|
1078
1059
|
|
|
1079
1060
|
const res = await this._locate(locator)
|
|
@@ -1096,7 +1077,7 @@ class Protractor extends Helper {
|
|
|
1096
1077
|
const stream = fs.createWriteStream(outputFile)
|
|
1097
1078
|
stream.write(Buffer.from(png, 'base64'))
|
|
1098
1079
|
stream.end()
|
|
1099
|
-
return new Promise(
|
|
1080
|
+
return new Promise(resolve => stream.on('finish', resolve))
|
|
1100
1081
|
}
|
|
1101
1082
|
|
|
1102
1083
|
if (!fullPage) {
|
|
@@ -1106,7 +1087,6 @@ class Protractor extends Helper {
|
|
|
1106
1087
|
}
|
|
1107
1088
|
|
|
1108
1089
|
let { width, height } = await this.browser.executeScript(() => ({
|
|
1109
|
-
// eslint-disable-line
|
|
1110
1090
|
height: document.body.scrollHeight,
|
|
1111
1091
|
width: document.body.scrollWidth,
|
|
1112
1092
|
}))
|
|
@@ -1136,7 +1116,7 @@ class Protractor extends Helper {
|
|
|
1136
1116
|
return this.browser
|
|
1137
1117
|
.manage()
|
|
1138
1118
|
.getCookie(name)
|
|
1139
|
-
.then(
|
|
1119
|
+
.then(res => truth(`cookie ${name}`, 'to be set').assert(res))
|
|
1140
1120
|
}
|
|
1141
1121
|
|
|
1142
1122
|
/**
|
|
@@ -1146,7 +1126,7 @@ class Protractor extends Helper {
|
|
|
1146
1126
|
return this.browser
|
|
1147
1127
|
.manage()
|
|
1148
1128
|
.getCookie(name)
|
|
1149
|
-
.then(
|
|
1129
|
+
.then(res => truth(`cookie ${name}`, 'to be set').negate(res))
|
|
1150
1130
|
}
|
|
1151
1131
|
|
|
1152
1132
|
/**
|
|
@@ -1244,11 +1224,11 @@ class Protractor extends Helper {
|
|
|
1244
1224
|
|
|
1245
1225
|
const handles = await client.getAllWindowHandles()
|
|
1246
1226
|
const currentHandle = await client.getWindowHandle()
|
|
1247
|
-
const otherHandles = handles.filter(
|
|
1227
|
+
const otherHandles = handles.filter(handle => handle !== currentHandle)
|
|
1248
1228
|
|
|
1249
1229
|
if (!otherHandles || !otherHandles.length) return
|
|
1250
1230
|
let p = Promise.resolve()
|
|
1251
|
-
otherHandles.forEach(
|
|
1231
|
+
otherHandles.forEach(handle => {
|
|
1252
1232
|
p = p.then(() =>
|
|
1253
1233
|
client
|
|
1254
1234
|
.switchTo()
|
|
@@ -1395,7 +1375,7 @@ class Protractor extends Helper {
|
|
|
1395
1375
|
async waitForDetached(locator, sec = null) {
|
|
1396
1376
|
const aSec = sec || this.options.waitForTimeoutInSeconds
|
|
1397
1377
|
const el = global.element(guessLocator(locator) || global.by.css(locator))
|
|
1398
|
-
return this.browser.wait(EC.not(EC.presenceOf(el)), aSec * 1000).catch(
|
|
1378
|
+
return this.browser.wait(EC.not(EC.presenceOf(el)), aSec * 1000).catch(err => {
|
|
1399
1379
|
if (err.message && err.message.indexOf('Wait timed out after') > -1) {
|
|
1400
1380
|
throw new Error(`element (${JSON.stringify(locator)}) still on page after ${sec} sec`)
|
|
1401
1381
|
} else throw err
|
|
@@ -1455,9 +1435,9 @@ class Protractor extends Helper {
|
|
|
1455
1435
|
return function () {
|
|
1456
1436
|
return global.element
|
|
1457
1437
|
.all(loc)
|
|
1458
|
-
.filter(
|
|
1438
|
+
.filter(el => el.isDisplayed())
|
|
1459
1439
|
.count()
|
|
1460
|
-
.then(
|
|
1440
|
+
.then(count => count === expectedCount)
|
|
1461
1441
|
}
|
|
1462
1442
|
}
|
|
1463
1443
|
|
|
@@ -1487,22 +1467,20 @@ class Protractor extends Helper {
|
|
|
1487
1467
|
async waitForValue(field, value, sec = null) {
|
|
1488
1468
|
const aSec = sec || this.options.waitForTimeoutInSeconds
|
|
1489
1469
|
|
|
1490
|
-
const valueToBeInElementValue =
|
|
1470
|
+
const valueToBeInElementValue = loc => {
|
|
1491
1471
|
return async () => {
|
|
1492
1472
|
const els = await findFields(this.browser, loc)
|
|
1493
1473
|
|
|
1494
1474
|
if (!els) {
|
|
1495
1475
|
return false
|
|
1496
1476
|
}
|
|
1497
|
-
const values = await Promise.all(els.map(
|
|
1498
|
-
return values.filter(
|
|
1477
|
+
const values = await Promise.all(els.map(el => el.getAttribute('value')))
|
|
1478
|
+
return values.filter(part => part.indexOf(value) >= 0).length > 0
|
|
1499
1479
|
}
|
|
1500
1480
|
}
|
|
1501
1481
|
|
|
1502
1482
|
return this.browser.wait(valueToBeInElementValue(field, value), aSec * 1000).catch(() => {
|
|
1503
|
-
throw Error(
|
|
1504
|
-
`element (${field}) is not in DOM or there is no element(${field}) with value "${value}" after ${aSec} sec`,
|
|
1505
|
-
)
|
|
1483
|
+
throw Error(`element (${field}) is not in DOM or there is no element(${field}) with value "${value}" after ${aSec} sec`)
|
|
1506
1484
|
})
|
|
1507
1485
|
}
|
|
1508
1486
|
|
|
@@ -1530,7 +1508,7 @@ class Protractor extends Helper {
|
|
|
1530
1508
|
const aSec = sec || this.options.waitForTimeoutInSeconds
|
|
1531
1509
|
const waitTimeout = aSec * 1000
|
|
1532
1510
|
|
|
1533
|
-
return this.browser.wait(EC.urlContains(urlPart), waitTimeout).catch(async
|
|
1511
|
+
return this.browser.wait(EC.urlContains(urlPart), waitTimeout).catch(async e => {
|
|
1534
1512
|
const currUrl = await this.browser.getCurrentUrl()
|
|
1535
1513
|
if (/wait timed out after/i.test(e.message)) {
|
|
1536
1514
|
throw new Error(`expected url to include ${urlPart}, but found ${currUrl}`)
|
|
@@ -1551,7 +1529,7 @@ class Protractor extends Helper {
|
|
|
1551
1529
|
urlPart = baseUrl + urlPart
|
|
1552
1530
|
}
|
|
1553
1531
|
|
|
1554
|
-
return this.browser.wait(EC.urlIs(urlPart), waitTimeout).catch(async
|
|
1532
|
+
return this.browser.wait(EC.urlIs(urlPart), waitTimeout).catch(async e => {
|
|
1555
1533
|
const currUrl = await this.browser.getCurrentUrl()
|
|
1556
1534
|
if (/wait timed out after/i.test(e.message)) {
|
|
1557
1535
|
throw new Error(`expected url to be ${urlPart}, but found ${currUrl}`)
|
|
@@ -1614,7 +1592,7 @@ class Protractor extends Helper {
|
|
|
1614
1592
|
}
|
|
1615
1593
|
const elem = res[0]
|
|
1616
1594
|
const location = await elem.getLocation()
|
|
1617
|
-
|
|
1595
|
+
|
|
1618
1596
|
return this.executeScript(
|
|
1619
1597
|
function (x, y) {
|
|
1620
1598
|
return window.scrollTo(x, y)
|
|
@@ -1622,10 +1600,8 @@ class Protractor extends Helper {
|
|
|
1622
1600
|
location.x + offsetX,
|
|
1623
1601
|
location.y + offsetY,
|
|
1624
1602
|
)
|
|
1625
|
-
/* eslint-enable */
|
|
1626
1603
|
}
|
|
1627
1604
|
|
|
1628
|
-
/* eslint-disable prefer-arrow-callback, comma-dangle */
|
|
1629
1605
|
return this.executeScript(
|
|
1630
1606
|
function (x, y) {
|
|
1631
1607
|
return window.scrollTo(x, y)
|
|
@@ -1633,7 +1609,6 @@ class Protractor extends Helper {
|
|
|
1633
1609
|
offsetX,
|
|
1634
1610
|
offsetY,
|
|
1635
1611
|
)
|
|
1636
|
-
/* eslint-enable */
|
|
1637
1612
|
}
|
|
1638
1613
|
|
|
1639
1614
|
/**
|
|
@@ -1647,30 +1622,24 @@ class Protractor extends Helper {
|
|
|
1647
1622
|
* {{> scrollPageToBottom }}
|
|
1648
1623
|
*/
|
|
1649
1624
|
async scrollPageToBottom() {
|
|
1650
|
-
/* eslint-disable prefer-arrow-callback, comma-dangle */
|
|
1651
1625
|
return this.executeScript(function () {
|
|
1652
1626
|
const body = document.body
|
|
1653
1627
|
const html = document.documentElement
|
|
1654
|
-
window.scrollTo(
|
|
1655
|
-
0,
|
|
1656
|
-
Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight),
|
|
1657
|
-
)
|
|
1628
|
+
window.scrollTo(0, Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight))
|
|
1658
1629
|
})
|
|
1659
|
-
/* eslint-enable */
|
|
1660
1630
|
}
|
|
1661
1631
|
|
|
1662
1632
|
/**
|
|
1663
1633
|
* {{> grabPageScrollPosition }}
|
|
1664
1634
|
*/
|
|
1665
1635
|
async grabPageScrollPosition() {
|
|
1666
|
-
/* eslint-disable comma-dangle */
|
|
1667
1636
|
function getScrollPosition() {
|
|
1668
1637
|
return {
|
|
1669
1638
|
x: window.pageXOffset,
|
|
1670
1639
|
y: window.pageYOffset,
|
|
1671
1640
|
}
|
|
1672
1641
|
}
|
|
1673
|
-
|
|
1642
|
+
|
|
1674
1643
|
return this.executeScript(getScrollPosition)
|
|
1675
1644
|
}
|
|
1676
1645
|
|
|
@@ -1786,7 +1755,7 @@ async function proceedSee(assertType, text, context) {
|
|
|
1786
1755
|
const els = await this._smartWait(() => this.browser.findElements(locator), enableSmartWait)
|
|
1787
1756
|
const promises = []
|
|
1788
1757
|
let source = ''
|
|
1789
|
-
els.forEach(
|
|
1758
|
+
els.forEach(el => promises.push(el.getText().then(elText => (source += `| ${elText}`))))
|
|
1790
1759
|
await Promise.all(promises)
|
|
1791
1760
|
return stringIncludes(description)[assertType](text, source)
|
|
1792
1761
|
}
|
|
@@ -1811,7 +1780,7 @@ async function proceedIsChecked(assertType, option) {
|
|
|
1811
1780
|
const els = await findCheckable(this.browser, option)
|
|
1812
1781
|
assertElementExists(els, option, 'Option')
|
|
1813
1782
|
const elsSelected = []
|
|
1814
|
-
els.forEach(
|
|
1783
|
+
els.forEach(el => elsSelected.push(el.isSelected()))
|
|
1815
1784
|
const values = await Promise.all(elsSelected)
|
|
1816
1785
|
const selected = values.reduce((prev, cur) => prev || cur)
|
|
1817
1786
|
return truth(`checkable ${option}`, 'to be checked')[assertType](selected)
|