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

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

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.

This answer of mine originally appeared on WordPress Answers / Stackexchange

Answer by Damien for Can I get at WordPress code from inside a Selenium test?:

Key trends in mobile usage from the UK

Mobile usage in the UK is on the increase. That’s all sounding good so far.

The latest communications report from Ofcom has shown a year on year growth of 1.6 million mobiles and the biggest growth in postpaid subscribers due to more customers taking out contracts for smartphones.

Want to download this for free? Read to the end of the presentation and copy the discount coupon code.

HOW TO: Install Chromedriver for Mac OS X / Selenium / Python

HOW TO: Install Chromedriver for Mac OS X / Selenium / Python

Selenium is great for automated testing of web-apps and I’ve been using the Firefox extension Selenium IDE for a few months now.

For completeness of automated testing for web apps you need to do this in a number of different browsers which Selenium IDE doesn’t do. So you’ll need to download and install Selenium on your Mac.

You can follow my Java or Python instructions to get started and install Selenium on your Mac.

Download Chromedriver to your Mac

Head over to the Chromedriver Project page and download the latest package.

You then need to unzip the package and then copy the file to /usr/bin

This is a hidden system folder so the easy way to get to this file is

  1. Open another finder window
  2. From the Go menu select Go To Folder
  3. Type /usr/bin and press enter

Now drag n drop the Chromedriver file from your Download folder to this directory. You’ll be prompted for you Admin password.

Finally, I suggest you restart your computer  as the next step didn’t work when I tried it.

Basic Test Case for Chromedriver and Selenium

If you’ve already followed my guide to setup Selenium via Python then this will look familiar

Open a terminal window and type the following, pressing enter at the end of each line

python
from selenium import webdriver
driver = webdriver.Chrome()

After a few seconds, if all is well a new instance of Chrome will open

To finish the test just type

driver.get("http://www.damien.co")

To exit Python from your open Terminal, press ctrl+z

HOW TO: Get started with Selenium 2 for Mac OS X / Java

HOW TO: Get started with Selenium 2 for Mac OS X / Java

If you own a Mac and want to get started with Selenium for Automated Testing of your web apps, then you’re already most of the way there. The Mac operating system already offers a number of baked in solutions and command line tools like Python, Ruby and Java.

Read my guide to setup Selenium with Pythonwhich is probably easier if you want to get started immediately

Get started with Selenium IDE and Firefox

Selenium IDE is a browser extension for Firefox. It’s useful to use this to create test cases so install this first.

Download & Install Selenium Java Server

Now you just have to get the selenium standalone java server so type

[php]mkdir selenium
cd selenium/
wget http://selenium.googlecode.com/files/selenium-server-standalone-2.24.1.jar
[/php]
(or check the project page for the latest Selenium Standalone Server)

Start the Selenium Standalone Java Server

While you’re in Terminal open a new shell / terminal window and type

[php]cd selenium/
java -jar selenium-server-standalone-2.24.1.jar[/php]

You’ll see some verbose scripting about the server starting and you can visit this URL to check the server status

http://127.0.0.1:4444/wd/hub/static/resource/hub.html

Stop the Selenium Server

Copy and visit this URL in your browser

http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
HOW TO: Install Selenium 2 for Mac OS X / Python

HOW TO: Install Selenium 2 for Mac OS X / Python

If you own a Mac and want to get started with Selenium for Automated Testing of your web apps, then you’re already most of the way there.

The Mac operating system already offers a number of baked in solutions and command line tools like Python, Ruby and Java.

How To Install Selenium on your Mac OSx

Mac already has Python and a package manager called easy_install, so open Terminal and type

sudo easy_install selenium

You need to run this as Sudo / Root or it can’t create the folders in protected directories.

1st Selenium Test Script from Command Line

Now open another Terminal / shell and type (press enter after each command)

python
from selenium import webdriver
driver = webdriver.Firefox()

If everything is setup, Firefox will open a new browser

To finish this test type

driver.get("http://www.damien.co")

Linkage

Python bindings

Install Climber – I must say this post did seem to be auto-translated into English.