Skip to content
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

#9 #12

Merged
merged 17 commits into from
Nov 28, 2017
Merged

#9 #12

Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cucumber.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

#Run server in background
node_modules/http-server/bin/http-server ./test/demo-app -p 9000 > /dev/null &
server=$!
#Run tests
./node_modules/.bin/wdio test/wdio.conf.js
#Kill server after run
kill -9 ${server}
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'

const fs = require('fs');
const files = fs.readdirSync('./src/steps');
const fs = require('fs')
const files = fs.readdirSync('./src/steps')

files.forEach((f) => {
const path = `./src/steps/${f}`
const fileSteps = require(path);
const fileSteps = require(path)

if (typeof fileSteps === 'function') {
fileSteps.apply(this);
fileSteps.apply(this)
}
});
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"lint": "./node_modules/eslint/bin/eslint.js -c .eslintrc.json src/ test/",
"mocha": "./node_modules/.bin/mocha test/mocha/*.spec.js",
"cucumber": "./node_modules/.bin/wdio test/wdio.conf.js",
"cucumber": ". ./cucumber.sh",
"test": "npm run lint && npm run mocha && npm run cucumber"
},
"repository": {
Expand Down Expand Up @@ -39,6 +39,7 @@
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.11.0",
"http-server": "^0.10.0",
"mocha": "^4.0.1",
"wdio-cucumber-framework": "^1.0.2",
"wdio-selenium-standalone-service": "0.0.9",
Expand Down
47 changes: 25 additions & 22 deletions src/helpers/objects.processor.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict'

/* eslint no-param-reassign: 0*/
/* eslint no-undef: 0 */

const { _r } = require('./utils')

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 @@ -44,54 +45,55 @@ 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 (!this.pages[page]) {
if (!pages[page]) {
throw new Error(`"${page}" page is missing`)
}
if (!this.pages[page][object]) {
if (!pages[page][object]) {
throw new Error(`"${object}" page object is missing for the "${page}" page`)
}
return this.pages[page][object]
return pages[page][object]
}
throw new Error(`Unknown Page Object type for "${str}"`)
}

function getPageObject(str) {
const value = parsePageObject.call(this, str)
const idValue = value.replace(_r(regDynamicId, 'g'), this.id)
const injection = 'not(ancestor-or-self::*[contains(@style,"visibility: hidden;") ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not remove semicolons from CSS "visibility: hidden;"

'or contains(@style,"display: none;") or contains(@class,"x-hide-offsets")])';
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")])'
const injectedvalue = injectInto(idValue, injection)

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 (!this.pages[dictionary]) {
if (!pages[dictionary]) {
throw new Error(`"${dictionary}" page is missing`)
}
if (!this.pages[dictionary][object]) {
if (!pages[dictionary][object]) {
throw new Error(`"${object}" page object is missing for the "${dictionary}" page`)
}
return this.pages[dictionary][object]
return pages[dictionary][object]
}
if (match[3] !== undefined) {
return match[3]
Expand All @@ -100,8 +102,9 @@ function parseDictionaryObject(str) {
}

function getDictionaryObject(str) {
const value = parseDictionaryObject.call(this, str)
const idValue = value.replace(_r(regDynamicId, 'g'), this.id)
const dicionaryGetterFunc = objectsProcessor.dicionaryGetter || dicionaryGetter
const value = dicionaryGetterFunc(str)
const idValue = value.replace(_r(regDynamicId, 'g'), id.getId())

return idValue
}
Expand Down
8 changes: 4 additions & 4 deletions src/steps/given.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict'

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

Expand All @@ -16,8 +16,8 @@ module.exports = function () {
*/
const url = getDictionaryObject.call(this, urlDictionary)

browser.url(url);
});
browser.url(url)
})

});
})
}
23 changes: 23 additions & 0 deletions src/steps/then.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint no-undef: 0 */

'use strict'

const { defineSupportCode } = require('cucumber')
const { pageObject, getPageObject } = require('../helpers/objects.processor')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.

const { _r } = require('../helpers/utils')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line


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

Then(_r(`^${pageObject} should be present$`), (object) => {
/**
* The element should be present
* @type {PageObject}
*/
const locator = getPageObject(object)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.


browser.$(locator).waitForExist()
})

})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.

11 changes: 11 additions & 0 deletions test/demo-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<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>
</head>
<body>
<div id="header">Header</div>
</body>
</html>
Empty file added test/demo-app/scripts/script.js
Empty file.
Empty file added test/demo-app/styles/style.css
Empty file.
6 changes: 6 additions & 0 deletions test/features/page_objects/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'
let e = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.


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

module.exports = e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.

5 changes: 3 additions & 2 deletions test/features/url.validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Feature: URL
As a developer
I want to open URL and check that is a certain value

Scenario: The URL should be https://github.com/
Given I open "https://github.com/"
Scenario: Check I write method
Given I open "http://localhost:9000"
Then txtHeader from main page should be present
55 changes: 29 additions & 26 deletions test/mocha/objects.processor.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'use strict'

const { expect } = require('chai')

Expand All @@ -14,18 +14,21 @@ const { _r } = require('../../src/helpers/utils')

const realId = 12345

const World = {
id: realId,
pages: {
page: {
object: `//div[@id='${dynamicId}']`
},
dictionary: {
object: `dictionaryObject${dynamicId}`
}
global.pages = {
main: {
object: `//div[@id='${dynamicId}']`
},
book: {
word: `dictionaryObject${dynamicId}`
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.


global.objectsProcessor = { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.


describe('injectInto', () => {
const data = [
{ locator: '//a', injection: '@class="b"]', result: '//a[@class="b"]' },
Expand All @@ -36,18 +39,18 @@ describe('injectInto', () => {

data.forEach((d) => {
it(`should get "${d.result}" string from "${d.locator}" and "${d.injection}" injection`, () => {
expect(injectInto(d.locator, d.injection)).to.be.equals(d.result);
});
});
});
expect(injectInto(d.locator, d.injection)).to.be.equals(d.result)
})
})
})

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")])]'
result: `//div[@id='${realId}' and not(ancestor-or-self::*[contains(@style,"visibility: hidden") ` +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not remove semicolons from CSS "visibility: hidden;"

'or contains(@style,"display: none") or contains(@class,"x-hide-offsets")])]'
}
]

Expand All @@ -59,18 +62,18 @@ describe('getPageObject', () => {

expect(match).to.be.an('array')
const strPageObject = match[1]
const pageObjectVal = getPageObject.call(World, strPageObject)
const pageObjectVal = getPageObject(strPageObject)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line


expect(pageObjectVal).to.be.equals(result)
next()
});
});
});
})
})
})

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 All @@ -89,10 +92,10 @@ describe('getDictionaryObject', () => {

expect(match).to.be.an('array')
const strDictionaryObject = match[1]
const dictionaryObjectVal = getDictionaryObject.call(World, strDictionaryObject)
const dictionaryObjectVal = getDictionaryObject(strDictionaryObject)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.


expect(dictionaryObjectVal).to.be.equals(result)
next()
});
});
});
})
})
})
13 changes: 13 additions & 0 deletions test/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ exports.config = {
global.expect = chai.expect;
global.assert = chai.assert;
global.should = chai.should();

global.pages = {
main: require('./features/page_objects/main')
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.


global.id = {
value: '',
regenerate: () => this.value === (new Date()).getTime(),
getId: () => this.value
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line


global.objectsProcessor = { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; is missing at the end of a line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try to use no semicolons.


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