Getting Started
Requirements
In order to run WPSelenium you will need to have the following installed
- Java (and make sure its on your system path. Type java in your terminal or command line window to check)
- Php >= 7.2
- Composer
- Chrome or Firefox or any other browser you want to test on (given you have the drivers)
1. Install
To get started with WPselenium install it using composer using the following command:-
composer require --dev devchid/wpselenium
Note:- This command assumes that the working directory you are running it from is a composer project. If not, you can easily make it one buy running
composer init
or adding acomposer.json
file.
Note:- WPSelenium currently downloads the 76.0.3809.126 chrome drivers and the 0.24 firefox gecko drivers. If your browser needs a newer or older version of a driver (you will get error suggesting this if unsure) please specify an updated download url for the driver in the wpselenium.xml config file. Please see Configuration > Advance for more detail.
2. Configure
Having installed wpselenium you need to create a wpselenium.xml config file. This file should be in the same location as your composer.json
file.
Below is a basic sample configuration to get you going. Please see the Configuration section below for more options.
<wpselenium>
<siteUrl>http://localhost:3000</siteUrl>
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="WPSelenium Sample Tests">
<file>vendor/devchid/wpselenium/src/Sample/SampleTest.php</file>
</testsuite>
</testsuites>
</phpunit>
</wpselenium>
You will need to replace siteUrl
, with the site you are trying to test.
Note:- The WPSelenium.xml can embed the phpunit config, using the phpunit endpoint (like above). This specified config is then loaded when testing your project with phpunit. However if you want to create your own phpunit config file (phpunit.xml) you can also do this (and not include it here). See Configuration > Basic for more details.
3. Run Tests
After this previous step you are in essence done. You can now run the following command from the same location as your composer.json
file (were browser_driver
can either be chrome or firefox) to test.
/vendor/bin/wpselenium [brower_driver]
If everything was configured properly you should see a browser window opened up to your site's home page (Example below). This window will close after about 10s . Note, this is using the sample test that comes with WPSelenium, specified in the config above.
Note:-
- On first run WPSelenium will download the required files and configure those appropriately. This means your first run will take a little bit longer to start testing your site.
- On windows you might get a pop up asking you to allow java to run. This is for the selenium server. Accept this, and run wpselenium again.
- WPSelenium currently comes with only support for chrome and firefox. However if there is another browser you want to test you can specify the link to the browser drivers in you wpselenium config. From there you can rerun the above command using the specified name of your driver (I.e /vendor/bin/wpselenium opera). See Configuration > Advance for more details.
If you managed to see the home page of your site like the above example, everything is set up correctly. You can now go ahead and write your tests.