From 257d80fe2b62f9457c32a6d1af58f3268c8ffffe Mon Sep 17 00:00:00 2001 From: saikrishna321 Date: Wed, 5 Aug 2020 15:50:07 +0530 Subject: [PATCH 1/4] initial commit --- actions/LoginActions.js | 12 ++++++++ actions/SideNavActions.js | 14 +++++++++ actor/Actor.js | 12 ++++++++ actor/Admin.js | 15 ++++++++++ actor/Author.js | 11 +++++++ docker-compose.yml | 32 ++++++++++++++++++++ elements/loginElements.js | 15 ++++++++++ factory/DesktopFlow.js | 5 ++++ factory/FlowFactory.js | 12 ++++++++ factory/MobileFlow.js | 5 ++++ interrogations/SideNavInterrogations.js | 9 ++++++ test/addPost.spec.js | 25 ++++++++++++++++ test/login.spec.js | 39 ++++++++++++++----------- 13 files changed, 189 insertions(+), 17 deletions(-) create mode 100644 actions/LoginActions.js create mode 100644 actions/SideNavActions.js create mode 100644 actor/Actor.js create mode 100644 actor/Admin.js create mode 100644 actor/Author.js create mode 100644 docker-compose.yml create mode 100644 elements/loginElements.js create mode 100644 factory/DesktopFlow.js create mode 100644 factory/FlowFactory.js create mode 100644 factory/MobileFlow.js create mode 100644 interrogations/SideNavInterrogations.js create mode 100644 test/addPost.spec.js diff --git a/actions/LoginActions.js b/actions/LoginActions.js new file mode 100644 index 0000000..7c22995 --- /dev/null +++ b/actions/LoginActions.js @@ -0,0 +1,12 @@ +import { write, click, into } from "taiko"; +import LoginElements from "../elements/loginElements"; + +class LoginActions { + async login(userName, password) { + await write(userName, into(LoginElements.userName)); + await write(password, into(LoginElements.password)); + await click(LoginElements.submit); + } +} + +export default new LoginActions(); diff --git a/actions/SideNavActions.js b/actions/SideNavActions.js new file mode 100644 index 0000000..5b59c7b --- /dev/null +++ b/actions/SideNavActions.js @@ -0,0 +1,14 @@ +import FlowFactory from "../factory/FlowFactory"; + +let runner; + +class SideNavActions { + constructor() { + runner = FlowFactory.getInstance(); + } + async writePost() { + await runner.writePost(); + } +} + +export default new SideNavActions(); diff --git a/actor/Actor.js b/actor/Actor.js new file mode 100644 index 0000000..e5eca9f --- /dev/null +++ b/actor/Actor.js @@ -0,0 +1,12 @@ +import LoginActions from "../actions/LoginActions"; +import SideNavActions from "../actions/SideNavActions"; + +export default class Actor { + async login() { + await LoginActions.login(this.userName, this.password); + } + + async writePost() { + await SideNavActions.writePost(); + } +} diff --git a/actor/Admin.js b/actor/Admin.js new file mode 100644 index 0000000..f88f377 --- /dev/null +++ b/actor/Admin.js @@ -0,0 +1,15 @@ +import Actor from "../actor/Actor"; + +export default class Admin extends Actor { + constructor(credentials) { + super(); + this.userName = credentials.user; + this.password = credentials.password; + } + + async deletePost() { + return true; + } + + async createAUser() {} +} diff --git a/actor/Author.js b/actor/Author.js new file mode 100644 index 0000000..1a714c6 --- /dev/null +++ b/actor/Author.js @@ -0,0 +1,11 @@ +import Actor from "../actor/Actor"; + +export default class Author extends Actor { + constructor(credentials) { + super(); + this.userName = credentials.user; + this.password = credentials.password; + } + + async publishAPost() {} +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bcfc989 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.3' + +services: + db: + image: mysql:5.7 + volumes: + - db_data:/var/lib/mysql + restart: always + ports: + - "3306:3306" + expose: + - "3306" + environment: + MYSQL_ROOT_PASSWORD: somewordpress + MYSQL_DATABASE: wordpress + MYSQL_USER: wordpress + MYSQL_PASSWORD: wordpress + + wordpress: + depends_on: + - db + image: wordpress:latest + ports: + - "8000:80" + restart: always + environment: + WORDPRESS_DB_HOST: db:3306 + WORDPRESS_DB_USER: wordpress + WORDPRESS_DB_PASSWORD: wordpress + WORDPRESS_DB_NAME: wordpress +volumes: + db_data: {} \ No newline at end of file diff --git a/elements/loginElements.js b/elements/loginElements.js new file mode 100644 index 0000000..24c2c3f --- /dev/null +++ b/elements/loginElements.js @@ -0,0 +1,15 @@ +import { $ } from "taiko"; + +export default class LoginElements { + static get userName() { + return $("#user_login"); + } + + static get password() { + return $("#user_pass"); + } + + static get submit() { + return $("#wp-submit"); + } +} diff --git a/factory/DesktopFlow.js b/factory/DesktopFlow.js new file mode 100644 index 0000000..552d93c --- /dev/null +++ b/factory/DesktopFlow.js @@ -0,0 +1,5 @@ +import { click, write } from "taiko"; + +export default class DesktopFlow { + async writePost() {} +} diff --git a/factory/FlowFactory.js b/factory/FlowFactory.js new file mode 100644 index 0000000..598d18f --- /dev/null +++ b/factory/FlowFactory.js @@ -0,0 +1,12 @@ +import MobileFlow from "../factory/MobileFlow"; +import DesktopFlow from "../factory/DesktopFlow"; + +export default class FlowFactory { + static getInstance() { + if (process.env.TAIKO_EMULATE_DEVICE) { + return new MobileFlow(); + } else { + return new DesktopFlow(); + } + } +} diff --git a/factory/MobileFlow.js b/factory/MobileFlow.js new file mode 100644 index 0000000..f95d9a4 --- /dev/null +++ b/factory/MobileFlow.js @@ -0,0 +1,5 @@ +export default class MobileFlow { + async writePost() { + console.log("Writing Post from Mobile Flow!!"); + } +} diff --git a/interrogations/SideNavInterrogations.js b/interrogations/SideNavInterrogations.js new file mode 100644 index 0000000..6f3a0fa --- /dev/null +++ b/interrogations/SideNavInterrogations.js @@ -0,0 +1,9 @@ +import { text } from "taiko"; + +class SideNavInterrogations { + async checkIfSettingsIsPresent() { + return await text("Settings").exists(); + } +} + +export default new SideNavInterrogations(); diff --git a/test/addPost.spec.js b/test/addPost.spec.js new file mode 100644 index 0000000..ae4a8b5 --- /dev/null +++ b/test/addPost.spec.js @@ -0,0 +1,25 @@ +import { openBrowser, goto, closeBrowser, text } from "taiko"; +import { expect } from "chai"; +import Admin from "../actor/Admin"; +import Author from "../actor/Author"; +import SideNavInterrogations from "../interrogations/SideNavInterrogations"; +describe("WordPress Login", async () => { + before("Open Browser", async () => { + await openBrowser(); + await goto("http://127.0.0.1:8000/wp-admin/"); + }); + + after("Close Browser", async () => { + await closeBrowser(); + }); + + it.only("User with Valid Admin Login should be able to see settings option", async () => { + let author = new Author({ + user: "taiko", + password: "taiko", + }); + await author.login(); + await author.writePost(); + //expect(await SideNavInterrogations.checkIfSettingsIsPresent()).to.be.true; + }); +}); diff --git a/test/login.spec.js b/test/login.spec.js index 97727d5..43c0f2b 100644 --- a/test/login.spec.js +++ b/test/login.spec.js @@ -1,15 +1,8 @@ -import { - openBrowser, - goto, - closeBrowser, - write, - click, - into, - $, - text, -} from "taiko"; +import { openBrowser, goto, closeBrowser, text } from "taiko"; import { expect } from "chai"; - +import Admin from "../actor/Admin"; +import Author from "../actor/Author"; +import SideNavInterrogations from "../interrogations/SideNavInterrogations"; describe("WordPress Login", async () => { before("Open Browser", async () => { await openBrowser(); @@ -19,11 +12,23 @@ describe("WordPress Login", async () => { after("Close Browser", async () => { await closeBrowser(); }); - it("User with Valid Login should be able to see settings option", async () => { - await write("Karley Crist", into($("#user_login"))); - await write("gkbjp93kFUFthK7", into($("#user_pass"))); - await click($("#wp-submit")); - const elementPresent = await text("Settings").exists(); - expect(elementPresent).to.be.true; + + it("User with Valid Admin Login should be able to see settings option", async () => { + let admin = new Admin({ + user: "Karley Crist", + password: "gkbjp93kFUFthK7", + }); + await admin.login(); + await admin.deletePost(); + expect(await SideNavInterrogations.checkIfSettingsIsPresent()).to.be.true; + }); + + it("User with Valid Non Admin Login should not be able to see settings option", async () => { + let author = new Author({ + user: "taiko", + password: "taiko", + }); + await author.login(); + expect(await SideNavInterrogations.checkIfSettingsIsPresent()).to.be.false; }); }); From 6042337c4247ab7e21220ed0b3355bdf5be16053 Mon Sep 17 00:00:00 2001 From: saikrishna321 Date: Wed, 5 Aug 2020 15:50:25 +0530 Subject: [PATCH 2/4] initial commit --- docker-compose.yml | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bcfc989..57546a1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,32 +1,32 @@ -version: '3.3' +version: "3.3" services: - db: - image: mysql:5.7 - volumes: - - db_data:/var/lib/mysql - restart: always - ports: - - "3306:3306" - expose: - - "3306" - environment: - MYSQL_ROOT_PASSWORD: somewordpress - MYSQL_DATABASE: wordpress - MYSQL_USER: wordpress - MYSQL_PASSWORD: wordpress + db: + image: mysql:5.7 + volumes: + - db_data:/var/lib/mysql + restart: always + ports: + - "3306:3306" + expose: + - "3306" + environment: + MYSQL_ROOT_PASSWORD: somewordpress + MYSQL_DATABASE: wordpress + MYSQL_USER: wordpress + MYSQL_PASSWORD: wordpress - wordpress: - depends_on: - - db - image: wordpress:latest - ports: - - "8000:80" - restart: always - environment: - WORDPRESS_DB_HOST: db:3306 - WORDPRESS_DB_USER: wordpress - WORDPRESS_DB_PASSWORD: wordpress - WORDPRESS_DB_NAME: wordpress + wordpress: + depends_on: + - db + image: wordpress:latest + ports: + - "8000:80" + restart: always + environment: + WORDPRESS_DB_HOST: db:3306 + WORDPRESS_DB_USER: wordpress + WORDPRESS_DB_PASSWORD: wordpress + WORDPRESS_DB_NAME: wordpress volumes: - db_data: {} \ No newline at end of file + db_data: {} From 892c2a8fb2d16fc5e28b5f010cdfe742c659ccc8 Mon Sep 17 00:00:00 2001 From: Lipika Jaskaran Dugar Date: Sat, 15 Aug 2020 23:31:41 +0530 Subject: [PATCH 3/4] Add decorator pattern --- actions/SideNavActions.js | 10 ++++---- factory/DesktopFlow.js | 7 ++++-- post/writeAndPublishPost.js | 10 ++++++++ post/writePost.js | 24 ++++++++++++++++++ post/writePostWithCategory.js | 19 +++++++++++++++ post/writePostWithTag.js | 20 +++++++++++++++ test/addPost.spec.js | 46 ++++++++++++++++++++++++++++------- test/login.spec.js | 4 +-- 8 files changed, 122 insertions(+), 18 deletions(-) create mode 100644 post/writeAndPublishPost.js create mode 100644 post/writePost.js create mode 100644 post/writePostWithCategory.js create mode 100644 post/writePostWithTag.js diff --git a/actions/SideNavActions.js b/actions/SideNavActions.js index 5b59c7b..3ac4c5f 100644 --- a/actions/SideNavActions.js +++ b/actions/SideNavActions.js @@ -1,14 +1,14 @@ import FlowFactory from "../factory/FlowFactory"; +import DesktopFlow from "../factory/DesktopFlow"; let runner; -class SideNavActions { +export default class SideNavActions { constructor() { runner = FlowFactory.getInstance(); } - async writePost() { - await runner.writePost(); + + static async addNewPost() { + await DesktopFlow.writePosts(); } } - -export default new SideNavActions(); diff --git a/factory/DesktopFlow.js b/factory/DesktopFlow.js index 552d93c..0efd2ff 100644 --- a/factory/DesktopFlow.js +++ b/factory/DesktopFlow.js @@ -1,5 +1,8 @@ -import { click, write } from "taiko"; +import { click } from "taiko"; export default class DesktopFlow { - async writePost() {} + static async writePosts() { + await click("Posts"); + await click("Add New"); + } } diff --git a/post/writeAndPublishPost.js b/post/writeAndPublishPost.js new file mode 100644 index 0000000..32f3d9c --- /dev/null +++ b/post/writeAndPublishPost.js @@ -0,0 +1,10 @@ +export default class WriteAndPublishPost { + constructor(writePost) { + this.post = writePost; + } + + async writePost() { + this.post.addPost(); + this.post.publishPost(); + } +} diff --git a/post/writePost.js b/post/writePost.js new file mode 100644 index 0000000..ce6e586 --- /dev/null +++ b/post/writePost.js @@ -0,0 +1,24 @@ +import SideNavActions from "../actions/SideNavActions"; +import { write, into, focus, textBox, click } from "taiko"; + +export default class WritePost { + async addPost() { + await SideNavActions.addNewPost(); + this.addTitle(); + this.addDescription(); + } + + async addTitle() { + await focus(textBox("Add title")); + await write("Post Title", into("#post-title-0")); + } + + async addDescription() { + console.log("Description added"); + } + + async publishPost() { + await click("Publish"); + await click("Publish"); + } +} diff --git a/post/writePostWithCategory.js b/post/writePostWithCategory.js new file mode 100644 index 0000000..47c2baf --- /dev/null +++ b/post/writePostWithCategory.js @@ -0,0 +1,19 @@ +import { click } from "taiko"; + +export default class WritePostWithCategory { + constructor(writePost) { + this.post = writePost; + } + + async writePost() { + this.post.writePost; + console.log("Adding Category"); + this.addCategory(); + this.post.publishPost(); + } + + async addCategory() { + await click("Categories"); + await click("JS"); + } +} diff --git a/post/writePostWithTag.js b/post/writePostWithTag.js new file mode 100644 index 0000000..74fa472 --- /dev/null +++ b/post/writePostWithTag.js @@ -0,0 +1,20 @@ +import { click, focus, write } from "taiko"; + +export default class WritePostWithTag { + constructor(writePost) { + this.post = writePost; + } + + async writePost() { + this.post.writePost; + console.log("Adding Tag"); + this.addTags(); + this.post.publishPost(); + } + + async addTags() { + await click("Tags"); + focus(textBox("Add New Tag")); + await write("Blog, Decorator, "); + } +} diff --git a/test/addPost.spec.js b/test/addPost.spec.js index ae4a8b5..c1f5a55 100644 --- a/test/addPost.spec.js +++ b/test/addPost.spec.js @@ -3,23 +3,51 @@ import { expect } from "chai"; import Admin from "../actor/Admin"; import Author from "../actor/Author"; import SideNavInterrogations from "../interrogations/SideNavInterrogations"; +import WritePost from "../post/writePost"; +import WriteAndPublishPost from "../post/writeAndPublishPost"; +import WritePostWithTag from "../post/writePostWithTag"; +import WritePostWithCategory from "../post/writePostWithCategory"; + describe("WordPress Login", async () => { - before("Open Browser", async () => { + beforeEach("Open Browser", async () => { await openBrowser(); await goto("http://127.0.0.1:8000/wp-admin/"); }); - after("Close Browser", async () => { + afterEach("Close Browser", async () => { await closeBrowser(); }); - it.only("User with Valid Admin Login should be able to see settings option", async () => { - let author = new Author({ - user: "taiko", - password: "taiko", + it.only("Admin should be able to add a new post", async () => { + let admin = new Admin({ + user: "Karley Crist", + password: "gkbjp93kFUFthK7", + }); + await admin.login(); + + let post = new WriteAndPublishPost(new WritePost()); + await post.writePost(); + }); + + it("Admin should be able to add a new post with tags", async () => { + let admin = new Admin({ + user: "Karley Crist", + password: "gkbjp93kFUFthK7", }); - await author.login(); - await author.writePost(); - //expect(await SideNavInterrogations.checkIfSettingsIsPresent()).to.be.true; + await admin.login(); + + let post = new WritePostWithTag(new WritePost()); + await post.writePost(); + }); + + it("Admin should be able to add a new post with category", async () => { + let admin = new Admin({ + user: "Karley Crist", + password: "gkbjp93kFUFthK7", + }); + await admin.login(); + + let post = new WritePostWithCategory(new WritePost()); + await post.writePost(); }); }); diff --git a/test/login.spec.js b/test/login.spec.js index 43c0f2b..2b19191 100644 --- a/test/login.spec.js +++ b/test/login.spec.js @@ -4,12 +4,12 @@ import Admin from "../actor/Admin"; import Author from "../actor/Author"; import SideNavInterrogations from "../interrogations/SideNavInterrogations"; describe("WordPress Login", async () => { - before("Open Browser", async () => { + beforeEach("Open Browser", async () => { await openBrowser(); await goto("http://127.0.0.1:8000/wp-admin/"); }); - after("Close Browser", async () => { + afterEach("Close Browser", async () => { await closeBrowser(); }); From aee7a8bfe047eaa7c56a26b0f0bccb6cc5ec89fc Mon Sep 17 00:00:00 2001 From: Lipika Jaskaran Dugar Date: Sun, 16 Aug 2020 13:01:50 +0530 Subject: [PATCH 4/4] Added await to fix tests --- actions/SideNavActions.js | 10 +++++----- factory/DesktopFlow.js | 2 +- post/writeAndPublishPost.js | 4 ++-- post/writePost.js | 5 +++-- post/writePostWithCategory.js | 7 +++---- post/writePostWithTag.js | 13 ++++++------- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/actions/SideNavActions.js b/actions/SideNavActions.js index 3ac4c5f..e5d0ff6 100644 --- a/actions/SideNavActions.js +++ b/actions/SideNavActions.js @@ -1,14 +1,14 @@ import FlowFactory from "../factory/FlowFactory"; -import DesktopFlow from "../factory/DesktopFlow"; let runner; -export default class SideNavActions { +class SideNavActions { constructor() { runner = FlowFactory.getInstance(); } - - static async addNewPost() { - await DesktopFlow.writePosts(); + async addNewPost() { + await runner.writePosts(); } } + +export default new SideNavActions(); diff --git a/factory/DesktopFlow.js b/factory/DesktopFlow.js index 0efd2ff..a952cc6 100644 --- a/factory/DesktopFlow.js +++ b/factory/DesktopFlow.js @@ -1,7 +1,7 @@ import { click } from "taiko"; export default class DesktopFlow { - static async writePosts() { + async writePosts() { await click("Posts"); await click("Add New"); } diff --git a/post/writeAndPublishPost.js b/post/writeAndPublishPost.js index 32f3d9c..b2cefa3 100644 --- a/post/writeAndPublishPost.js +++ b/post/writeAndPublishPost.js @@ -4,7 +4,7 @@ export default class WriteAndPublishPost { } async writePost() { - this.post.addPost(); - this.post.publishPost(); + await this.post.addPost(); + await this.post.publishPost(); } } diff --git a/post/writePost.js b/post/writePost.js index ce6e586..30cb174 100644 --- a/post/writePost.js +++ b/post/writePost.js @@ -4,8 +4,8 @@ import { write, into, focus, textBox, click } from "taiko"; export default class WritePost { async addPost() { await SideNavActions.addNewPost(); - this.addTitle(); - this.addDescription(); + await this.addTitle(); + await this.addDescription(); } async addTitle() { @@ -14,6 +14,7 @@ export default class WritePost { } async addDescription() { + //TODO: Add Description console.log("Description added"); } diff --git a/post/writePostWithCategory.js b/post/writePostWithCategory.js index 47c2baf..f938cc8 100644 --- a/post/writePostWithCategory.js +++ b/post/writePostWithCategory.js @@ -6,10 +6,9 @@ export default class WritePostWithCategory { } async writePost() { - this.post.writePost; - console.log("Adding Category"); - this.addCategory(); - this.post.publishPost(); + await this.post.addPost(); + await this.addCategory(); + await this.post.publishPost(); } async addCategory() { diff --git a/post/writePostWithTag.js b/post/writePostWithTag.js index 74fa472..598572b 100644 --- a/post/writePostWithTag.js +++ b/post/writePostWithTag.js @@ -1,4 +1,4 @@ -import { click, focus, write } from "taiko"; +import { click, focus, write, textBox } from "taiko"; export default class WritePostWithTag { constructor(writePost) { @@ -6,15 +6,14 @@ export default class WritePostWithTag { } async writePost() { - this.post.writePost; - console.log("Adding Tag"); - this.addTags(); - this.post.publishPost(); + await this.post.addPost(); + await this.addTags(); + await this.post.publishPost(); } async addTags() { await click("Tags"); - focus(textBox("Add New Tag")); - await write("Blog, Decorator, "); + await focus(textBox("Add New Tag")); + await write("Blog, "); } }