| storeEval | var d=new Date(); ((d.getMonth()+1))+'/'+d.getDate()+'/'+d.getFullYear(); | date1 |
Monday, March 5, 2012
Javascript to get current date: m/d/yyyy
I used the following javascript in Selenium IDE to get the current date in the format m/d/yyyy (ex: 2/5/2012 or 12/10/2012). No zero's preceed the month and day.
Selenium IDE commands that don't export to C# WebDriver
I'm working on a Selenium 2 automation framework in C#. After recording scripts in IDE, I export them to C# (WebDriver). Some IDE commands will not export to C#, and you end up with messages like this:
// ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
So, obviously verifyTextPresent and assertTextPresent do not export. I plan to figure out the best way to code this in C# because "verifyTextPresent" is useful in things like smoke scripts, where I don't want the script to fail easily because a page element moved or was renamed.
If you're using the flowControl extension, "gotoIf" and "label" commands do not export; but that's not really a big deal.
getEval and storeEval do not export. Sometimes I use these javascript commands to get the current date or generate a random value. Again no big deal.
These are the only ones I've run into so far.
// ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
So, obviously verifyTextPresent and assertTextPresent do not export. I plan to figure out the best way to code this in C# because "verifyTextPresent" is useful in things like smoke scripts, where I don't want the script to fail easily because a page element moved or was renamed.
If you're using the flowControl extension, "gotoIf" and "label" commands do not export; but that's not really a big deal.
getEval and storeEval do not export. Sometimes I use these javascript commands to get the current date or generate a random value. Again no big deal.
These are the only ones I've run into so far.
Selenium IDE Conditional commands
Using the flowControl extension, you can include conditional commands in Selenium IDE. The conditional statements do not export to WebDriver (Selenium 2) C# scripts; but it's still a very handy tool for IDE.
I used javascript to define conditions. In the following example, if the variable, aVar, is greater than 550, the script moves to the line that is labeled 'target1'. If the variable is 550 or less, the verifyText command executes.
Here's an example of javascript checking if the variable is less than 550 or greater than 599, the script skips to the line labeled "target2". If the variable is between 550 and 599, the verifyText command executes.
One thing to keep in mind is that each "label" value has to be unique throughout the script. In other words, you cannot have two "target1" labels.
I used javascript to define conditions. In the following example, if the variable, aVar, is greater than 550, the script moves to the line that is labeled 'target1'. If the variable is 550 or less, the verifyText command executes.
| gotoIf | storedVars.aVar > 550 | target1 |
| verifyText | css=span.amount | $500.00 |
| label | target1 |
Here's an example of javascript checking if the variable is less than 550 or greater than 599, the script skips to the line labeled "target2". If the variable is between 550 and 599, the verifyText command executes.
| gotoIf | storedVars.aFico < 550 || storedVars.aFico > 599 | target2 |
| verifyText | css=span.current-amount | $500.00 |
| label | target2 |
One thing to keep in mind is that each "label" value has to be unique throughout the script. In other words, you cannot have two "target1" labels.
Selenium IDE Data-driven testing
You can do data-driven testing using Selenium IDE data driven extension. However, your data must be in an XML file, and the data must be defined in attributes of the "test" element. It is possible to create an XML file from an Excel file (just look it up in MS Excel Help); however, the data is imported as elements, not attributes.
Friday, April 29, 2011
Quality Assurance vs. Testing
I've known QA Analysts who became very upset when called "testers". There's an idea that being an "Analyst" means you analyze the quality of an application, which involves more than just testing. Being called a "tester" implies that all you do is test and nothing else.
There are a lot of strong opinions about whether we are in the Quality Assurance or Testing business.
I really like Michael Bolton's blog post on the subject:
http://www.developsense.com/blog/2010/05/testers-get-out-of-the-quality-assurance-business/(insert over-used, but still funny Office Space joke here)
Wednesday, March 23, 2011
Selenium IDE and Wicket
When testing a Wicket application, Selenium IDE often records element id's that are dynamic and change every time the application is opened. To resolve this problem, I followed this tip from https://issues.apache.org/jira/browse/WICKET-1830 by Frank van Lankvelt.
Create a folder "wicketPathLocatorBuilder" with the file "user-extension.js.wicketPathLocatorBuilder". Paste the following snippet in this file.
Open Selenium IDE, go to menu Options -> Options. In the Selenium Core extensions input field, paste the path to the earlier created folder "wicketPathLocatorBuilder". Restart firefox.
Now when you record tests, the wicketpath attribute is used to generate an element locator.
Create a folder "wicketPathLocatorBuilder" with the file "user-extension.js.wicketPathLocatorBuilder". Paste the following snippet in this file.
LocatorBuilders.add('wicketpath', function(e) {
this.log.debug("wicketpath: e=" + e);
if (e.attributes && e.hasAttribute("wicketpath")) {
this.log.info("found attribute " + e.getAttribute("wicketpath"));
return "//" + this.xpathHtmlElement(e.nodeName.toLowerCase()) +
"[@wicketpath=" + this.attributeValue(e.getAttribute("wicketpath")) + "]";
}
return null;
});
LocatorBuilders.order.unshift(LocatorBuilders.order.pop());
Open Selenium IDE, go to menu Options -> Options. In the Selenium Core extensions input field, paste the path to the earlier created folder "wicketPathLocatorBuilder". Restart firefox.
Now when you record tests, the wicketpath attribute is used to generate an element locator.
Wednesday, February 23, 2011
Incremental Variables in Selenium
I needed to create 50 names that were similiar and incremental (ex: Tracey1, Tracey2, Tracey3, etc.). I used javascript to increment the numbers.
<!--Here I store the alpha-text part of my name as variable 'a'. This allows me to change this later to something else.-->
<tr>
<td>store</td>
<td>Tracey</td>
<td>a</td>
</tr>
<!--This increments the number ('y'), starting at 1-->
<tr>
<td>store</td>
<td>1</td>
<td>x</td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['x'] = ${x}+1</td>
<td>y</td>
</tr>
<!--Here I type the name-->
<tr>
<td>type</td>
<td>fieldname</td>
<td>${a}${y}</td>
</tr>
<!--And the next time I need to type the name, I just increment 'y' by one-->
<tr>
<td>storeEval</td>
<td>storedVars['y'] = ${y}+1</td>
<td>y</td>
</tr>
<tr>
<td>type</td>
<td>fieldname</td>
<td>${a}${y}</td>
<!--Here I store the alpha-text part of my name as variable 'a'. This allows me to change this later to something else.-->
<tr>
<td>store</td>
<td>Tracey</td>
<td>a</td>
</tr>
<!--This increments the number ('y'), starting at 1-->
<tr>
<td>store</td>
<td>1</td>
<td>x</td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['x'] = ${x}+1</td>
<td>y</td>
</tr>
<!--Here I type the name-->
<tr>
<td>type</td>
<td>fieldname</td>
<td>${a}${y}</td>
</tr>
<!--And the next time I need to type the name, I just increment 'y' by one-->
<tr>
<td>storeEval</td>
<td>storedVars['y'] = ${y}+1</td>
<td>y</td>
</tr>
<tr>
<td>type</td>
<td>fieldname</td>
<td>${a}${y}</td>
Subscribe to:
Posts (Atom)