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..e5d0ff6 --- /dev/null +++ b/actions/SideNavActions.js @@ -0,0 +1,14 @@ +import FlowFactory from "../factory/FlowFactory"; + +let runner; + +class SideNavActions { + constructor() { + runner = FlowFactory.getInstance(); + } + async addNewPost() { + await runner.writePosts(); + } +} + +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..57546a1 --- /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: {} 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..a952cc6 --- /dev/null +++ b/factory/DesktopFlow.js @@ -0,0 +1,8 @@ +import { click } from "taiko"; + +export default class DesktopFlow { + async writePosts() { + await click("Posts"); + await click("Add New"); + } +} 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/post/writeAndPublishPost.js b/post/writeAndPublishPost.js new file mode 100644 index 0000000..b2cefa3 --- /dev/null +++ b/post/writeAndPublishPost.js @@ -0,0 +1,10 @@ +export default class WriteAndPublishPost { + constructor(writePost) { + this.post = writePost; + } + + async writePost() { + await this.post.addPost(); + await this.post.publishPost(); + } +} diff --git a/post/writePost.js b/post/writePost.js new file mode 100644 index 0000000..30cb174 --- /dev/null +++ b/post/writePost.js @@ -0,0 +1,25 @@ +import SideNavActions from "../actions/SideNavActions"; +import { write, into, focus, textBox, click } from "taiko"; + +export default class WritePost { + async addPost() { + await SideNavActions.addNewPost(); + await this.addTitle(); + await this.addDescription(); + } + + async addTitle() { + await focus(textBox("Add title")); + await write("Post Title", into("#post-title-0")); + } + + async addDescription() { + //TODO: Add Description + 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..f938cc8 --- /dev/null +++ b/post/writePostWithCategory.js @@ -0,0 +1,18 @@ +import { click } from "taiko"; + +export default class WritePostWithCategory { + constructor(writePost) { + this.post = writePost; + } + + async writePost() { + await this.post.addPost(); + await this.addCategory(); + await 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..598572b --- /dev/null +++ b/post/writePostWithTag.js @@ -0,0 +1,19 @@ +import { click, focus, write, textBox } from "taiko"; + +export default class WritePostWithTag { + constructor(writePost) { + this.post = writePost; + } + + async writePost() { + await this.post.addPost(); + await this.addTags(); + await this.post.publishPost(); + } + + async addTags() { + await click("Tags"); + await focus(textBox("Add New Tag")); + await write("Blog, "); + } +} diff --git a/test/addPost.spec.js b/test/addPost.spec.js new file mode 100644 index 0000000..c1f5a55 --- /dev/null +++ b/test/addPost.spec.js @@ -0,0 +1,53 @@ +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"; +import WritePost from "../post/writePost"; +import WriteAndPublishPost from "../post/writeAndPublishPost"; +import WritePostWithTag from "../post/writePostWithTag"; +import WritePostWithCategory from "../post/writePostWithCategory"; + +describe("WordPress Login", async () => { + beforeEach("Open Browser", async () => { + await openBrowser(); + await goto("http://127.0.0.1:8000/wp-admin/"); + }); + + afterEach("Close Browser", async () => { + await closeBrowser(); + }); + + 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 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 97727d5..2b19191 100644 --- a/test/login.spec.js +++ b/test/login.spec.js @@ -1,29 +1,34 @@ -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 () => { + 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("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; }); });