Posted on

Selenium IDE Script for New WordPress Site Setup

selenium ide

I use Selenium IDE as a testing tool for WordPress plugins.  It provides basic testing of the user interface elements via a record-and-playback browser script.   However, there is another use for tools like Selenium IDE; automation of repetitive web tasks.   On every build I reset my WordPress install and build a new site.   The setup form is short, but it is something I do at least once every week and answer the same half-dozen questions the same way.

The script shown below is my Selenium IDE script that sets up the website and activates a few plugins I know I am going to want on every site setup.   The script prompts for the admin password during execution.  Other than that it is hands off.    As for the plugins, they are already in my wp-content/plugins sub-directory.  You will need to modify the checkbox IDs and email address to implement this effectively on  your WordPress development and testing servers.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhost/" />
<title>New SLP Install</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New SLP Install</td></tr>
</thead><tbody>
<tr>
	<td>setSpeed[box type="info"]Determines how fast the test script runs.  Delay between commands in ms.  0 (fast) is the default.  Slow is 900.[/box] </td>
	<td>200</td>
	<td></td>
</tr>
<tr>
	<td>open</td>
	<td>/wp-admin/install.php</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>id=weblog_title</td>
	<td>SLP Dev</td>
</tr>
<tr>
	<td>storeEval</td>
	<td>prompt(&quot;Password&quot;)</td>
	<td>password</td>
</tr>
<tr>
	<td>type</td>
	<td>id=user_login</td>
	<td>admin</td>
</tr>
<tr>
	<td>type</td>
	<td>id=pass1</td>
	<td>${password}</td>
</tr>
<tr>
	<td>type</td>
	<td>id=pass2</td>
	<td>${password}</td>
</tr>
<tr>
	<td>type</td>
	<td>id=admin_email</td>
	<td>your...email...here</td>
</tr>
<tr>
	<td>click</td>
	<td>name=blog_public</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>name=Submit</td>
	<td></td>
</tr>
<tr>
	<td>open</td>
	<td>/wp-login.php</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>id=user_login</td>
	<td>admin</td>
</tr>
<tr>
	<td>type</td>
	<td>id=user_pass</td>
	<td>${password}</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>id=wp-submit</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>//li[@id='menu-pages']/a/div[3]</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>link=Edit</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>id=content</td>
	<td>[slplus]</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>id=publish</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>link=Installed Plugins</td>
	<td></td>
</tr>
<tr>
	<td>click</td>
	<td>id=checkbox_a55f1e83ab4fee1b42772d08e9971a9c</td>
	<td></td>
</tr>
<tr>
	<td>click</td>
	<td>id=checkbox_bac6e3a30c8d87d2221981bfc36c48c6</td>
	<td></td>
</tr>
<tr>
	<td>click</td>
	<td>id=checkbox_b70d95e549c77d1ee381947b403a4ff0</td>
	<td></td>
</tr>
<tr>
	<td>select</td>
	<td>name=action</td>
	<td>label=Activate</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>id=doaction</td>
	<td></td>
</tr>
</tbody></table>
</body>
</html>

Yes, Selenium IDE stores the script data in an HTML table.    The first cell is the command, the second is the target the third is the value.  Makes for easy editing of scripts with other tools if you find the need.