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.
 
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>

Friday, August 27, 2010

Oracle Dates and Timestamps

Date/Timestamps in Oracle make be break out into hives. And then I start to miss MS SQL Server.....a little.

Oracle does not like to return timestamps when querying date/time fields; so sometimes I have to use something like this:

SELECT to_char(to_timestamp(to_char(a.fieldName, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS'))
FROM tableName a

Saturday, August 7, 2010

SpiraTest Tips

  • Make your test case names as short as possible. On some screens, SpiraTest only shows so many characters of the test name, so shorter is better.
  • I had trouble changing the font on the Test Steps. I had to view the step in HTML (a button when you're editing the step) and edit the HTML to change the fonts. I pretty much gave up on doing this b/c it's a waste of time.
  • Be careful navigating away from a test you are writing. SpiraTest will not warn you that you haven't saved your changes.
  • On the Test List screen, "Show Level" may need to be changed in order to view all tests

Non-Invasive VPN

If you need to route only certain traffic over a VPN connection, do the following:
  1. After setting up the VPN connection, open up the Connect screen.
  2. Click on Properties and go to the "Networking" tab.
  3. Select Internet Protocol and click on Properties.
  4. Click Advanced and go to the "General" tab.
  5. Uncheck "Use default gateway on remote network."
  6. Click OK 3 times to get back to the connect window.
  7. Connect.
  8. Open a command prompt and run ipconfig to see what IP the VPN server assigned you.
  9. Run the following command: route add 192.62.174.0 MASK 255.255.255.0
Replace  with the actual IP the VPN assigned you.
    For example, if I were assigned IP 192.168.0.216, I'd run this command: route add 192.62.174.0 MASK 255.255.255.0 192.168.0.216
    .

    Checkboxes and Selenium

    When checking (or unchecking) a checkbox, Selenium IDE might record something like this:
    click - chckbx_0_0
    Both the command and the location are ambiguous.

    For example, let's say you're trying to
    uncheck BoxA. "Click" is ambiguous because if BoxA is already unchecked, you'll check it by clicking the checkbox. "chckbx_0_0" is ambiguous as a locator because if checkboxes are added or removed from the screen in the future, "chckbx_0_0" could identify a different checkbox.

    Use this instead:
    command = uncheck (or check)
    target (location) = relative xPath of the checkbox element

    Of course, Selenium IDE recorded ambiguously on my project in this particular scenario. It will record differently depending on the application.

    XPath and Selenium Locator Information

    I often need to use a relative XPath to locate elements in Selenium. A few reasons to use relative XPath:
    1. The ID of the element changes every time you go to the page.
    2. You suspect the element could change location in the future and the locator recorded by Selenium IDE is too ambiguous to handle changes in the future.
    Here's some excellent information on Locators in Selenium: http://seleniumhq.org/docs/02_selenium_ide.html#locating-elements

    I often refer to http://www.w3.org/TR/xpath/ , particularly sections 2 Location Paths, 2.2 Axes, 2.5 Abbreviated Syntax.