Can I get at WordPress code from inside a Selenium test?

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.

Read More

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?

Related posts

Leave a Reply

1 comment

  1. 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.