I'm writing unit tests using PHPUnit and WP_UnitTestCase, and using Selenium for front-end testing.

My Selenium test classes merrily click around my pages without trouble. What would be truly useful, though, would be if they could also execute code in the context of WordPress. So for example, I could test visiting a user's profile page, then change the path to the page and test that, too.

As a stopgap I've made a very crude adapter for wp-cli, which I use inside my test. Obviously this is quite clunky. Is there any way I can get at all the goodness of a WP_UnitTestCase in the context of a Selenium test?

  • Could you expand a bit on this use case 'test visiting a user's profile page, then change the path to the page' ... WordPress Permalinks would mean an author / profile page would always be at the same url like 'damien.co/author/damiensaunders' – Damien Oct 18 '12 at 10:27
  • hi. i'd change the rewrite rules, but it's immaterial anyway - perhaps a better example would be "visit a user's page, delete the user, then confirm their page would give a 404" - something a bit more like you can do using RSpec – djb Oct 18 '12 at 10:52

There are many ways to skin a cat and trying to use Selenium with WordPress CLI is new to me. Essentially, WordPress is 'just' a dynamic website using a SQL database with some themes and plugin files behind it.

Selenium is designed as a frontend browser test tool so keep that in mind for a minute and I assume you mean Selenium IDE. The result would be very brittle test cases if you built something up with Selenium IDE + WordPress CLI.

What is Brittle? Hard to maintain, test cases that need to be adjusted everytime you try to run them, a lot more test fails then passes. <<

Given your experience of testing is probably more than mine (which is easy) ... I'd recommend you look at python or php and connect to the mySQL database and not use WP CLI (or start by having SequelPro or PHPMyAdmin running).

I believe this is what you are looking for as:

a. It separates the Front End user experience from the database
b. Your Selenium IDE test cases won't need WP CLI
c. You won't need to update your Selenium test cases as often as you probably do today
d. You can trigger pyhton / php unit tests from terminal
e. You can play around with database changes and just watch your Selenium test cases pass or fail f. you can the just drop / reset your database table and start test cases again :)

PS ... I've written about using ChromeDriver / Python / Selenium to do very basic browser tests for my WordPress site.

PPS I'd be interested to keep in touch / have a chat if you're in the UK about Selenium / WordPress, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.