diff -uNr a/mp-wp-tests/credentials.js b/mp-wp-tests/credentials.js --- a/mp-wp-tests/credentials.js false +++ b/mp-wp-tests/credentials.js d58de3b248eedff36035681597a4d7a81082d9274d76b1cc14a20e9d07e5f1af421b7e52e9484e1b6b3d62f83e4826298957f81b0665b7444e618cd061834ed8 @@ -0,0 +1,7 @@ +// set to your mp-wp admin credentials +const credentials = { + username: 'admin', + password: 'password', +}; + +module.exports = credentials; diff -uNr a/mp-wp-tests/manifest b/mp-wp-tests/manifest --- a/mp-wp-tests/manifest false +++ b/mp-wp-tests/manifest ae177629bf40b02a850cf673ca37a25b2c1348ef55ce1a9d3be146056a1fa157cbf229e5e2e28bdf2cfef2f93c0ace584cfe54052a2c14d07ec3607a83128caf @@ -0,0 +1 @@ +589275 mp-wp-tests_genesis billymg End-to-end tests for mp-wp. Meant to be run on a toilet box with Java and Node.js installed. Press and then run `npm install` to download shitdeps. diff -uNr a/mp-wp-tests/package.json b/mp-wp-tests/package.json --- a/mp-wp-tests/package.json false +++ b/mp-wp-tests/package.json 3efce66bfc0f4cd00f67f4b248ee599b0056fd4a1ddb683bb0be0769092b3a17f3fcfb11c4f5c8a8af9e73d40163d7493149be9eccdb321472ca633d916dc1ba @@ -0,0 +1,22 @@ +{ + "name": "mp-wp-tests", + "version": "0.1.0", + "description": "e2e tests for mp-wp", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": {}, + "devDependencies": { + "@wdio/cli": "^5.11.5", + "@wdio/jasmine-framework": "^5.11.0", + "@wdio/local-runner": "^5.11.5", + "@wdio/selenium-standalone-service": "^5.11.2", + "@wdio/spec-reporter": "^5.11.0", + "@wdio/sync": "^5.11.0", + "geckodriver": "^1.16.2", + "webdriverio": "^5.11.5" + } +} diff -uNr a/mp-wp-tests/test/pages/DashboardPage.js b/mp-wp-tests/test/pages/DashboardPage.js --- a/mp-wp-tests/test/pages/DashboardPage.js false +++ b/mp-wp-tests/test/pages/DashboardPage.js 0a811bdd3005dc3a1ad323ea8c782838211bb25c3f9794f46f7c82ec9fdd0a25cb07925242e82798bc13b78b99525d8598a291ce2a2cf536b38601ff24f89c22 @@ -0,0 +1,54 @@ +class DashboardPage { + get page() { + return $('.wp-admin'); + } + + get sideNav() { + return this.page.$('#adminmenu'); + } + + get logOutButton() { + return this.page.$('a=Log Out'); + } + + get siteLink() { + return this.page.$('a[title="Visit site"]'); + } + + getSubMenu(menuTitle) { + return this.sideNav.$(`a=${menuTitle}`).$('..'); + } + + navigate() { + browser.url('/wp-admin/index.php'); + } + + navigateToBlog() { + this.siteLink.click(); + $('#page').waitForDisplayed(); + } + + followNavLinkTo(linkText, pageTitle) { + this.sideNav.$(`a=${linkText}`).click(); + this.page.$(`h2=${pageTitle}`).waitForDisplayed(); + } + + followNavSubMenuLinkTo(menuTitle, linkText, pageTitle) { + const subMenu = this.getSubMenu(menuTitle); + + if (!subMenu.getAttribute('class').includes('wp-menu-open')) { + subMenu.$('.wp-menu-toggle').click(); + subMenu.$('.wp-submenu').waitForDisplayed(); + } + + subMenu.$(`a=${linkText}`).click(); + this.page.$(`h2=${pageTitle}`).waitForDisplayed(); + } + + logOut() { + this.logOutButton.click(); + $('p.message*=You are now logged out').waitForDisplayed(); + } +} + +module.exports = DashboardPage; diff -uNr a/mp-wp-tests/test/pages/EditPostPage.js b/mp-wp-tests/test/pages/EditPostPage.js --- a/mp-wp-tests/test/pages/EditPostPage.js false +++ b/mp-wp-tests/test/pages/EditPostPage.js e1cf9596e750c66a19ce07bb03747946d331e0602fce232474169703cf208c6f4f308a127a911a01e56b2a39c16925c32b6ed25b5cc702b7a93bf8d3621da0ff @@ -0,0 +1,36 @@ +class EditPostPage { + get pageTitle() { + return $('h2*=Post'); + } + + get page() { + return this.pageTitle.$('..'); + } + + get postTitleInput() { + return this.page.$('input#title[name=post_title]'); + } + + get postBodyInput() { + return this.page.$('textarea#content[name=content]'); + } + + get publishPostButton() { + return this.page.$('input#publish'); + } + + publishPost() { + this.publishPostButton.click(); + this.page.$('#message*=Post').waitForDisplayed(); + } + + editAndPublishPost({ postTitle, postBody } = { postTitle: 'Title', postBody: 'Body' }) { + this.postTitleInput.click(); + browser.keys(postTitle); + this.postBodyInput.click(); + browser.keys(postBody); + this.publishPost(); + } +} + +module.exports = EditPostPage; diff -uNr a/mp-wp-tests/test/pages/LoginPage.js b/mp-wp-tests/test/pages/LoginPage.js --- a/mp-wp-tests/test/pages/LoginPage.js false +++ b/mp-wp-tests/test/pages/LoginPage.js 2bdb3d2090f521edff208246e9133175b1914307069e9379998b342d583a7d05e53d9530f10b0a685b019fbbfc66c2437803a924a08aaf8a3b18282badc4ff3e @@ -0,0 +1,32 @@ +const credentials = require('../../credentials'); + +class LoginPage { + get page() { + return $('.login'); + } + + get userNameInput() { + return this.page.$('#user_login'); + } + + get passwordInput() { + return this.page.$('#user_pass'); + } + + get logInButton() { + return this.page.$('#wp-submit'); + } + + navigate() { + browser.url('/wp-login.php'); + } + + logIn({ username, password } = { username: credentials.username, password: credentials.password }) { + this.userNameInput.setValue(username); + this.passwordInput.setValue(password); + this.logInButton.click(); + $('h2=Dashboard').waitForDisplayed(); + } +} + +module.exports = LoginPage; diff -uNr a/mp-wp-tests/test/pages/PostsPage.js b/mp-wp-tests/test/pages/PostsPage.js --- a/mp-wp-tests/test/pages/PostsPage.js false +++ b/mp-wp-tests/test/pages/PostsPage.js fc4267458a5fb9b27ce8758d4b351c2b748d9d6db5b524c190c6d28ec569f84e51b9bcb1131192cf2be320226aa0b058c20baad457bd2a66d66781ce8676e5c7 @@ -0,0 +1,15 @@ +class PostsPage { + get pageTitle() { + return $('h2=Edit Posts'); + } + + get page() { + return this.pageTitle.$('..'); + } + + get postsTable() { + return this.page.$('table.widefat.post.fixed'); + } +} + +module.exports = PostsPage; diff -uNr a/mp-wp-tests/test/pages/index.js b/mp-wp-tests/test/pages/index.js --- a/mp-wp-tests/test/pages/index.js false +++ b/mp-wp-tests/test/pages/index.js bde5a1a7d1e8e3c887808e3cc8a81ff8eb104da736eacc5a730ecb6f765df938dc0d30e80eadb441c2cf6fc7c82bb8f2ef32b68439f1fa589083c70031eafe6e @@ -0,0 +1,11 @@ +const LoginPage = require('../pages/LoginPage'); +const DashboardPage = require('../pages/DashboardPage'); +const PostsPage = require('../pages/PostsPage'); +const EditPostPage = require('../pages/EditPostPage'); + +module.exports = { + LoginPage, + DashboardPage, + PostsPage, + EditPostPage, +}; diff -uNr a/mp-wp-tests/test/specs/Posts.js b/mp-wp-tests/test/specs/Posts.js --- a/mp-wp-tests/test/specs/Posts.js false +++ b/mp-wp-tests/test/specs/Posts.js 7ed5c63d8fa9d62776faec1740c6353946a3e943198e68fb9f38f30aa65df5e2f4fbdaaa152ed74d6d7db484c06b38c9c0926ce24b3e586f4d2f7dcab20c3d4c @@ -0,0 +1,43 @@ +const { LoginPage, DashboardPage, PostsPage, EditPostPage } = require('../pages'); + +describe('Posts', () => { + beforeAll(() => { + const loginPage = new LoginPage(); + loginPage.navigate(); + loginPage.logIn(); + }); + + afterAll(() => { + const dashboardPage = new DashboardPage(); + dashboardPage.navigate(); + dashboardPage.logOut(); + }); + + it('Can navigate to and display the Posts page', () => { + const dashboardPage = new DashboardPage(); + dashboardPage.followNavLinkTo('Posts', 'Edit Posts'); + + const postsPage = new PostsPage(); + + expect(postsPage.pageTitle.isExisting()).toBe(true); + expect(postsPage.postsTable.isExisting()).toBe(true); + }); + + it('Can create and publish a post', () => { + const dashboardPage = new DashboardPage(); + dashboardPage.followNavSubMenuLinkTo('Posts', 'Add New', 'Add New Post'); + + const postTitle = 'Bitcoin Declaration Of Sovereignty'; + const postBody = '
When in the course of human events, it becomes necessary for one person to dissolve the political bands which have connected them with the human herd, and to assume among the powers of the world the separate and equal station to which the laws of nature entitle them, a modicum of respect to their own intelligence requires that they should declare the causes which impel them to the separation.
'; + + const editPostPage = new EditPostPage(); + editPostPage.editAndPublishPost({ postTitle, postBody }); + + expect(editPostPage.page.$('#message*=Post published').isExisting()).toBe(true); + + dashboardPage.navigateToBlog(); + + expect($(`a=${postTitle}`).isExisting()).toBe(true); + expect($('.entry').getHTML(false).trim()).toEqual(postBody); + }); +}); diff -uNr a/mp-wp-tests/wdio.conf.js b/mp-wp-tests/wdio.conf.js --- a/mp-wp-tests/wdio.conf.js false +++ b/mp-wp-tests/wdio.conf.js 45fb0ea2996a4a447a2e6c6bf82591865e4ee9cc9839fd48ef225882bc5566c9ef0913c1c125c90636d695eb2efe69be2f72465f38297d130eecc3eaef51685b @@ -0,0 +1,253 @@ +exports.config = { + // + // ==================== + // Runner Configuration + // ==================== + // + // WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or + // on a remote machine). + runner: 'local', + // + // ================== + // Specify Test Files + // ================== + // Define which test specs should run. The pattern is relative to the directory + // from which `wdio` was called. Notice that, if you are calling `wdio` from an + // NPM script (see https://docs.npmjs.com/cli/run-script) then the current working + // directory is where your package.json resides, so `wdio` will be called from there. + // + specs: [ + './test/specs/**/*.js' + ], + // Patterns to exclude. + exclude: [ + // 'path/to/excluded/files' + ], + // + // ============ + // Capabilities + // ============ + // Define your capabilities here. WebdriverIO can run multiple capabilities at the same + // time. Depending on the number of capabilities, WebdriverIO launches several test + // sessions. Within your capabilities you can overwrite the spec and exclude options in + // order to group specific specs to a specific capability. + // + // First, you can define how many instances should be started at the same time. Let's + // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have + // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec + // files and you set maxInstances to 10, all spec files will get tested at the same time + // and 30 processes will get spawned. The property handles how many capabilities + // from the same test should run tests. + // + maxInstances: 10, + // + // If you have trouble getting all important capabilities together, check out the + // Sauce Labs platform configurator - a great tool to configure your capabilities: + // https://docs.saucelabs.com/reference/platforms-configurator + // + capabilities: [{ + maxInstances: 5, + browserName: 'firefox', + }], + + // Run browser commands synchronously + sync: true, + // + // =================== + // Test Configurations + // =================== + // Define all options that are relevant for the WebdriverIO instance here + // + // Level of logging verbosity: trace | debug | info | warn | error | silent + logLevel: 'error', + // + // Set specific log levels per logger + // loggers: + // - webdriver, webdriverio + // - @wdio/applitools-service, @wdio/browserstack-service, @wdio/devtools-service, @wdio/sauce-service + // - @wdio/mocha-framework, @wdio/jasmine-framework + // - @wdio/local-runner, @wdio/lambda-runner + // - @wdio/sumologic-reporter + // - @wdio/cli, @wdio/config, @wdio/sync, @wdio/utils + // Level of logging verbosity: trace | debug | info | warn | error | silent + // logLevels: { + // webdriver: 'info', + // '@wdio/applitools-service': 'info' + // }, + // + // If you only want to run your tests until a specific amount of tests have failed use + // bail (default is 0 - don't bail, run all tests). + bail: 0, + // + // Set a base URL in order to shorten url command calls. If your `url` parameter starts + // with `/`, the base url gets prepended, not including the path portion of your baseUrl. + // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url + // gets prepended directly. + baseUrl: 'http://localhost', + // + // Default timeout for all waitFor* commands. + waitforTimeout: 10000, + // + // Default timeout in milliseconds for request + // if Selenium Grid doesn't send response + connectionRetryTimeout: 90000, + // + // Default request retries count + connectionRetryCount: 3, + // + // Test runner services + // Services take over a specific job you don't want to take care of. They enhance + // your test setup with almost no effort. Unlike plugins, they don't add new + // commands. Instead, they hook themselves up into the test process. + services: ['selenium-standalone'], + + // Framework you want to run your specs with. + // The following are supported: Mocha, Jasmine, and Cucumber + // see also: https://webdriver.io/docs/frameworks.html + // + // Make sure you have the wdio adapter package for the specific framework installed + // before running any tests. + framework: 'jasmine', + // + // The number of times to retry the entire specfile when it fails as a whole + // specFileRetries: 1, + // + // Test reporter for stdout. + // The only one supported by default is 'dot' + // see also: https://webdriver.io/docs/dot-reporter.html + reporters: ['spec'], + + // + // Options to be passed to Jasmine. + jasmineNodeOpts: { + // + // Jasmine default timeout + defaultTimeoutInterval: 60000, + // + // The Jasmine framework allows interception of each assertion in order to log the state of the application + // or website depending on the result. For example, it is pretty handy to take a screenshot every time + // an assertion fails. + expectationResultHandler: function(passed, assertion) { + // do something + } + }, + + // + // ===== + // Hooks + // ===== + // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance + // it and to build services around it. You can either apply a single function or an array of + // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got + // resolved to continue. + /** + * Gets executed once before all workers get launched. + * @param {Object} config wdio configuration object + * @param {Array.