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 all 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
13 changes: 5 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@
"EC": true
},
"root": true,
"ecmaFeatures": {
"modules": true
},
"rules": {
// Possible Errors
"comma-dangle": [2, "never"],
"no-cond-assign": 2,
"no-console": 0,
"no-console": 1,
"no-constant-condition": 2,
"no-control-regex": 2,
"no-debugger": 2,
Expand Down Expand Up @@ -88,7 +85,7 @@
"no-caller": 2,
"no-case-declarations": 2,
"no-div-regex": 2,
"no-else-return": 1,
"no-else-return": 2,
"no-empty-pattern": 2,
"no-eq-null": 2,
"no-eval": 2,
Expand Down Expand Up @@ -133,7 +130,7 @@
"yoda": [2, "never", { "exceptRange": true }],

// Strict Mode
"strict": [0, "global"],
"strict": [2, "global"],

// Variables
"init-declarations": 0,
Expand All @@ -145,7 +142,7 @@
"no-undef-init": 2,
"no-undef": 2,
"no-undefined": 0,
"no-unused-vars": 1,
"no-unused-vars": 2,
"no-use-before-define": 2,

// Stylistic Issues
Expand Down Expand Up @@ -198,7 +195,7 @@
"padded-blocks": 0,
"quote-props": [2, "consistent-as-needed"],
"quotes": [2, "single", "avoid-escape"],
"require-jsdoc": 2,
"require-jsdoc": 1,
"semi-spacing": [2, {"before": false, "after": true}],
"semi": [0, "always"],
"sort-vars": 0,
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Logs
logs
*.log

# Dependency directory
node_modules

*.DS_Store
.*
!.travis.yml
!.editorconfig
!.eslintrc.json
Copy link
Member

Choose a reason for hiding this comment

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

If we will remove this line, then any changes to .eslintrc.json will not be tracked by git - are we sure that it should not be tracked?

!.eslintrc.*
*.xml
.settings
downloads
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ install:

# http://docs.travis-ci.com/user/pull-requests/
script:
- npm run lint
- npm run mocha
- npm run cucumber
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
55 changes: 26 additions & 29 deletions src/helpers/objects.processor.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
'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 All @@ -34,64 +33,61 @@ function injectInto(locator, injection) {
const body = locator.replace(/\[[0-9]+\]$/, '')

return injectInto(body, injection) + nums
} else {
// Locator ends with brackets, which contain some properties
return locator.substring(0, locator.length - 1) + ' and ' + injection
}
} else {
// Locator contains no brackets
return locator + '[' + injection
return locator.substring(0, locator.length - 1) + ' and ' + injection
}
return 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 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")])';
'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 +96,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
2 changes: 0 additions & 2 deletions src/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const escapeRegExp = function (str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\$&')
}
Expand Down
11 changes: 5 additions & 6 deletions src/steps/given.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint no-undef: 0 */
/* eslint new-cap: 0 */

'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 +15,8 @@ module.exports = function () {
*/
const url = getDictionaryObject.call(this, urlDictionary)

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

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

const { defineSupportCode } = require('cucumber')
const { pageObject, getPageObject } = require('../helpers/objects.processor')
const { _r } = require('../helpers/utils')

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()
})

})
}
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.
5 changes: 5 additions & 0 deletions test/features/page_objects/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let e = {}

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

module.exports = e
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
Loading