From 5698ae162b9cf206f2cfeedf613a58224c4d0891 Mon Sep 17 00:00:00 2001 From: Alex Krechik Date: Wed, 22 Nov 2017 19:31:49 +0100 Subject: [PATCH] #10 --- src/helpers/objects.processor.js | 26 ++++++++++++++------------ test/features/url.validation.feature | 2 +- test/mocha/objects.processor.spec.js | 12 +++++++----- test/wdio.conf.js | 2 ++ 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/helpers/objects.processor.js b/src/helpers/objects.processor.js index c9edc18..311dff6 100644 --- a/src/helpers/objects.processor.js +++ b/src/helpers/objects.processor.js @@ -9,11 +9,11 @@ const dynamicId = '$dynamicId$' const regDynamicId = '\\$dynamicId\\$' // Can come from applysteps ?? -const pageObject = '("[^"]+"\."[^"]+")' -const pageObjectsParts = '^"([^"]+)"\."([^"]+)"$' +const pageObject = '([a-zA-Z0-9_-]+ from [a-zA-Z0-9_-]+ page)' +const pageObjectsParts = '^([a-zA-Z0-9_-]+) from ([a-zA-Z0-9_-]+) page$' -const dictionaryObject = '("[^"]+"\."[^"]+"|"[^"]*")' -const dictionaryObjectsParts = '^(?:"([^"]+)"\."([^"]+)"|"([^"]*)")$' +const dictionaryObject = '([a-zA-Z0-9_-]+ from [a-zA-Z0-9_-]+ dictionary|"[^"]*")' +const dictionaryObjectsParts = '^(?:([a-zA-Z0-9_-]+) from ([a-zA-Z0-9_-]+) dictionary|"([^"]*)")$' // Todo do we need this in csp-qa function injectInto(locator, injection) { @@ -45,15 +45,15 @@ function injectInto(locator, injection) { } } -function parsePageObject(str) { +function pageObjectGetter(str) { const match = _r(pageObjectsParts).exec(str) if (!match) { throw new Error(`Was unable to find Page Object for "${str}"`) } if (match[1]) { - const page = match[1] - const object = match[2] + const page = match[2] + const object = match[1] if (!pages[page]) { throw new Error(`"${page}" page is missing`) @@ -67,7 +67,8 @@ function parsePageObject(str) { } function getPageObject(str) { - const value = parsePageObject.call(this, str) + const pageObjectGetterFunc = objectsProcessor.pageObjectGetter || pageObjectGetter + const value = pageObjectGetterFunc(str) const idValue = value.replace(_r(regDynamicId, 'g'), id.getId()) const injection = 'not(ancestor-or-self::*[contains(@style,"visibility: hidden;") ' + 'or contains(@style,"display: none;") or contains(@class,"x-hide-offsets")])'; @@ -76,15 +77,15 @@ function getPageObject(str) { return injectedvalue } -function parseDictionaryObject(str) { +function dicionaryGetter(str) { const match = _r(dictionaryObjectsParts).exec(str) if (!match) { throw new Error(`Was unable to find Dictionary Object type for "${str}"`) } if (match[1]) { - const dictionary = match[1] - const object = match[2] + const dictionary = match[2] + const object = match[1] if (!pages[dictionary]) { throw new Error(`"${dictionary}" page is missing`) @@ -101,7 +102,8 @@ function parseDictionaryObject(str) { } function getDictionaryObject(str) { - const value = parseDictionaryObject.call(this, str) + const dicionaryGetterFunc = objectsProcessor.dicionaryGetter || dicionaryGetter + const value = dicionaryGetterFunc(str) const idValue = value.replace(_r(regDynamicId, 'g'), id.getId()) return idValue diff --git a/test/features/url.validation.feature b/test/features/url.validation.feature index bf1c90a..93254e4 100644 --- a/test/features/url.validation.feature +++ b/test/features/url.validation.feature @@ -8,4 +8,4 @@ Feature: URL Scenario: Check I write method Given I open "http://localhost:9000" - Then "main"."txtHeader" should be present + Then txtHeader from main page should be present diff --git a/test/mocha/objects.processor.spec.js b/test/mocha/objects.processor.spec.js index 5bae3a3..f80653c 100644 --- a/test/mocha/objects.processor.spec.js +++ b/test/mocha/objects.processor.spec.js @@ -15,11 +15,11 @@ const { _r } = require('../../src/helpers/utils') const realId = 12345 global.pages = { - page: { + main: { object: `//div[@id='${dynamicId}']` }, - dictionary: { - object: `dictionaryObject${dynamicId}` + book: { + word: `dictionaryObject${dynamicId}` } } @@ -27,6 +27,8 @@ global.id = { getId: () => realId } +global.objectsProcessor = { } + describe('injectInto', () => { const data = [ { locator: '//a', injection: '@class="b"]', result: '//a[@class="b"]' }, @@ -45,7 +47,7 @@ describe('injectInto', () => { describe('getPageObject', () => { const data = [ { - step: 'When I click "page"."object"', + step: 'When I click object from main page', regExp: _r(`When I click ${pageObject}`), result: `//div[@id='${realId}' and not(ancestor-or-self::*[contains(@style,"visibility: hidden;") ` + 'or contains(@style,"display: none;") or contains(@class,"x-hide-offsets")])]' @@ -71,7 +73,7 @@ describe('getPageObject', () => { describe('getDictionaryObject', () => { const data = [ { - step: 'When I write "dictionary"."object"', + step: 'When I write word from book dictionary', regExp: _r(`When I write ${dictionaryObject}`), result: `dictionaryObject${realId}` }, diff --git a/test/wdio.conf.js b/test/wdio.conf.js index 6acc8b7..338bf23 100644 --- a/test/wdio.conf.js +++ b/test/wdio.conf.js @@ -199,6 +199,8 @@ exports.config = { getId: () => this.value } + global.objectsProcessor = { } + }, /** * Runs before a WebdriverIO command gets executed.