Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

tooling: Use Puppeteer (#433)

Guilherme Oenninga2b29e7dfceb
diff --git a/.circleci/config.yml b/.circleci/config.yml
index b01bba42a..c566b73ea 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -1,7 +1,7 @@
version: 2
references:
builder: &builder
- getfider/circleci:0.0.9
+ getfider/circleci:0.0.11
workdir: &workdir
/go/src/github.com/getfider/fider
diff --git a/Makefile b/Makefile
index 125075c0a..2b271e877 100644
--- a/Makefile
+++ b/Makefile
@@ -41,7 +41,7 @@ e2e-build:
./scripts/e2e.sh build
e2e:
- ./scripts/e2e.sh
+ ./scripts/e2e.sh
# Development
watch:
diff --git a/package-lock.json b/package-lock.json
index 05e15dacd..888c2ce29 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -90,12 +90,11 @@
"dev": true
},
"@types/jsdom": {
- "version": "11.0.5",
- "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-11.0.5.tgz",
- "integrity": "sha512-j8ANkoDARupBS38xxQv2vu6qsUFZrlM7sSNBPhqe66mM7cjcqAEDUphOG7nE7/fePslJgNcEPVNTYFlkFVogyg==",
+ "version": "11.0.4",
+ "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-11.0.4.tgz",
+ "integrity": "sha512-lthMj4kw7Fzs3LjBhQ0+1faAfDrN9GFJZO5Nf/xO7fppFfxqnnQdNR28n0xMGXsx8fTHOPliE1NTkAW1bVLpYw==",
"dev": true,
"requires": {
- "@types/events": "*",
"@types/node": "*",
"@types/tough-cookie": "*",
"parse5": "^3.0.2"
@@ -124,6 +123,16 @@
"integrity": "sha512-/gwCgiI2e9RzzZTKbl+am3vgNqOt7a9fJ/uxv4SqYKxenoEDNVU3KZEadlpusWhQI0A0dOrZ0T68JYKVjzmgdQ==",
"dev": true
},
+ "@types/puppeteer": {
+ "version": "1.3.4",
+ "resolved": "https://registry.npmjs.org/@types/puppeteer/-/puppeteer-1.3.4.tgz",
+ "integrity": "sha512-WI43+i2SZnYAm39ASmeDxhSR+czDIBuEqTNftg3V+bgTlqsbdmj8n/p9/95wWd4ipsnb/qD6nrvBekEvWh8UKQ==",
+ "dev": true,
+ "requires": {
+ "@types/events": "*",
+ "@types/node": "*"
+ }
+ },
"@types/react": {
"version": "16.3.17",
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.3.17.tgz",
@@ -152,12 +161,6 @@
"@types/react": "*"
}
},
- "@types/selenium-webdriver": {
- "version": "3.0.8",
- "resolved": "https://registry.npmjs.org/@types/selenium-webdriver/-/selenium-webdriver-3.0.8.tgz",
- "integrity": "sha512-yrqQvb1EZhH+ONMzUmsEnBjzitortVv0lynRe5US2+FofdoMWUE4wf7v4peCd62fqXq8COCVTbpS1/jIg5EbuQ==",
- "dev": true
- },
"@types/tough-cookie": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.3.tgz",
@@ -451,6 +454,15 @@
"acorn": "^5.0.0"
}
},
+ "agent-base": {
+ "version": "4.2.0",
+ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.0.tgz",
+ "integrity": "sha512-c+R/U5X+2zz2+UCrCFv6odQzJdoqI+YecuhnAJLa1zYaMc13zPfwMwZrr91Pd1DYNo/yPRbiM4WVf9whgwFsIg==",
+ "dev": true,
+ "requires": {
+ "es6-promisify": "^5.0.0"
+ }
+ },
"ajv": {
"version": "5.5.2",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz",
@@ -1616,19 +1628,6 @@
"tslib": "^1.9.0"
}
},
- "chromedriver": {
- "version": "2.38.3",
- "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-2.38.3.tgz",
- "integrity": "sha512-tczy6RHl0LOVA4p+xezcu3NRjr9A1iLyyfjP9yPIUynvV28YSKH/Ll1iw0jMCjN9jwtaB2HB4aPjv0Uuw2VARw==",
- "dev": true,
- "requires": {
- "del": "^3.0.0",
- "extract-zip": "^1.6.6",
- "kew": "^0.7.0",
- "mkdirp": "^0.5.1",
- "request": "^2.85.0"
- }
- },
"ci-info": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-1.1.3.tgz",
@@ -2505,11 +2504,22 @@
"is-symbol": "^1.0.1"
}
},
- "es6-promise": {
- "version": "3.0.2",
- "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.0.2.tgz",
- "integrity": "sha1-AQ1YWEI6XxGJeWZfRkhqlcbuK7Y=",
- "dev": true
+ "es6-promisify": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz",
+ "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=",
+ "dev": true,
+ "requires": {
+ "es6-promise": "^4.0.3"
+ },
+ "dependencies": {
+ "es6-promise": {
+ "version": "4.2.4",
+ "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.4.tgz",
+ "integrity": "sha512-/NdNZVJg+uZgtm9eS3O6lrOLYmQag2DjdEXuPaHlZ6RuVqgqaVZfgYCepEIKsLqwdQArOPtC3XzRLqGGfT8KQQ==",
+ "dev": true
+ }
+ }
},
"escape-string-regexp": {
"version": "1.0.5",
@@ -4108,6 +4118,27 @@
"integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=",
"dev": true
},
+ "https-proxy-agent": {
+ "version": "2.2.1",
+ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz",
+ "integrity": "sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==",
+ "dev": true,
+ "requires": {
+ "agent-base": "^4.1.0",
+ "debug": "^3.1.0"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
+ "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
+ "dev": true,
+ "requires": {
+ "ms": "2.0.0"
+ }
+ }
+ }
+ },
"iconv-lite": {
"version": "0.4.21",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.21.tgz",
@@ -4197,12 +4228,6 @@
"integrity": "sha1-xg7taebY/bazEEofy8ocGS3FtQE=",
"dev": true
},
- "immediate": {
- "version": "3.0.6",
- "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
- "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=",
- "dev": true
- },
"import-local": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/import-local/-/import-local-1.0.0.tgz",
@@ -7260,59 +7285,6 @@
"verror": "1.10.0"
}
},
- "jszip": {
- "version": "3.1.5",
- "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.1.5.tgz",
- "integrity": "sha512-5W8NUaFRFRqTOL7ZDDrx5qWHJyBXy6velVudIzQUSoqAAYqzSh2Z7/m0Rf1QbmQJccegD0r+YZxBjzqoBiEeJQ==",
- "dev": true,
- "requires": {
- "core-js": "~2.3.0",
- "es6-promise": "~3.0.2",
- "lie": "~3.1.0",
- "pako": "~1.0.2",
- "readable-stream": "~2.0.6"
- },
- "dependencies": {
- "core-js": {
- "version": "2.3.0",
- "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.3.0.tgz",
- "integrity": "sha1-+rg/uwstjchfpjbEudNMdUIMbWU=",
- "dev": true
- },
- "process-nextick-args": {
- "version": "1.0.7",
- "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
- "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=",
- "dev": true
- },
- "readable-stream": {
- "version": "2.0.6",
- "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz",
- "integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=",
- "dev": true,
- "requires": {
- "core-util-is": "~1.0.0",
- "inherits": "~2.0.1",
- "isarray": "~1.0.0",
- "process-nextick-args": "~1.0.6",
- "string_decoder": "~0.10.x",
- "util-deprecate": "~1.0.1"
- }
- },
- "string_decoder": {
- "version": "0.10.31",
- "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
- "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
- "dev": true
- }
- }
- },
- "kew": {
- "version": "0.7.0",
- "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz",
- "integrity": "sha1-edk9LTM2PW/dKXCzNdkUGtWR15s=",
- "dev": true
- },
"keyboard-key": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/keyboard-key/-/keyboard-key-1.0.1.tgz",
@@ -7368,15 +7340,6 @@
"type-check": "~0.3.2"
}
},
- "lie": {
- "version": "3.1.1",
- "resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",
- "integrity": "sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=",
- "dev": true,
- "requires": {
- "immediate": "~3.0.5"
- }
- },
"linkify-it": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.0.3.tgz",
@@ -7709,6 +7672,12 @@
"brorand": "^1.0.1"
}
},
+ "mime": {
+ "version": "2.3.1",
+ "resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz",
+ "integrity": "sha512-OEUllcVoydBHGN1z84yfQDimn58pZNNNXgZlHXSboxMlFvgI6MXSWpWKpFRra7H1HxpVhHTkrghfRW49k6yjeg==",
+ "dev": true
+ },
"mime-db": {
"version": "1.33.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz",
@@ -9316,6 +9285,12 @@
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==",
"dev": true
},
+ "progress": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz",
+ "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=",
+ "dev": true
+ },
"promise": {
"version": "7.3.1",
"resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",
@@ -9340,6 +9315,12 @@
"object-assign": "^4.1.1"
}
},
+ "proxy-from-env": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.0.0.tgz",
+ "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=",
+ "dev": true
+ },
"prr": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz",
@@ -9392,6 +9373,42 @@
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=",
"dev": true
},
+ "puppeteer": {
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.5.0.tgz",
+ "integrity": "sha512-eELwFtFxL+uhmg4jPZOZXzSrPEYy4CaYQNbcchBbfxY+KjMpnv6XGf/aYWaQG49OTpfi2/DMziXtDM8XuJgoUA==",
+ "dev": true,
+ "requires": {
+ "debug": "^3.1.0",
+ "extract-zip": "^1.6.6",
+ "https-proxy-agent": "^2.2.1",
+ "mime": "^2.0.3",
+ "progress": "^2.0.0",
+ "proxy-from-env": "^1.0.0",
+ "rimraf": "^2.6.1",
+ "ws": "^5.1.1"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
+ "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
+ "dev": true,
+ "requires": {
+ "ms": "2.0.0"
+ }
+ },
+ "ws": {
+ "version": "5.2.1",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.1.tgz",
+ "integrity": "sha512-2NkHdPKjDBj3CHdnAGNpmlliryKqF+n9MYXX7/wsVC4yqYocKreKNjydPDvT3wShAZnndlM0RytEfTALCDvz7A==",
+ "dev": true,
+ "requires": {
+ "async-limiter": "~1.0.0"
+ }
+ }
+ }
+ },
"q": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
@@ -10528,18 +10545,6 @@
}
}
},
- "selenium-webdriver": {
- "version": "3.6.0",
- "resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-3.6.0.tgz",
- "integrity": "sha512-WH7Aldse+2P5bbFBO4Gle/nuQOdVwpHMTL6raL3uuBj/vPG07k6uzt3aiahu352ONBr5xXh0hDlM3LhtXPOC4Q==",
- "dev": true,
- "requires": {
- "jszip": "^3.1.3",
- "rimraf": "^2.5.4",
- "tmp": "0.0.30",
- "xml2js": "^0.4.17"
- }
- },
"semantic-ui-css": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/semantic-ui-css/-/semantic-ui-css-2.3.1.tgz",
@@ -11201,15 +11206,6 @@
"setimmediate": "^1.0.4"
}
},
- "tmp": {
- "version": "0.0.30",
- "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.30.tgz",
- "integrity": "sha1-ckGdSovn1s51FI/YsyTlk6cRwu0=",
- "dev": true,
- "requires": {
- "os-tmpdir": "~1.0.1"
- }
- },
"tmpl": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz",
@@ -12568,22 +12564,6 @@
"integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==",
"dev": true
},
- "xml2js": {
- "version": "0.4.19",
- "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
- "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
- "dev": true,
- "requires": {
- "sax": ">=0.6.0",
- "xmlbuilder": "~9.0.1"
- }
- },
- "xmlbuilder": {
- "version": "9.0.7",
- "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
- "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=",
- "dev": true
- },
"xtend": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
diff --git a/package.json b/package.json
index bd65aee52..26a9b67c3 100644
--- a/package.json
+++ b/package.json
@@ -11,18 +11,17 @@
"react-toastify": "4.1.0",
"semantic-ui-css": "2.3.1",
"semantic-ui-react": "0.81.1",
- "tslib": "^1.9.2"
+ "tslib": "1.9.2"
},
"devDependencies": {
"@types/jest": "23.1.0",
- "@types/jsdom": "^11.0.5",
+ "@types/jsdom": " 11.0.4",
"@types/markdown-it": "0.0.4",
"@types/node": "10.3.3",
+ "@types/puppeteer": "^1.3.4",
"@types/react": "16.3.17",
"@types/react-dom": "16.0.6",
"@types/react-textarea-autosize": "4.3.2",
- "@types/selenium-webdriver": "3.0.8",
- "chromedriver": "2.38.3",
"css-loader": "0.28.11",
"dotenv": "6.0.0",
"file-loader": "1.1.11",
@@ -30,9 +29,9 @@
"mini-css-extract-plugin": "0.4.0",
"node-sass": "4.9.0",
"prettier": "1.13.5",
+ "puppeteer": "1.5.0",
"reflect-metadata": "0.1.12",
"sass-loader": "7.0.3",
- "selenium-webdriver": "3.6.0",
"ts-jest": "22.4.6",
"ts-loader": "4.4.1",
"tslint": "5.10.0",
diff --git a/public/pages/ShowIdea/ShowIdea.page.tsx b/public/pages/ShowIdea/ShowIdea.page.tsx
index 220869266..9303af73c 100644
--- a/public/pages/ShowIdea/ShowIdea.page.tsx
+++ b/public/pages/ShowIdea/ShowIdea.page.tsx
@@ -130,12 +130,12 @@ export class ShowIdeaPage extends React.Component<ShowIdeaPageProps, ShowIdeaPag
this.state.editMode ? (
<List key={1}>
<ListItem>
- <Button color="positive" fluid={true} onClick={this.saveChanges}>
+ <Button className="save" color="positive" fluid={true} onClick={this.saveChanges}>
<i className="save icon" /> Save
</Button>
</ListItem>
<ListItem>
- <Button fluid={true} onClick={this.cancelEdit}>
+ <Button className="cancel" fluid={true} onClick={this.cancelEdit}>
<i className="cancel icon" /> Cancel
</Button>
</ListItem>
@@ -143,7 +143,7 @@ export class ShowIdeaPage extends React.Component<ShowIdeaPageProps, ShowIdeaPag
) : (
<List key={1}>
<ListItem>
- <Button fluid={true} onClick={this.startEdit}>
+ <Button className="edit" fluid={true} onClick={this.startEdit}>
<i className="edit icon" /> Edit
</Button>
</ListItem>
diff --git a/public/pages/SignUp/SignUp.page.tsx b/public/pages/SignUp/SignUp.page.tsx
index 9d0d9601e..979d958af 100644
--- a/public/pages/SignUp/SignUp.page.tsx
+++ b/public/pages/SignUp/SignUp.page.tsx
@@ -2,7 +2,6 @@ import "./SignUp.page.scss";
import * as React from "react";
import { SignInControl, Modal, Button, DisplayError, Form, Input, Message, LegalAgreement } from "@fider/components";
-import { SystemSettings } from "@fider/models";
import { jwt, actions, Failure, querystring } from "@fider/services";
interface OAuthUser {
@@ -80,16 +79,32 @@ export class SignUpPage extends React.Component<{}, SignUpPageState> {
}
};
- private checkAvailability = async (subdomain: string) => {
- const result = await actions.checkAvailability(subdomain);
+ private timer?: number;
+ private checkAvailability = (subdomain: string) => {
+ window.clearTimeout(this.timer);
+ this.timer = window.setTimeout(() => {
+ actions.checkAvailability(subdomain).then(result => {
+ this.setState({
+ subdomain: {
+ value: subdomain,
+ available: !result.data.message,
+ message: result.data.message
+ }
+ });
+ });
+ }, 200);
+ };
- this.setState({
- subdomain: {
- value: subdomain,
- available: !result.data.message,
- message: result.data.message
- }
- });
+ private setSubdomain = async (subdomain: string) => {
+ this.setState(
+ {
+ subdomain: {
+ value: subdomain,
+ available: false
+ }
+ },
+ this.checkAvailability.bind(this, subdomain)
+ );
};
private onAgree = (agreed: boolean): void => {
@@ -157,7 +172,7 @@ export class SignUpPage extends React.Component<{}, SignUpPageState> {
<Input
field="subdomain"
maxLength={40}
- onChange={this.checkAvailability}
+ onChange={this.setSubdomain}
placeholder="subdomain"
suffix={Fider.settings.domain}
>
diff --git a/scripts/e2e.sh b/scripts/e2e.sh
index 58e462b84..b178190a3 100755
--- a/scripts/e2e.sh
+++ b/scripts/e2e.sh
@@ -4,24 +4,25 @@ FIDER_CONTAINER="fider_e2e"
PG_CONTAINER="fider_pge2e"
PORT=3000
-run_e2e () {
- echo "Compiling tests..."
- rm -rf ./output/tests
- npx tsc -p ./tests/tsconfig.json
-
+start_fider () {
echo "Starting Fider (HOST_MODE: $1)..."
docker rm -f $FIDER_CONTAINER $PG_CONTAINER || true
docker run -d -e POSTGRES_USER=fider_e2e -e POSTGRES_PASSWORD=fider_e2e_pw --name $PG_CONTAINER postgres:9.6.8
docker run --link $PG_CONTAINER:pg waisbrot/wait
- docker run -d -p 3000:3000 --link $PG_CONTAINER -e HOST_MODE=$1 -e DATABASE_URL=postgres://fider_e2e:fider_e2e_pw@$PG_CONTAINER:5432/fider_e2e?sslmode=disable --env-file .env --name $FIDER_CONTAINER getfider/fider:e2e
-
- {
- echo "Running e2e tests ..."
- npx jest ./output/tests/e2e-$1.spec.js
- } && {
- echo "Stopping Fider ..."
- docker rm -f $FIDER_CONTAINER
- }
+ docker run \
+ -d \
+ -p 3000:3000 \
+ -e HOST_MODE=$1 \
+ -e DATABASE_URL=postgres://fider_e2e:fider_e2e_pw@$PG_CONTAINER:5432/fider_e2e?sslmode=disable \
+ --env-file .env \
+ --link $PG_CONTAINER \
+ --name $FIDER_CONTAINER getfider/fider:e2e
+}
+
+run_e2e () {
+ start_fider $1
+ echo "Running e2e tests ..."
+ npx jest ./tests/$1.spec.ts
}
if [[ $1 == 'build' ]] || [ -z $1 ]
@@ -40,6 +41,8 @@ then
run_e2e multi
fi
+echo "Stopping Containers ..."
+docker rm -f $FIDER_CONTAINER $PG_CONTAINER || true
-echo "Stopping Postgres ..."
-docker rm -f $PG_CONTAINER || true
\ No newline at end of file
+echo "Killing Chromium..."
+ps -A | grep '[c]hromium' | awk '{print $1}' | xargs kill || true
\ No newline at end of file
diff --git a/tests/components/CommentList.ts b/tests/components/CommentList.ts
deleted file mode 100644
index 2e67dc715..000000000
--- a/tests/components/CommentList.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { WebElement, By } from "selenium-webdriver";
-import { Browser, WebComponent } from "../lib";
-
-export class CommentList {
- constructor(private elements: Promise<WebElement[]>, private selector: string, private browser: Browser) {}
-
- public async count(): Promise<number> {
- return (await this.elements).length;
- }
-}
diff --git a/tests/components/IdeaList.ts b/tests/components/IdeaList.ts
deleted file mode 100644
index 774deca4d..000000000
--- a/tests/components/IdeaList.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { WebElement, By } from "selenium-webdriver";
-import { Browser, WebComponent, WaitCondition } from "../lib";
-
-export class IdeaList {
- constructor(private elements: Promise<WebElement[]>, private selector: string, private browser: Browser) {}
-
- public async want(index: number) {
- await (await this.elements)[index].findElement(By.css(".c-support-counter button")).click();
- }
-
- public async navigateAndWait(index: number, condition: WaitCondition) {
- await (await this.elements)[index].findElement(By.css(".c-list-item-title")).click();
- await this.browser.wait(condition);
- }
-
- public async at(index: number): Promise<WebComponent> {
- const selector = ".c-support-counter button";
- const counter = (await this.elements)[index].findElement(By.css(selector));
- return new WebComponent(counter, selector);
- }
-}
diff --git a/tests/config.ts b/tests/config.ts
deleted file mode 100644
index 8b7c3e9cd..000000000
--- a/tests/config.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-const config = {
- baseUrl: process.env.BASE_URL || "http://demo.dev.fider.io:3000"
-};
-
-export default config;
diff --git a/tests/context.ts b/tests/context.ts
deleted file mode 100644
index f73f1dccb..000000000
--- a/tests/context.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { Browser } from "./lib";
-import { AllPages } from "./pages";
-
-export let pages: AllPages;
-export let browser: Browser;
-export let tenant: string;
-
-export const setPages = (value: AllPages) => {
- pages = value;
-};
-
-export const setBrowser = (value: Browser) => {
- browser = value;
-};
-
-export const setTenant = (value: string) => {
- if (process.env.HOST_MODE === "single") {
- tenant = "login";
- } else {
- tenant = value;
- }
-};
diff --git a/tests/e2e-multi.spec.ts b/tests/e2e-multi.spec.ts
deleted file mode 100644
index cace22792..000000000
--- a/tests/e2e-multi.spec.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-process.env.HOST_MODE = "multi";
-jest.setTimeout(30000);
-require("./testcases/email-signup");
-require("./testcases/entry");
diff --git a/tests/lib/browser.ts b/tests/lib/browser.ts
index f03cf885a..029998c42 100644
--- a/tests/lib/browser.ts
+++ b/tests/lib/browser.ts
@@ -1,69 +1,28 @@
-import "chromedriver";
-import { Builder, ThenableWebDriver, WebElement, Capabilities, By, WebElementPromise } from "selenium-webdriver";
-import { Page, NewablePage, WebComponent, WaitCondition, timeout } from "./";
+import * as puppeteer from "puppeteer";
+import { BrowserTab } from ".";
export class Browser {
- private driver: ThenableWebDriver;
- public constructor(private browserName: string) {
- this.driver = new Builder().forBrowser("chrome").build();
- this.driver
- .manage()
- .timeouts()
- .implicitlyWait(1000);
- }
-
- public async navigate(url: string): Promise<void> {
- await this.driver.navigate().to(url);
- }
-
- public async clearCookies(url?: string): Promise<void> {
- if (url) {
- const currentUrl = await this.driver.getCurrentUrl();
- await this.navigate(url);
- await this.driver.manage().deleteAllCookies();
- await this.navigate(currentUrl);
- }
- await this.driver.manage().deleteAllCookies();
- }
-
- public findElement(selector: string): WebElementPromise {
- return this.driver.findElement(By.css(selector));
- }
-
- public async findElements(selector: string): Promise<WebElement[]> {
- return await this.driver.findElements(By.css(selector));
- }
+ private browser: puppeteer.Browser;
- public async switchTo(element: string | WebElement): Promise<void> {
- if (typeof element === "string") {
- await this.driver.switchTo().frame(this.findElement(element));
- } else {
- return await this.driver.switchTo().frame(element);
- }
+ public constructor(browser: puppeteer.Browser) {
+ this.browser = browser;
}
- public async wait(condition: WaitCondition) {
- await this.waitAny(condition);
+ public static async launch(): Promise<Browser> {
+ const browser = await puppeteer.launch({
+ headless: false,
+ devtools: true
+ });
+ return new Browser(browser);
}
- public async waitAny(conditions: WaitCondition | WaitCondition[]): Promise<void> {
- const all = !(conditions instanceof Array) ? [conditions] : conditions;
-
- await this.driver.wait(async () => {
- for (const condition of all) {
- try {
- if ((await condition(this)) === true) {
- return true;
- }
- continue;
- } catch (ex) {
- continue;
- }
- }
- });
+ public async newTab(baseUrl: string): Promise<BrowserTab> {
+ const page = await this.browser.newPage();
+ await page.bringToFront();
+ return new BrowserTab(page, baseUrl);
}
public async close(): Promise<void> {
- await this.driver.quit();
+ await this.browser.close();
}
}
diff --git a/tests/lib/components.ts b/tests/lib/components.ts
index 574f12913..b86bf1e85 100644
--- a/tests/lib/components.ts
+++ b/tests/lib/components.ts
@@ -1,84 +1,95 @@
-import { WebElementPromise, Key, By } from "selenium-webdriver";
+import { elementIsVisible, BrowserTab } from ".";
export class WebComponent {
- constructor(protected element: WebElementPromise, public selector: string) {}
+ constructor(protected tab: BrowserTab, public selector: string) {}
public async click() {
- try {
- return await this.element.click();
- } catch (clickErr) {
- try {
- await this.element.getDriver().executeScript("arguments[0].click();", this.element);
- } catch (jsErr) {
- throw clickErr;
- }
- }
+ await this.tab.click(this.selector);
}
- public async getAttribute(attrName: string): Promise<string> {
- return await this.element.getAttribute(attrName);
+ public async getText(): Promise<string> {
+ return await this.tab.evaluate<string>(
+ (selector: string) => {
+ const el = document.querySelector(selector) as HTMLElement | undefined;
+ return el ? el.textContent : "";
+ },
+ [this.selector]
+ );
}
- public async isDisplayed() {
- try {
- return await this.element.isDisplayed();
- } catch (ex) {
- return false;
- }
+ public async getAttribute(attibuteName: string): Promise<string> {
+ return await this.tab.evaluate<string>(
+ (selector: string, attrName: string) => {
+ const el = document.querySelector(selector) as HTMLElement | undefined;
+ return el ? el.getAttribute(attrName) || "" : "";
+ },
+ [this.selector, attibuteName]
+ );
}
- public async getText() {
- if ((await this.element.getTagName()) === "input") {
- return await this.element.getAttribute("value");
- }
- return await this.element.getText();
+ public async isVisible(): Promise<boolean> {
+ const condition = elementIsVisible(this.selector);
+ const instance = condition(this.tab);
+ return this.tab.evaluate<boolean>(instance.function, instance.args);
}
}
export class Button extends WebComponent {
- constructor(element: WebElementPromise, selector: string) {
- super(element, selector);
- }
-
- public async isDisabled() {
- try {
- return (await this.element.getAttribute("disabled")) === "disabled";
- } catch (ex) {
- return false;
- }
+ constructor(protected tab: BrowserTab, selector: string) {
+ super(tab, selector);
}
}
export class DropDownList extends WebComponent {
- constructor(element: WebElementPromise, selector: string) {
- super(element, selector);
+ constructor(protected tab: BrowserTab, selector: string) {
+ super(tab, selector);
}
- public async selectByText(text: string) {
- const options = await this.element.findElements(By.tagName("option"));
- for (const option of options) {
- if ((await option.getText()) === text) {
- return await option.click();
- }
- }
- throw new Error(`No option found for text '${text}'.`);
+ public async selectByText(text: string): Promise<void> {
+ const value = await this.tab.evaluate<string>(
+ (selector: string, textToSelect: string) => {
+ const options = document.querySelectorAll(`${selector} option`);
+ for (const opt of options) {
+ if (opt && opt.textContent === textToSelect) {
+ return (opt as HTMLOptionElement).value;
+ }
+ }
+ return "";
+ },
+ [this.selector, text]
+ );
+ await this.tab.select(this.selector, value);
}
}
+export abstract class List {
+ constructor(protected tab: BrowserTab, public selector: string) {}
+ public abstract count(): Promise<number>;
+}
+
export class TextInput extends WebComponent {
- constructor(element: WebElementPromise, selector: string) {
- super(element, selector);
+ constructor(protected tab: BrowserTab, selector: string) {
+ super(tab, selector);
}
public async type(text: string) {
- await this.element.sendKeys(text);
+ await this.tab.type(this.selector, text);
+ const current = await this.getText();
+ if (current !== text) {
+ await this.clear();
+ await this.type(text);
+ }
+ }
+
+ public async getText(): Promise<string> {
+ return await this.tab.evaluate<string>(
+ (selector: string) => (document.querySelector(selector) as HTMLInputElement).value,
+ [this.selector]
+ );
}
public async clear() {
- const text = await this.getText();
- for (const char of text) {
- await this.element.sendKeys(Key.ARROW_RIGHT);
- await this.element.sendKeys(Key.BACK_SPACE);
- }
+ await this.tab.click(this.selector, { clickCount: 3 });
+ await this.tab.press("Backspace");
}
}
diff --git a/tests/lib/conditions.ts b/tests/lib/conditions.ts
index 0e92084b0..8ef7c107c 100644
--- a/tests/lib/conditions.ts
+++ b/tests/lib/conditions.ts
@@ -1,22 +1,48 @@
-import { Browser, WebComponent, NewablePage, Page } from "./";
+import { NewablePage, Page, BrowserTab, WebComponent } from ".";
-export type WaitCondition = (browser: Browser) => Promise<boolean>;
+export type WaitCondition = (
+ browser: BrowserTab
+) => {
+ function: (...args: any[]) => boolean;
+ args: any[];
+};
-export function elementIsVisible(locator: () => WebComponent): WaitCondition {
- return async () => await locator().isDisplayed();
-}
-
-export function elementIsNotVisible(locator: () => WebComponent): WaitCondition {
- return async () => (await locator().isDisplayed()) === false;
-}
+export const elementIsVisible = (target: string | WebComponent): WaitCondition => {
+ return (tab: BrowserTab) => {
+ const selector = typeof target === "string" ? target : target.selector;
+ return {
+ function: (query: string) => {
+ const node = document.querySelector(query);
+ if (!node) {
+ return false;
+ }
+ const style = window.getComputedStyle(node);
+ return style && style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
+ },
+ args: [selector]
+ };
+ };
+};
-export function elementIsPresent(locator: () => WebComponent): WaitCondition {
- return async () => (await locator()) !== undefined;
-}
+export const elementIsNotVisible = (target: string | WebComponent): WaitCondition => {
+ return (tab: BrowserTab) => {
+ const selector = typeof target === "string" ? target : target.selector;
+ return {
+ function: (query: string) => {
+ const node = document.querySelector(query);
+ if (!node) {
+ return true;
+ }
+ const style = window.getComputedStyle(node);
+ return style && (style.display === "none" || style.visibility === "hidden" || style.opacity === "0");
+ },
+ args: [selector]
+ };
+ };
+};
export function pageHasLoaded<T extends Page>(page: NewablePage<T>): WaitCondition {
- return (browser: Browser) => {
- const condition = new page(browser).loadCondition();
- return condition(browser);
+ return (tab: BrowserTab) => {
+ return new page(tab).loadCondition()(tab);
};
}
diff --git a/tests/lib/ensure.ts b/tests/lib/ensure.ts
index c5703c411..7de53a673 100644
--- a/tests/lib/ensure.ts
+++ b/tests/lib/ensure.ts
@@ -1,26 +1,25 @@
-import { WebElementPromise } from "selenium-webdriver";
-import { WebComponent, Button, TextInput, delay } from "./";
+import { WebComponent, Button, TextInput, delay, List } from ".";
-class WebComponentEnsurer {
- public async retry(fn: () => Promise<void>) {
- let count = 0;
- let lastErr: Error;
- do {
- try {
- return await fn();
- } catch (err) {
- lastErr = err;
- await delay(500);
- count++;
- }
- } while (count !== 3);
- throw lastErr;
- }
+const retry = async (fn: () => Promise<void>) => {
+ let count = 0;
+ let lastErr: Error;
+ do {
+ try {
+ return await fn();
+ } catch (err) {
+ lastErr = err;
+ await delay(500);
+ count++;
+ }
+ } while (count !== 3);
+ throw lastErr;
+};
- constructor(private component: WebComponent) {}
+class WebComponentEnsurer {
+ constructor(protected component: WebComponent) {}
public async textIs(expected: string) {
- await this.retry(async () => {
+ await retry(async () => {
const text = await this.component.getText();
if (expected.trim() !== text.trim()) {
@@ -30,62 +29,89 @@ class WebComponentEnsurer {
}
public async attributeIs(attrName: string, expected: string) {
- await this.retry(async () => {
- const value = await this.component.getAttribute(attrName);
+ await retry(async () => {
+ const attrValue = await this.component.getAttribute(attrName);
- if (value.trim() !== expected.trim()) {
+ if (expected.trim() !== attrValue.trim()) {
throw new Error(
- `Element ${this.component.selector} attribute '${attrName}' is '${value}'. Expected value is '${expected}'`
+ `Element ${this.component.selector} ${attrName} is '${attrValue}'. Expected value is '${expected}'`
);
}
});
}
- public async isVisible() {
- await this.retry(async () => {
- if (!(await this.component.isDisplayed())) {
- throw new Error(`Element ${this.component.selector} is not visible`);
- }
- });
- }
+ // public async attributeIs(attrName: string, expected: string) {
+ // await this.retry(async () => {
+ // const value = await this.component.getAttribute(attrName);
- public async isNotVisible() {
- await this.retry(async () => {
- if (await this.component.isDisplayed()) {
- throw new Error(`Element ${this.component.selector} is visible`);
- }
- });
- }
+ // if (value.trim() !== expected.trim()) {
+ // throw new Error(
+ // `Element ${this.component.selector} attribute '${attrName}' is '${value}'. Expected value is '${expected}'`
+ // );
+ // }
+ // });
+ // }
+
+ // public async isVisible() {
+ // await this.retry(async () => {
+ // if (!(await this.component.isDisplayed())) {
+ // throw new Error(`Element ${this.component.selector} is not visible`);
+ // }
+ // });
+ // }
+
+ // public async isNotVisible() {
+ // await this.retry(async () => {
+ // if (await this.component.isDisplayed()) {
+ // throw new Error(`Element ${this.component.selector} is visible`);
+ // }
+ // });
+ // }
}
class ButtonEnsurer extends WebComponentEnsurer {
- protected button: Button;
- constructor(button: Button) {
+ constructor(protected button: Button) {
super(button);
- this.button = button;
}
- public async isNotDisabled() {
- await this.retry(async () => {
- if (await this.button.isDisabled()) {
- throw new Error(`Button ${this.button.selector} is disabled`);
+ // public async isNotDisabled() {
+ // await this.retry(async () => {
+ // if (await this.button.isDisabled()) {
+ // throw new Error(`Button ${this.button.selector} is disabled`);
+ // }
+ // });
+ // }
+}
+
+class ListEnsurer {
+ constructor(protected list: List) {}
+
+ public async countIs(expected: number) {
+ await retry(async () => {
+ const count = await this.list.count();
+ if (count !== expected) {
+ throw new Error(`Count of ${this.list.selector} is ${count}, expected ${expected}`);
}
});
}
}
class TextInputEnsurer extends WebComponentEnsurer {
- constructor(element: TextInput) {
- super(element);
+ constructor(component: TextInput) {
+ super(component);
}
}
export function ensure(component: Button): ButtonEnsurer;
export function ensure(component: TextInput): TextInputEnsurer;
export function ensure(component: WebComponent): WebComponentEnsurer;
-export function ensure(component: WebComponent | Button): any {
+export function ensure(component: List): ListEnsurer;
+export function ensure(component: WebComponent): WebComponentEnsurer;
+export function ensure(component: WebComponent | List | Button): any {
if (component instanceof Button) {
return new ButtonEnsurer(component);
+ } else if (component instanceof List) {
+ return new ListEnsurer(component);
} else if (component instanceof WebComponent) {
return new WebComponentEnsurer(component);
}
diff --git a/tests/lib/index.ts b/tests/lib/index.ts
index 9b19d737c..05a6a3f0a 100644
--- a/tests/lib/index.ts
+++ b/tests/lib/index.ts
@@ -1,7 +1,8 @@
-export * from "./page";
-export * from "./browser";
-export * from "./utils";
-export * from "./ensure";
-export * from "./components";
export * from "./conditions";
+export * from "./components";
+export * from "./utils";
+export * from "./browser";
+export * from "./page";
+export * from "./tab";
export * from "./mailgun";
+export * from "./ensure";
diff --git a/tests/lib/mailgun/index.ts b/tests/lib/mailgun/index.ts
index e80c73148..bda9d3b21 100644
--- a/tests/lib/mailgun/index.ts
+++ b/tests/lib/mailgun/index.ts
@@ -23,7 +23,7 @@ const httpGet = (endpoint: string): Promise<any> => {
};
export const mailgun = {
- getLinkFromLastEmailTo: async (to: string): Promise<string> => {
+ getLinkFromLastEmailTo: async (tenant: string, to: string): Promise<string> => {
let messageUrl = "";
let count = 0;
@@ -31,7 +31,7 @@ export const mailgun = {
count++;
const url = `https://api.mailgun.net/v3/${
process.env.EMAIL_MAILGUN_DOMAIN
- }/events?to=${to}&event=accepted&limit=1&ascending=no`;
+ }/events?to=${to}&tags=tenant:${tenant}&event=accepted&limit=1&ascending=no`;
const events = await httpGet(url);
if (events.items.length > 0 && events.items[0].recipient === to) {
messageUrl = events.items[0].storage.url;
diff --git a/tests/lib/page.ts b/tests/lib/page.ts
index 32a0d14bb..c14adf9af 100644
--- a/tests/lib/page.ts
+++ b/tests/lib/page.ts
@@ -1,19 +1,20 @@
-import { Browser, WaitCondition } from "./";
+import { BrowserTab, WaitCondition } from ".";
export interface NewablePage<T extends Page> {
- new (browser: Browser): T;
+ new (tab: BrowserTab): T;
}
export abstract class Page {
public async navigate(): Promise<void> {
- await this.browser.navigate(this.getUrl());
- await this.browser.wait(this.loadCondition());
+ await this.tab.navigate(this.getUrl());
+ await this.tab.wait(this.loadCondition());
}
public abstract loadCondition(): WaitCondition;
+
protected getUrl(): string {
throw new Error("getUrl not implemented");
}
- public constructor(protected browser: Browser) {}
+ public constructor(protected tab: BrowserTab) {}
}
diff --git a/tests/lib/tab.ts b/tests/lib/tab.ts
new file mode 100644
index 000000000..f8ebb021e
--- /dev/null
+++ b/tests/lib/tab.ts
@@ -0,0 +1,72 @@
+import * as puppeteer from "puppeteer";
+import { AllPages } from "../pages";
+import { WaitCondition, Page, NewablePage } from ".";
+import { pageHasLoaded } from "./conditions";
+
+export class BrowserTab {
+ private page: puppeteer.Page;
+ public pages: AllPages;
+ public baseUrl: string;
+
+ public constructor(page: puppeteer.Page, baseUrl: string) {
+ this.page = page;
+ this.baseUrl = baseUrl;
+ this.pages = new AllPages(this);
+ }
+
+ public async navigate(url: string): Promise<void> {
+ await this.page.goto(url);
+ }
+
+ public async reload<T extends Page>(page: NewablePage<T>): Promise<void> {
+ await this.page.goto(this.page.url());
+ await this.wait(pageHasLoaded(page));
+ }
+
+ public async clearCookies(): Promise<void> {
+ const cookies = (await this.page.cookies()).map(x => ({ name: x.name }));
+ await this.page.deleteCookie(...cookies);
+ }
+
+ public async wait(condition: WaitCondition, timeout = 30000): Promise<void> {
+ const inst = condition(this);
+ await this.page.waitForFunction(inst.function, { timeout }, ...inst.args);
+ }
+
+ public async press(key: string): Promise<void> {
+ await this.page.keyboard.press(key);
+ }
+
+ public async click(selector: string, options?: puppeteer.ClickOptions): Promise<void> {
+ await this.page.click(selector, options);
+ }
+
+ public async type(selector: string, text: string): Promise<void> {
+ await this.page.type(selector, text);
+ }
+
+ public async select(selector: string, value: string): Promise<void> {
+ await this.page.select(selector, value);
+ }
+
+ public async evaluate<T>(fn: puppeteer.EvaluateFn, args: any[]): Promise<T> {
+ return await this.page.evaluate(fn, ...args);
+ }
+
+ public async waitAny(conditions: WaitCondition | WaitCondition[]): Promise<void> {
+ const all = !(conditions instanceof Array) ? [conditions] : conditions;
+
+ let retry = 20;
+ do {
+ for (const condition of all) {
+ retry--;
+ try {
+ await this.wait(condition, 200);
+ return;
+ } catch (ex) {
+ continue;
+ }
+ }
+ } while (retry >= 0);
+ }
+}
diff --git a/tests/lib/utils.ts b/tests/lib/utils.ts
index 3e54668bd..0757c07c3 100644
--- a/tests/lib/utils.ts
+++ b/tests/lib/utils.ts
@@ -1,40 +1,18 @@
import "reflect-metadata";
-import { ThenableWebDriver, WebElementPromise } from "selenium-webdriver";
-import { Browser } from "./";
export const delay = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms));
};
-export const timeout = (ms: number) => {
- return new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), ms));
-};
-
-export function findBy(selector: string, t?: new (element: WebElementPromise, selector: string) => any) {
- return (target: any, propertyKey: string) => {
- const type = Reflect.getMetadata("design:type", target, propertyKey);
- Object.defineProperty(target, propertyKey, {
- configurable: true,
- enumerable: true,
- get() {
- const browser = (this as any).browser;
- const promise = (browser as Browser).findElement(selector);
- return new type(promise, selector, browser);
- }
- });
- };
-}
-
-export function findMultipleBy(selector: string, t?: new (element: WebElementPromise, selector: string) => any) {
+export function findBy(selector: string) {
return (target: any, propertyKey: string) => {
const type = Reflect.getMetadata("design:type", target, propertyKey);
Object.defineProperty(target, propertyKey, {
configurable: true,
enumerable: true,
get() {
- const browser = (this as any).browser;
- const promise = (browser as Browser).findElements(selector);
- return new type(promise, selector, browser);
+ const tab = (this as any).tab;
+ return new type(tab, selector);
}
});
};
diff --git a/tests/multi.spec.ts b/tests/multi.spec.ts
new file mode 100644
index 000000000..7dde8c499
--- /dev/null
+++ b/tests/multi.spec.ts
@@ -0,0 +1,4 @@
+process.env.HOST_MODE = "multi";
+jest.setTimeout(30000);
+require("./scenarios/email-signup");
+require("./scenarios/index");
diff --git a/tests/pages/AdminSettingsPage.ts b/tests/pages/AdminSettingsPage.ts
deleted file mode 100644
index ed28aa5bc..000000000
--- a/tests/pages/AdminSettingsPage.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import {
- WebComponent,
- Browser,
- Page,
- findBy,
- findMultipleBy,
- Button,
- TextInput,
- elementIsVisible,
- elementIsNotVisible,
- pageHasLoaded
-} from "../lib";
-import { tenant } from "../context";
-
-export class AdminSettingsPage extends Page {
- constructor(browser: Browser) {
- super(browser);
- }
-
- public getUrl(): string {
- return `http://${tenant}.dev.fider.io:3000/admin`;
- }
-
- @findBy("#p-admin-general #input-title") public TitleInput!: TextInput;
- @findBy("#p-admin-general #input-welcomeMessage") public WelcomeMessageInput!: TextInput;
- @findBy("#p-admin-general #input-invitation") public InvitationInput!: TextInput;
- @findBy("#p-admin-general .c-button.m-positive") public ConfirmButton!: Button;
-
- public loadCondition() {
- return elementIsVisible(() => this.TitleInput);
- }
-}
diff --git a/tests/pages/FacebookSignInPage.ts b/tests/pages/FacebookSignInPage.ts
index 7f3cbfcc0..b01c64e4c 100644
--- a/tests/pages/FacebookSignInPage.ts
+++ b/tests/pages/FacebookSignInPage.ts
@@ -1,10 +1,9 @@
-import { TextInput, Button, Browser, WebComponent, Page, findBy, elementIsPresent, pageHasLoaded } from "../lib";
-import { HomePage, SignUpPage } from "./";
-import config from "../config";
+import { findBy, Page, BrowserTab, TextInput, elementIsVisible, Button, pageHasLoaded } from "../lib";
+import { HomePage, SignUpPage } from ".";
export class FacebookSignInPage extends Page {
- constructor(browser: Browser) {
- super(browser);
+ constructor(tab: BrowserTab) {
+ super(tab);
}
@findBy("#email") public Email!: TextInput;
@@ -12,7 +11,7 @@ export class FacebookSignInPage extends Page {
@findBy("#loginbutton") public Confirm!: Button;
public loadCondition() {
- return elementIsPresent(() => this.Email);
+ return elementIsVisible(this.Email);
}
public async signInAsJonSnow() {
@@ -27,6 +26,6 @@ export class FacebookSignInPage extends Page {
await this.Email.type(email);
await this.Password.type(password);
await this.Confirm.click();
- await this.browser.waitAny([pageHasLoaded(HomePage), pageHasLoaded(SignUpPage)]);
+ await this.tab.waitAny([pageHasLoaded(HomePage), pageHasLoaded(SignUpPage)]);
}
}
diff --git a/tests/pages/GeneralSettingsPage.ts b/tests/pages/GeneralSettingsPage.ts
new file mode 100644
index 000000000..6a56eace9
--- /dev/null
+++ b/tests/pages/GeneralSettingsPage.ts
@@ -0,0 +1,42 @@
+import {
+ BrowserTab,
+ WaitCondition,
+ Page,
+ elementIsVisible,
+ findBy,
+ TextInput,
+ WebComponent,
+ Button,
+ pageHasLoaded
+} from "../lib";
+import { HomePage, FacebookSignInPage } from ".";
+
+export class GeneralSettingsPage extends Page {
+ constructor(tab: BrowserTab) {
+ super(tab);
+ }
+
+ public getUrl(): string {
+ return `${this.tab.baseUrl}/admin`;
+ }
+
+ @findBy("#p-admin-general #input-title") private TitleInput!: TextInput;
+ @findBy("#p-admin-general #input-welcomeMessage") private WelcomeMessageInput!: TextInput;
+ @findBy("#p-admin-general #input-invitation") private InvitationInput!: TextInput;
+ @findBy("#p-admin-general .c-button.m-positive") private SaveChangesButton!: Button;
+
+ public loadCondition(): WaitCondition {
+ return elementIsVisible(this.TitleInput);
+ }
+
+ public async changeSettings(title: string, welcomeMessage: string, invitation: string): Promise<void> {
+ await this.TitleInput.clear();
+ await this.TitleInput.type(title);
+ await this.WelcomeMessageInput.clear();
+ await this.WelcomeMessageInput.type(welcomeMessage);
+ await this.InvitationInput.clear();
+ await this.InvitationInput.type(invitation);
+ await this.SaveChangesButton.click();
+ await this.tab.wait(pageHasLoaded(HomePage));
+ }
+}
diff --git a/tests/pages/GoogleSignInPage.ts b/tests/pages/GoogleSignInPage.ts
deleted file mode 100644
index 03d04478c..000000000
--- a/tests/pages/GoogleSignInPage.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import {
- TextInput,
- Button,
- Browser,
- WebComponent,
- Page,
- findBy,
- elementIsVisible,
- elementIsPresent,
- pageHasLoaded
-} from "../lib";
-import { HomePage, SignUpPage } from "./";
-import config from "../config";
-
-export class GoogleSignInPage extends Page {
- constructor(browser: Browser) {
- super(browser);
- }
-
- @findBy("#view_container") private Container!: WebComponent;
- @findBy("#identifierId") public Email!: TextInput;
- @findBy("#identifierNext") public ConfirmEmail!: Button;
- @findBy('input[type="password"]') public Password!: TextInput;
- @findBy("#passwordNext") public ConfirmPassword!: Button;
-
- public loadCondition() {
- return elementIsPresent(() => this.Container);
- }
-
- public async signInAsDarthVader() {
- return this.signInAs("[email protected]", process.env.DARTHVADER_PASSWORD!);
- }
-
- public async signInAs(email: string, password: string) {
- try {
- const element = await this.browser.findElement(`p[data-email='${email}']`);
- await element.click();
- } catch (ex) {
- await this.browser.wait(elementIsVisible(() => this.Email));
- await this.Email.type(email);
- await this.ConfirmEmail.click();
- }
-
- await this.browser.wait(elementIsVisible(() => this.Password));
- await this.Password.type(password);
- await this.ConfirmPassword.click();
- await this.browser.waitAny([pageHasLoaded(HomePage), pageHasLoaded(SignUpPage)]);
- }
-}
diff --git a/tests/pages/HomePage.ts b/tests/pages/HomePage.ts
index e49563c0e..0e6adcf9b 100644
--- a/tests/pages/HomePage.ts
+++ b/tests/pages/HomePage.ts
@@ -1,28 +1,24 @@
import {
- WebComponent,
- Browser,
+ BrowserTab,
Page,
findBy,
- findMultipleBy,
- Button,
TextInput,
elementIsVisible,
- elementIsNotVisible,
- pageHasLoaded
+ WebComponent,
+ pageHasLoaded,
+ Button,
+ elementIsNotVisible
} from "../lib";
-import { ShowIdeaPage, GoogleSignInPage, FacebookSignInPage } from "./";
-import config from "../config";
-import { tenant } from "../context";
-
-import { IdeaList } from "../components/IdeaList";
+import { ShowIdeaPage, FacebookSignInPage } from ".";
+import { IdeaList } from "./components";
export class HomePage extends Page {
- constructor(browser: Browser) {
- super(browser);
+ constructor(tab: BrowserTab) {
+ super(tab);
}
public getUrl(): string {
- return `http://${tenant}.dev.fider.io:3000/`;
+ return `${this.tab.baseUrl}/`;
}
@findBy(".c-menu-item-title") public MenuTitle!: WebComponent;
@@ -31,73 +27,62 @@ export class HomePage extends Page {
@findBy("#input-description") public IdeaDescription!: TextInput;
@findBy(".c-button.m-positive") public SubmitIdea!: Button;
@findBy(".c-menu-item-signin") public UserMenu!: WebComponent;
+ @findBy(".c-unread-count") public UnreadCounter!: WebComponent;
@findBy(".c-menu-user-heading") public UserName!: WebComponent;
@findBy(".c-modal-window") public SignInModal!: WebComponent;
- @findBy(".c-modal-window .c-button.m-google") public GoogleSignIn!: Button;
@findBy(".c-modal-window .c-button.m-facebook") public FacebookSignIn!: Button;
@findBy(".c-modal-window .c-signin-control #input-email") private EmailSignInInput!: TextInput;
@findBy(".c-modal-window .c-signin-control .c-button.m-positive") private EmailSignInButton!: TextInput;
@findBy(".signout") private SignOut!: Button;
- @findMultipleBy(".c-idea-list > .c-list-item") public IdeaList!: IdeaList;
+ @findBy(".c-idea-list") public IdeaList!: IdeaList;
@findBy(".c-modal-window input") private CompleteEmailSignInInput!: TextInput;
@findBy(".c-modal-window button") private CompleteEmailSignInButton!: Button;
public loadCondition() {
- return elementIsVisible(() => this.IdeaTitle);
+ return elementIsVisible("#p-home");
}
public async submitNewIdea(title: string, description: string): Promise<void> {
await this.IdeaTitle.type(title);
await this.IdeaDescription.type(description);
await this.SubmitIdea.click();
- await this.browser.wait(pageHasLoaded(ShowIdeaPage));
+ await this.tab.wait(pageHasLoaded(ShowIdeaPage));
}
public async signOut(): Promise<void> {
- try {
+ if (await this.SignOut.isVisible()) {
+ await this.UserMenu.click();
await this.SignOut.click();
- } catch (ex) {
- return;
+ await this.tab.wait(pageHasLoaded(HomePage));
}
- await this.browser.wait(pageHasLoaded(HomePage));
- }
-
- public async signInWithGoogle(): Promise<void> {
- await this.browser.clearCookies("https://accounts.google.com");
- await this.signOut();
-
- await this.signIn(() => this.GoogleSignIn);
- await this.browser.waitAny([pageHasLoaded(GoogleSignInPage), pageHasLoaded(HomePage)]);
}
public async signInWithFacebook(): Promise<void> {
- await this.browser.clearCookies("https://facebook.com");
await this.signOut();
-
- await this.signIn(() => this.FacebookSignIn);
- await this.browser.waitAny([pageHasLoaded(FacebookSignInPage), pageHasLoaded(HomePage)]);
+ await this.signIn(this.FacebookSignIn);
+ await this.tab.wait(pageHasLoaded(FacebookSignInPage));
}
public async signInWithEmail(email: string): Promise<void> {
await this.signOut();
await this.UserMenu.click();
- await this.browser.wait(elementIsVisible(() => this.EmailSignInInput));
+ await this.tab.wait(elementIsVisible(this.EmailSignInInput));
await this.EmailSignInInput.type(email);
await this.EmailSignInButton.click();
- await this.browser.wait(elementIsNotVisible(() => this.EmailSignInButton));
+ await this.tab.wait(elementIsNotVisible(this.EmailSignInButton));
}
public async completeSignIn(name: string): Promise<void> {
- await this.browser.wait(elementIsVisible(() => this.CompleteEmailSignInInput));
+ await this.tab.wait(elementIsVisible(this.CompleteEmailSignInInput));
await this.CompleteEmailSignInInput.type(name);
await this.CompleteEmailSignInButton.click();
- await this.browser.wait(elementIsNotVisible(() => this.CompleteEmailSignInInput));
- await this.browser.wait(this.loadCondition());
+ await this.tab.wait(elementIsNotVisible(this.CompleteEmailSignInInput));
+ await this.tab.wait(this.loadCondition());
}
- private async signIn(locator: () => WebComponent): Promise<void> {
+ private async signIn(locator: WebComponent): Promise<void> {
await this.UserMenu.click();
- await this.browser.wait(elementIsVisible(locator));
- await locator().click();
+ await this.tab.wait(elementIsVisible(locator));
+ await locator.click();
}
}
diff --git a/tests/pages/ShowIdeaPage.ts b/tests/pages/ShowIdeaPage.ts
index 61916002f..cbb141991 100644
--- a/tests/pages/ShowIdeaPage.ts
+++ b/tests/pages/ShowIdeaPage.ts
@@ -1,19 +1,9 @@
-import {
- WebComponent,
- TextInput,
- Button,
- DropDownList,
- Browser,
- Page,
- findBy,
- findMultipleBy,
- elementIsVisible
-} from "../lib";
-import { CommentList } from "../components/CommentList";
+import { BrowserTab, Page, WebComponent, TextInput, Button, findBy, elementIsVisible, DropDownList } from "../lib";
+import { CommentList } from "./components";
export class ShowIdeaPage extends Page {
- constructor(browser: Browser) {
- super(browser);
+ constructor(tab: BrowserTab) {
+ super(tab);
}
@findBy(".idea-header h1") public Title!: WebComponent;
@@ -21,23 +11,46 @@ export class ShowIdeaPage extends Page {
@findBy(".c-segment.l-response .status-label") public Status!: WebComponent;
@findBy(".c-segment.l-response .content") public ResponseText!: WebComponent;
@findBy(".c-support-counter button") public SupportCounter!: WebComponent;
- @findBy(".c-comment-input #input-content") public CommentInput!: TextInput;
- @findBy(".c-comment-input .c-button.m-positive") public SubmitCommentButton!: Button;
- @findMultipleBy(".c-comment-list .c-comment") public CommentList!: CommentList;
@findBy(".action-col .c-button.respond") public RespondButton!: Button;
@findBy(".c-modal-window .c-response-form") public ResponseModal!: WebComponent;
+ @findBy(".c-comment-list") public Comments!: CommentList;
+
@findBy(".c-modal-window .c-response-form #input-status") private ResponseModalStatus!: DropDownList;
@findBy(".c-modal-window .c-response-form #input-text") private ResponseModalText!: TextInput;
@findBy(".c-modal-window .c-modal-footer .c-button.m-positive") private ResponseModalSubmitButton!: Button;
+ @findBy(".c-comment-input #input-content") private CommentInput!: TextInput;
+ @findBy(".c-comment-input .c-button.m-positive") private SubmitCommentButton!: Button;
+
+ @findBy(".action-col .c-button.edit") private Edit!: Button;
+ @findBy("#input-title") private EditTitle!: TextInput;
+ @findBy("#input-description") private EditDescription!: TextInput;
+ @findBy(".action-col .c-button.save") private SaveEdit!: Button;
+
public loadCondition() {
- return elementIsVisible(() => this.Title);
+ return elementIsVisible(this.Title);
}
public async changeStatus(status: string, text: string): Promise<void> {
+ await this.RespondButton.click();
+ await this.tab.wait(elementIsVisible(this.ResponseModal));
await this.ResponseModalStatus.selectByText(status);
await this.ResponseModalText.clear();
await this.ResponseModalText.type(text);
await this.ResponseModalSubmitButton.click();
}
+
+ public async edit(newTitle: string, newDescription: string): Promise<void> {
+ await this.Edit.click();
+ await this.EditTitle.clear();
+ await this.EditTitle.type(newTitle);
+ await this.EditDescription.clear();
+ await this.EditDescription.type(newDescription);
+ await this.SaveEdit.click();
+ }
+
+ public async comment(text: string): Promise<void> {
+ await this.CommentInput.type(text);
+ await this.SubmitCommentButton.click();
+ }
}
diff --git a/tests/pages/SignUpPage.ts b/tests/pages/SignUpPage.ts
index cc41912d7..aecfee73a 100644
--- a/tests/pages/SignUpPage.ts
+++ b/tests/pages/SignUpPage.ts
@@ -1,17 +1,26 @@
-import { WebComponent, Browser, Page, Button, TextInput, findBy, elementIsVisible, pageHasLoaded } from "../lib";
-import { GoogleSignInPage, FacebookSignInPage, HomePage } from "./";
+import {
+ BrowserTab,
+ WaitCondition,
+ Page,
+ elementIsVisible,
+ findBy,
+ TextInput,
+ WebComponent,
+ Button,
+ pageHasLoaded
+} from "../lib";
+import { HomePage, FacebookSignInPage } from ".";
export class SignUpPage extends Page {
- constructor(browser: Browser) {
- super(browser);
+ constructor(tab: BrowserTab) {
+ super(tab);
}
public getUrl(): string {
- return `http://login.dev.fider.io:3000/signup`;
+ return `${this.tab.baseUrl}/signup`;
}
@findBy("#p-signup") private Container!: WebComponent;
- @findBy("#p-signup .c-button.m-google") public GoogleSignIn!: Button;
@findBy("#p-signup .c-button.m-facebook") public FacebookSignIn!: Button;
@findBy("#p-signup #input-name") public UserName!: TextInput;
@findBy("#p-signup #input-email") public UserEmail!: TextInput;
@@ -21,18 +30,13 @@ export class SignUpPage extends Page {
@findBy("#p-signup .c-message.m-success") private SubdomainOk!: WebComponent;
@findBy(".c-modal-window") private ConfirmationModal!: WebComponent;
- public loadCondition() {
- return elementIsVisible(() => this.Container);
- }
-
- public async signInWithGoogle(): Promise<void> {
- await this.GoogleSignIn.click();
- await this.browser.wait(pageHasLoaded(GoogleSignInPage));
+ public loadCondition(): WaitCondition {
+ return elementIsVisible(this.Container);
}
public async signInWithFacebook(): Promise<void> {
await this.FacebookSignIn.click();
- await this.browser.wait(pageHasLoaded(FacebookSignInPage));
+ await this.tab.wait(pageHasLoaded(FacebookSignInPage));
}
public async signInWithEmail(name: string, email: string): Promise<void> {
@@ -42,11 +46,11 @@ export class SignUpPage extends Page {
public async signUpAs(name: string, subdomain: string): Promise<void> {
await this.TenantName.type(name);
- if (await this.Subdomain.isDisplayed()) {
+ if (await this.Subdomain.isVisible()) {
await this.Subdomain.type(subdomain);
- await this.browser.wait(elementIsVisible(() => this.SubdomainOk));
+ await this.tab.wait(elementIsVisible(this.SubdomainOk));
}
await this.Confirm.click();
- await this.browser.waitAny([pageHasLoaded(HomePage), elementIsVisible(() => this.ConfirmationModal)]);
+ await this.tab.waitAny([pageHasLoaded(HomePage), elementIsVisible(this.ConfirmationModal)]);
}
}
diff --git a/tests/pages/components/CommentList.ts b/tests/pages/components/CommentList.ts
new file mode 100644
index 000000000..c105d6b52
--- /dev/null
+++ b/tests/pages/components/CommentList.ts
@@ -0,0 +1,16 @@
+import { BrowserTab, List } from "../../lib";
+
+export class CommentList extends List {
+ constructor(tab: BrowserTab, selector: string) {
+ super(tab, selector);
+ }
+
+ public async count(): Promise<number> {
+ return await this.tab.evaluate<number>(
+ (selector: string) => {
+ return document.querySelectorAll(`${selector} .c-comment`).length;
+ },
+ [this.selector]
+ );
+ }
+}
diff --git a/tests/pages/components/IdeaList.ts b/tests/pages/components/IdeaList.ts
new file mode 100644
index 000000000..3eebc596a
--- /dev/null
+++ b/tests/pages/components/IdeaList.ts
@@ -0,0 +1,41 @@
+import { WebComponent, BrowserTab, pageHasLoaded } from "../../lib";
+import { ShowIdeaPage } from "..";
+
+export class IdeaItem {
+ public Vote: WebComponent;
+ private Link: WebComponent;
+
+ constructor(protected tab: BrowserTab, public selector: string) {
+ this.Vote = new WebComponent(tab, `${this.selector} .c-support-counter button`);
+ this.Link = new WebComponent(tab, `${this.selector} .c-list-item-title`);
+ }
+
+ public async navigate(): Promise<void> {
+ await this.Link.click();
+ await this.tab.wait(pageHasLoaded(ShowIdeaPage));
+ }
+}
+
+export class IdeaList {
+ constructor(protected tab: BrowserTab, public selector: string) {}
+
+ private async findIdeaIndex(title: string): Promise<number> {
+ return this.tab.evaluate<number>(
+ (text: string, selector: string) => {
+ const elements = document.querySelectorAll(`${selector} .c-list-item-title`);
+ for (let i = 0; i <= elements.length; i++) {
+ if (elements[i].textContent === text) {
+ return i;
+ }
+ }
+ return -1;
+ },
+ [title, this.selector]
+ );
+ }
+
+ public async get(title: string): Promise<IdeaItem> {
+ const idx = await this.findIdeaIndex(title);
+ return new IdeaItem(this.tab, `${this.selector} > .c-list-item:nth-child(${idx + 1})`);
+ }
+}
diff --git a/tests/pages/components/index.ts b/tests/pages/components/index.ts
new file mode 100644
index 000000000..57b8ae27e
--- /dev/null
+++ b/tests/pages/components/index.ts
@@ -0,0 +1,2 @@
+export * from "./IdeaList";
+export * from "./CommentList";
diff --git a/tests/pages/index.ts b/tests/pages/index.ts
index d861148f2..becc958d7 100644
--- a/tests/pages/index.ts
+++ b/tests/pages/index.ts
@@ -1,35 +1,28 @@
-import { GoogleSignInPage } from "./GoogleSignInPage";
-import { FacebookSignInPage } from "./FacebookSignInPage";
import { HomePage } from "./HomePage";
-import { AdminSettingsPage } from "./AdminSettingsPage";
-import { ShowIdeaPage } from "./ShowIdeaPage";
import { SignUpPage } from "./SignUpPage";
-import { Browser } from "../lib";
+import { FacebookSignInPage } from "./FacebookSignInPage";
+import { GeneralSettingsPage } from "./GeneralSettingsPage";
+import { ShowIdeaPage } from "./ShowIdeaPage";
+import { BrowserTab } from "../lib";
-export { GoogleSignInPage, HomePage, SignUpPage, ShowIdeaPage, FacebookSignInPage, AdminSettingsPage };
+export { SignUpPage, ShowIdeaPage, HomePage, FacebookSignInPage, GeneralSettingsPage };
export class AllPages {
- public google: GoogleSignInPage;
- public facebook: FacebookSignInPage;
public home: HomePage;
- public adminSettings: AdminSettingsPage;
public signup: SignUpPage;
public showIdea: ShowIdeaPage;
+ public facebook: FacebookSignInPage;
+ public generalSettings: GeneralSettingsPage;
- constructor(public browser: Browser) {
- this.google = new GoogleSignInPage(browser);
- this.facebook = new FacebookSignInPage(browser);
- this.home = new HomePage(browser);
- this.signup = new SignUpPage(browser);
- this.showIdea = new ShowIdeaPage(browser);
- this.adminSettings = new AdminSettingsPage(browser);
+ constructor(public tab: BrowserTab) {
+ this.home = new HomePage(tab);
+ this.signup = new SignUpPage(tab);
+ this.showIdea = new ShowIdeaPage(tab);
+ this.facebook = new FacebookSignInPage(tab);
+ this.generalSettings = new GeneralSettingsPage(tab);
}
public async goTo(url: string): Promise<void> {
- return this.browser.navigate(url);
- }
-
- public async dispose(): Promise<void> {
- await this.browser.close();
+ return this.tab.navigate(url);
}
}
diff --git a/tests/scenarios/admin-settings.ts b/tests/scenarios/admin-settings.ts
new file mode 100644
index 000000000..33f8d2863
--- /dev/null
+++ b/tests/scenarios/admin-settings.ts
@@ -0,0 +1,13 @@
+import { ensure } from "../lib";
+import { ctx } from ".";
+
+it("Tab1: User can change general settings", async () => {
+ // Action
+ await ctx.tab1.pages.generalSettings.navigate();
+ await ctx.tab1.pages.generalSettings.changeSettings("Feedback for X", "Leave your feedback below", "Enter here...");
+
+ // Assert
+ await ensure(ctx.tab1.pages.home.MenuTitle).textIs("Feedback for X");
+ await ensure(ctx.tab1.pages.home.IdeaTitle).attributeIs("placeholder", "Enter here...");
+ await ensure(ctx.tab1.pages.home.WelcomeMessage).textIs("Leave your feedback below");
+});
diff --git a/tests/scenarios/email-signup.ts b/tests/scenarios/email-signup.ts
new file mode 100644
index 000000000..fa7d86c26
--- /dev/null
+++ b/tests/scenarios/email-signup.ts
@@ -0,0 +1,33 @@
+import { Browser, BrowserTab, mailgun, pageHasLoaded, ensure } from "../lib";
+import { HomePage } from "../pages";
+
+describe("E2E: Sign up with e-mail", () => {
+ let browser: Browser;
+ let tab: BrowserTab;
+
+ beforeAll(async () => {
+ browser = await Browser.launch();
+ tab = await browser.newTab("http://login.dev.fider.io:3000");
+ });
+
+ afterAll(async () => {
+ await browser.close();
+ });
+
+ it("User can sign up using email", async () => {
+ const now = new Date().getTime();
+
+ // Action
+ await tab.pages.signup.navigate();
+ await tab.pages.signup.signInWithEmail(`Darth Vader ${now}`, `[email protected]`);
+ await tab.pages.signup.signUpAs(`Selenium ${now}`, `selenium${now}`);
+
+ const link = await mailgun.getLinkFromLastEmailTo(`selenium${now}`, `[email protected]`);
+
+ await tab.pages.goTo(link);
+ await tab.wait(pageHasLoaded(HomePage));
+
+ // Assert
+ await ensure(tab.pages.home.UserName).textIs(`Darth Vader ${now}`);
+ });
+});
diff --git a/tests/scenarios/feedback-loop.ts b/tests/scenarios/feedback-loop.ts
new file mode 100644
index 000000000..6fcb178e8
--- /dev/null
+++ b/tests/scenarios/feedback-loop.ts
@@ -0,0 +1,147 @@
+import {
+ Browser,
+ BrowserTab,
+ pageHasLoaded,
+ ensure,
+ elementIsNotVisible,
+ delay,
+ elementIsVisible,
+ mailgun
+} from "../lib";
+import { HomePage, ShowIdeaPage } from "../pages";
+import { ctx } from ".";
+
+it("Tab1: User is authenticated after sign up", async () => {
+ // Action
+ await ctx.tab1.pages.home.navigate();
+
+ // Assert
+ await ensure(ctx.tab1.pages.home.UserName).textIs("Jon Snow");
+});
+
+it("Tab1: User doesn't lose what they typed", async () => {
+ // Action
+ await ctx.tab1.pages.home.navigate();
+ await ctx.tab1.pages.home.IdeaTitle.type("My Great Idea");
+ await ctx.tab1.pages.home.IdeaDescription.type("With an awesome description");
+ await ctx.tab1.pages.home.IdeaTitle.clear();
+ await ctx.tab1.pages.home.IdeaTitle.type("My Great Idea has a new title");
+
+ // Assert
+ await ensure(ctx.tab1.pages.home.IdeaTitle).textIs("My Great Idea has a new title");
+ await ensure(ctx.tab1.pages.home.IdeaDescription).textIs("With an awesome description");
+
+ // Action
+ await ctx.tab1.pages.home.navigate();
+
+ // Assert
+ await ensure(ctx.tab1.pages.home.IdeaTitle).textIs("My Great Idea has a new title");
+ await ensure(ctx.tab1.pages.home.IdeaDescription).textIs("With an awesome description");
+
+ // Action
+ await ctx.tab1.pages.home.IdeaDescription.clear();
+ await ctx.tab1.pages.home.IdeaTitle.clear();
+ await ctx.tab1.pages.home.navigate();
+
+ // Assert
+ await ensure(ctx.tab1.pages.home.IdeaTitle).textIs("");
+ await ctx.tab1.wait(elementIsNotVisible(ctx.tab1.pages.home.IdeaDescription));
+});
+
+it("Tab1: Can submit ideas", async () => {
+ // Action
+ await ctx.tab1.pages.home.navigate();
+ await ctx.tab1.pages.home.submitNewIdea(
+ "Add support to TypeScript",
+ "Because the language and community is awesome! :)"
+ );
+
+ // Assert
+ await ensure(ctx.tab1.pages.showIdea.Title).textIs("Add support to TypeScript");
+ await ensure(ctx.tab1.pages.showIdea.Description).textIs("Because the language and community is awesome! :)");
+ await ensure(ctx.tab1.pages.showIdea.SupportCounter).textIs("1");
+});
+
+it("Tab1: Can edit title and description", async () => {
+ // Action
+ await ctx.tab1.pages.showIdea.edit("Support for TypeScript", "Because the language and community is awesome!");
+
+ // Assert
+ await ensure(ctx.tab1.pages.showIdea.Title).textIs("Support for TypeScript");
+ await ensure(ctx.tab1.pages.showIdea.Description).textIs("Because the language and community is awesome!");
+ await ensure(ctx.tab1.pages.showIdea.SupportCounter).textIs("1");
+});
+
+it("Tab2: Can login as another user", async () => {
+ // Action
+ await ctx.tab2.pages.home.navigate();
+ await ctx.tab2.pages.home.signInWithFacebook();
+ await ctx.tab2.pages.facebook.signInAsAryaStark();
+ await ctx.tab2.wait(pageHasLoaded(HomePage));
+
+ // Assert
+ await ensure(ctx.tab2.pages.home.UserName).textIs("Arya Stark");
+});
+
+it("Tab2: User can vote on idea", async () => {
+ // Action
+ await ctx.tab2.pages.home.navigate();
+ const item = await ctx.tab2.pages.home.IdeaList.get("Support for TypeScript");
+ await item.Vote.click();
+
+ // Assert
+ await ensure(item.Vote).textIs("2");
+});
+
+it("Tab2: Open idea and vote on it", async () => {
+ // Action
+ const item = await ctx.tab2.pages.home.IdeaList.get("Support for TypeScript");
+ await item.navigate();
+ await ctx.tab2.pages.showIdea.comment("I support this request!");
+
+ // Assert
+ await ensure(ctx.tab2.pages.showIdea.Comments).countIs(1);
+});
+
+it("Tab1: Open idea and change status", async () => {
+ // Action
+ await ctx.tab1.pages.home.navigate();
+ const item = await ctx.tab1.pages.home.IdeaList.get("Support for TypeScript");
+ await item.navigate();
+ await ctx.tab1.pages.showIdea.changeStatus("Started", "This will be delivered on next release.");
+ await ctx.tab1.wait(elementIsVisible(ctx.tab1.pages.showIdea.Status));
+
+ // Assert
+ await ensure(ctx.tab1.pages.showIdea.Status).textIs("Started");
+ await ensure(ctx.tab1.pages.showIdea.ResponseText).textIs("This will be delivered on next release.");
+});
+
+it("Tab2: Refresh and see status", async () => {
+ // Action
+ await ctx.tab2.reload(ShowIdeaPage);
+
+ // Assert
+ await ensure(ctx.tab1.pages.showIdea.Status).textIs("Started");
+ await ensure(ctx.tab1.pages.showIdea.ResponseText).textIs("This will be delivered on next release.");
+});
+
+it("Tab2: Check notifications", async () => {
+ // Action
+ await ctx.tab2.pages.home.navigate();
+ await ctx.tab2.pages.home.UserMenu.click();
+
+ // Assert
+ await ensure(ctx.tab2.pages.home.UnreadCounter).textIs("1");
+});
+
+it("Tab2: Logout and sign in with email", async () => {
+ // Action
+ await ctx.tab2.pages.home.navigate();
+ await ctx.tab2.pages.home.signInWithEmail("[email protected]");
+ const link = await mailgun.getLinkFromLastEmailTo(ctx.tenantSubdomain, `[email protected]`);
+ await ctx.tab2.navigate(link);
+ await ctx.tab2.pages.home.completeSignIn("Darth Vader");
+
+ // Assert
+ await ensure(ctx.tab2.pages.home.UserName).textIs("Darth Vader");
+});
diff --git a/tests/scenarios/index.ts b/tests/scenarios/index.ts
new file mode 100644
index 000000000..92ea28a14
--- /dev/null
+++ b/tests/scenarios/index.ts
@@ -0,0 +1,67 @@
+import {
+ Browser,
+ BrowserTab,
+ pageHasLoaded,
+ ensure,
+ elementIsNotVisible,
+ delay,
+ elementIsVisible,
+ mailgun
+} from "../lib";
+import { HomePage, ShowIdeaPage } from "../pages";
+
+export interface TestContext {
+ browser1: Browser;
+ browser2: Browser;
+ tab1: BrowserTab;
+ tab2: BrowserTab;
+ tenantName: string;
+ tenantSubdomain: string;
+}
+
+export let ctx: TestContext;
+
+describe("E2E", () => {
+ beforeAll(async () => {
+ const now = new Date().getTime();
+ const tenantName = `Selenium ${now}`;
+ const tenantSubdomain = process.env.HOST_MODE === "single" ? "login" : `selenium${now}`;
+ const baseUrl = `http://${tenantSubdomain}.dev.fider.io:3000`;
+ const browser1 = await Browser.launch();
+ const tab1 = await browser1.newTab(baseUrl);
+ const browser2 = await Browser.launch();
+ const tab2 = await browser2.newTab(baseUrl);
+
+ ctx = {
+ tenantName,
+ tenantSubdomain,
+ browser1,
+ tab1,
+ browser2,
+ tab2
+ };
+ });
+
+ afterAll(async () => {
+ await ctx.browser1.close();
+ await ctx.browser2.close();
+ });
+
+ it("Tab1: User can sign up with facebook", async () => {
+ await ctx.tab1.pages.signup.navigate();
+ await ctx.tab1.pages.signup.signInWithFacebook();
+ await ctx.tab1.pages.facebook.signInAsJonSnow();
+
+ await ctx.tab1.pages.signup.signUpAs(ctx.tenantName, ctx.tenantSubdomain);
+
+ await ctx.tab1.wait(pageHasLoaded(HomePage));
+ });
+
+ describe("E2E: Feedback Loop", () => {
+ require("./feedback-loop");
+ });
+
+ describe("E2E: Admin Settings", () => {
+ require("./admin-settings");
+ });
+});
diff --git a/tests/e2e-single.spec.ts b/tests/single.spec.ts
similarity index 60%
rename from tests/e2e-single.spec.ts
rename to tests/single.spec.ts
index 5cd3fec33..4722e3f28 100644
--- a/tests/e2e-single.spec.ts
+++ b/tests/single.spec.ts
@@ -1,3 +1,3 @@
process.env.HOST_MODE = "single";
jest.setTimeout(30000);
-require("./testcases/entry");
+require("./scenarios/feedback-loop");
diff --git a/tests/testcases/admin.ts b/tests/testcases/admin.ts
deleted file mode 100644
index 0c3054175..000000000
--- a/tests/testcases/admin.ts
+++ /dev/null
@@ -1,112 +0,0 @@
-import { ensure, elementIsVisible, elementIsNotVisible } from "../lib";
-import { pages, browser } from "../context";
-
-it("User is authenticated after sign up", async () => {
- // Action
- await pages.home.navigate();
- await pages.home.UserMenu.click();
-
- // Assert
- await ensure(pages.home.UserName).textIs("JON SNOW");
-});
-
-it("User doesn't lose what they typed", async () => {
- // Action
- await pages.home.navigate();
- await pages.home.IdeaTitle.type("My Great Idea");
- await pages.home.IdeaDescription.type("With an awesome description");
-
- await pages.home.IdeaTitle.clear();
- await pages.home.IdeaTitle.type("My Great Idea has a new title");
-
- // Assert
- await ensure(pages.home.IdeaTitle).textIs("My Great Idea has a new title");
- await ensure(pages.home.IdeaDescription).textIs("With an awesome description");
-
- // Action
- await pages.home.navigate();
-
- // Assert
- await ensure(pages.home.IdeaTitle).textIs("My Great Idea has a new title");
- await ensure(pages.home.IdeaDescription).textIs("With an awesome description");
-
- // Action
- await pages.home.IdeaDescription.clear();
- await pages.home.IdeaTitle.clear();
- await pages.home.navigate();
-
- // Assert
- await ensure(pages.home.IdeaTitle).textIs("");
- await browser.wait(elementIsNotVisible(() => pages.home.IdeaDescription));
-});
-
-it("Can submit ideas", async () => {
- // Action
- await pages.home.navigate();
- await pages.home.submitNewIdea("Add support to TypeScript", "Because the language and community is awesome! :)");
-
- // Assert
- await ensure(pages.showIdea.Title).textIs("Add support to TypeScript");
- await ensure(pages.showIdea.Description).textIs("Because the language and community is awesome! :)");
- await ensure(pages.showIdea.SupportCounter).textIs("1");
-});
-
-it("Can change status", async () => {
- // Action & Assert
- await pages.home.navigate();
- await pages.home.IdeaList.navigateAndWait(0, pages.showIdea.loadCondition());
- await pages.showIdea.RespondButton.click();
- await browser.wait(elementIsVisible(() => pages.showIdea.ResponseModal));
-
- // Action & Assert
- await pages.showIdea.changeStatus("Planned", "We will work on this soon...");
- await browser.wait(elementIsVisible(() => pages.showIdea.Status));
- await ensure(pages.showIdea.Status).textIs("PLANNED");
- await ensure(pages.showIdea.ResponseText).textIs("We will work on this soon...");
-});
-
-it("Can change status to another one", async () => {
- // Action & Assert
- await pages.showIdea.RespondButton.click();
- await browser.wait(elementIsVisible(() => pages.showIdea.ResponseModal));
- await pages.showIdea.changeStatus("Planned", "We will work on this soon...");
- await browser.wait(elementIsVisible(() => pages.showIdea.Status));
- await ensure(pages.showIdea.Status).textIs("PLANNED");
- await ensure(pages.showIdea.ResponseText).textIs("We will work on this soon...");
-});
-
-it("Can comment on an idea", async () => {
- // Action & Assert
- await pages.home.navigate();
- await pages.home.IdeaList.navigateAndWait(0, pages.showIdea.loadCondition());
- await ensure(pages.showIdea.SubmitCommentButton).isNotVisible();
-
- // Action & Assert
- await pages.showIdea.CommentInput.type("This is my first comment");
- await ensure(pages.showIdea.SubmitCommentButton).isVisible();
-
- // Action & Assert
- await pages.showIdea.SubmitCommentButton.click();
- await browser.wait(async () => (await pages.showIdea.CommentList.count()) === 1);
-});
-
-it("Can change Title, Invitation and Welcome Message", async () => {
- await pages.adminSettings.navigate();
-
- await pages.adminSettings.TitleInput.clear();
- await pages.adminSettings.TitleInput.type("Selenium Feedback");
-
- await pages.adminSettings.WelcomeMessageInput.clear();
- await pages.adminSettings.WelcomeMessageInput.type("Welcome to our Selenium Feedback Forum");
-
- await pages.adminSettings.InvitationInput.clear();
- await pages.adminSettings.InvitationInput.type("Say something...");
-
- await pages.adminSettings.ConfirmButton.click();
-
- await browser.wait(pages.home.loadCondition());
-
- await ensure(pages.home.MenuTitle).textIs("Selenium Feedback");
- await ensure(pages.home.WelcomeMessage).textIs("Welcome to our Selenium Feedback Forum");
- await ensure(pages.home.IdeaTitle).attributeIs("placeholder", "Say something...");
-});
diff --git a/tests/testcases/anonymous.ts b/tests/testcases/anonymous.ts
deleted file mode 100644
index 971985269..000000000
--- a/tests/testcases/anonymous.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { ensure, elementIsVisible } from "../lib";
-import { pages, browser } from "../context";
-
-it("Cannot submit ideas", async () => {
- // Action
- await pages.home.navigate();
- await pages.home.IdeaTitle.click();
-
- // Assert
- await browser.wait(elementIsVisible(() => pages.home.SignInModal));
-});
-
-it("Cannot see actions or comment on an idea", async () => {
- // Action & Assert
- await pages.home.navigate();
- await pages.home.IdeaList.navigateAndWait(0, pages.showIdea.loadCondition());
- await ensure(pages.showIdea.RespondButton).isNotVisible();
-
- // Action & Assert
- await pages.showIdea.CommentInput.click();
- await browser.wait(elementIsVisible(() => pages.home.SignInModal));
-});
diff --git a/tests/testcases/email-signup.ts b/tests/testcases/email-signup.ts
deleted file mode 100644
index bc21871ba..000000000
--- a/tests/testcases/email-signup.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { ensure, elementIsVisible, mailgun, Browser } from "../lib";
-import { AllPages } from "../pages";
-
-describe("Sign up by email", () => {
- let browser: Browser;
- let pages: AllPages;
-
- beforeAll(async () => {
- browser = new Browser("chrome");
- pages = new AllPages(browser);
- });
-
- afterAll(async () => {
- await pages.dispose();
- });
-
- it("User can sign up using email", async () => {
- const now = new Date().getTime();
-
- // Action
- await pages.signup.navigate();
- await pages.signup.signInWithEmail(`Darth Vader ${now}`, `darthvader.fider+${now}@gmail.com`);
- await pages.signup.signUpAs(`Selenium ${now}`, `selenium${now}`);
-
- const link = await mailgun.getLinkFromLastEmailTo(`darthvader.fider+${now}@gmail.com`);
-
- await pages.goTo(link);
- await browser.wait(pages.home.loadCondition());
-
- // Assert
- await pages.home.UserMenu.click();
- await ensure(pages.home.UserName).textIs(`DARTH VADER ${now}`);
- });
-});
diff --git a/tests/testcases/entry.ts b/tests/testcases/entry.ts
deleted file mode 100644
index 37b183615..000000000
--- a/tests/testcases/entry.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import { Browser } from "../lib";
-import { setPages, setBrowser, setTenant } from "../context";
-import { AllPages } from "../pages";
-
-describe("Using Fider", () => {
- let browser: Browser;
- let pages: AllPages;
-
- beforeAll(async () => {
- const now = new Date().getTime();
- const tenantName = `Selenium ${now}`;
- const tenantSubdomain = `selenium${now}`;
- setTenant(tenantSubdomain);
-
- browser = new Browser("chrome");
- pages = new AllPages(browser);
-
- setBrowser(browser);
- setPages(pages);
-
- await pages.signup.navigate();
- await pages.signup.signInWithFacebook();
- await pages.facebook.signInAsJonSnow();
-
- await pages.signup.signUpAs(tenantName, tenantSubdomain);
- });
-
- afterAll(async () => {
- await pages.dispose();
- });
-
- describe("As an Admin", () => {
- require("./admin");
- });
-
- describe("As an anonymous user", () => {
- beforeAll(async () => {
- await pages.home.navigate();
- await pages.home.signOut();
- });
- require("./anonymous");
- });
-
- describe("Alternative sign in", () => {
- require("./signin");
- });
-});
diff --git a/tests/testcases/signin.ts b/tests/testcases/signin.ts
deleted file mode 100644
index 246202dc9..000000000
--- a/tests/testcases/signin.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { ensure, elementIsVisible, mailgun } from "../lib";
-import { pages, browser } from "../context";
-
-it("Can sign in with Google and support an idea", async () => {
- // Action & Assert
- await pages.home.navigate();
- await pages.home.signInWithGoogle();
- await pages.google.signInAsDarthVader();
- await pages.home.UserMenu.click();
- await ensure(pages.home.UserName).textIs("DARTH VADER");
-
- // Action & Assert
- await pages.home.IdeaList.want(0);
- await ensure(await pages.home.IdeaList.at(0)).textIs("2");
-});
-
-it("User can sign in using email on existing tenant", async () => {
- const now = new Date().getTime();
-
- // Action
- await pages.home.navigate();
- await pages.home.signInWithEmail(`darthvader.fider+${now}@gmail.com`);
-
- const link = await mailgun.getLinkFromLastEmailTo(`darthvader.fider+${now}@gmail.com`);
-
- await pages.goTo(link);
- await browser.wait(pages.home.loadCondition());
-
- await pages.home.completeSignIn(`Darth Vader ${now}`);
-
- // Assert
- await pages.home.UserMenu.click();
- await ensure(pages.home.UserName).textIs(`DARTH VADER ${now}`);
-});