Skip to content

Commit

Permalink
#10
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkrechik committed Nov 22, 2017
1 parent 1a345b1 commit 5698ae1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
26 changes: 14 additions & 12 deletions src/helpers/objects.processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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`)
Expand All @@ -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")])';
Expand All @@ -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`)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/features/url.validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions test/mocha/objects.processor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ 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}`
}
}

global.id = {
getId: () => realId
}

global.objectsProcessor = { }

describe('injectInto', () => {
const data = [
{ locator: '//a', injection: '@class="b"]', result: '//a[@class="b"]' },
Expand All @@ -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")])]'
Expand All @@ -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}`
},
Expand Down
2 changes: 2 additions & 0 deletions test/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ exports.config = {
getId: () => this.value
}

global.objectsProcessor = { }

},
/**
* Runs before a WebdriverIO command gets executed.
Expand Down

0 comments on commit 5698ae1

Please sign in to comment.