Pages

Sunday, February 8, 2015

Tableau Testing Automation using Selenium IDE

Have you ever had to test a million reports on Tableau and take screenshots to prove they are working (or not as the case might be)? Well, maybe not a million but most Tableau implementations grow quite quickly as it is so much fun to use. A typical use case for this sort of testing would be a migration to another server or a server upgrade.

Recently I have spent a day testing Tableau reports for one of my clients, taking lots of screenshots. A big part of my test included:
  1. open a view in Tableau
  2. take a screenshot
  3. go back and repeat from step 1.
Does this make you want to automate the process? Yes, that is what my partner said when I told him how I've spent my day. Solution by Ralf Weinand:
  1. Download and install Firefox browser
  2. Download Selenium IDE: http://www.seleniumhq.org/projects/ide/
  3. Download a Firefox add-on 'Selenium IDE Flow Control' https://addons.mozilla.org/en-US/firefox/addon/flow-control/
  4. In Firefox open Selenium IDE: Tools -> Selenium IDE
  5. Create a new test as per screenshot below (or copy-paste the code below). Adjust the server name and the location where to save the screenshots.
  6. Go grab some coffee. Happy testing!

Code credit: Ralf Weinand

<?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="https://localhost/views" />
<title>Tableau Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>http://localhost/views</td>
    <td></td>
</tr>
<tr>
    <td>store</td>
    <td>1</td>
    <td>x</td>
</tr>
<tr>
    <td>storeXpathCount</td>
    <td>//div[1]/div[4]/div[1]/div[2]/form/div/div/div/div[2]/span/span[2]/div[1]/div/div/span/a</td>
    <td>max</td>
</tr>
<tr>
    <td>while</td>
    <td>(${x}&lt;=${max})</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>//div[1]/div[4]/div[1]/div[2]/form/div/div/div/div[2]/span/span[2]/div[1]/div[${x}]/div/span/a</td>
    <td></td>
</tr>
<tr>
    <td>storeAttribute</td>
    <td>//div[1]/div/div[1]/span[1]/div[1]/span[2]@title</td>
    <td>workbook</td>
</tr>
<tr>
    <td>storeLocation</td>
    <td>url</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>'${url}'.split('/').last();</td>
    <td>sheet</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>'${url}'.split('/').slice(-2, -1)[0];</td>
    <td>workbookurl</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>'${workbooknametemp}'.replace('/','_');</td>
    <td>workbookname</td>
</tr>
<tr>
    <td>echo</td>
    <td>${workbookurl}</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>${workbookname}</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>${sheet}</td>
    <td></td>
</tr>
<tr>
    <td>pause</td>
    <td>10000</td>
    <td></td>
</tr>
<tr>
    <td>captureEntirePageScreenshot</td>
    <td>C:\Users\julia\Desktop\tableau_selenium_test_workbooks\${workbookurl}_${sheet}.png</td>
    <td></td>
</tr>
<tr>
    <td>open</td>
    <td>http://localhost/views</td>
    <td></td>
</tr>
<tr>
    <td>waitForElementPresent</td>
    <td>//div[1]/div[4]/div[1]/div[2]/form/div/div/div/div[2]/span/span[2]/div[1]/div[${max}]/div/span/a</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>storedVars['x'] = ${x}+1</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>${x}</td>
    <td></td>
</tr>
<tr>
    <td>endWhile</td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>name=navbar-iframe</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>link=Sign In</td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>null</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>id=Email</td>
    <td>julia.gusman@gmail.com</td>
</tr>
<tr>
    <td>type</td>
    <td>id=Passwd</td>
    <td>julia007</td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>id=signIn</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>link=Drag and Drop</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>//img[@alt='Create new post']</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>//body[@id='blogger-app']/div[3]/div[3]/div/div/div/form/div/span/button[4]</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=span.GCUXF0KCNIB</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>link=Edit</td>
    <td></td>
</tr>
<tr>
    <td>selectFrame</td>
    <td>Rich text editor</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=img</td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>null</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>id=tr_delete-image</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=div.tr-icon.tr-image</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=input[type=&quot;file&quot;]</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>css=input[type=&quot;file&quot;]</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>id=picker:ap:0</td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>name=Rich text editor</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=img</td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>null</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>id=tr_x-large_link</td>
    <td></td>
</tr>
<tr>
    <td>selectFrame</td>
    <td>Rich text editor</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=img</td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>null</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>id=tr_original_link</td>
    <td></td>
</tr>
</tbody></table>
</body>
</html>

4 comments: