Monday, May 9, 2011

Intro to Selenium 2 with IDE

Selenium 2 brings many improvements to the Selenium Suite of tools. The quickest way to get started is to download this plug in to Firefox for Selenium IDE web backed formatters. This will allow you to change to format to WebDriver and save the test code into your jUnit or nUnit test suite.

Within the IDE of you choice such as Eclipse or NetBeans edit your project to add the Selenium 2 dependent libraries and selenium-java-2.0b3.jar. The zip file you need on the download page. Or go directly.

This is using the web backed selenium driver which will use the Selenium 1 commands. Once your old tests are working they can be converted to WebDriver type commands. Currently WebDriver does not support all browsers such as Safari so using this emulator mode might be best way to run WebDriver.

By using WebDriver you will not have to start the Selenium Server before running tests. In addition, WebDriver tests do not work by controlling the browser with Javascript. Selenium RC would always want to modify the proxy settings of the browser to enable operation. If your administrator has locked out the ability to modify proxy settings it was impossible to run tests against remote applications. Selenium 2 is a way around this. There should also be additional benefits when testing SSL enabled applications.

If you wish to run the tests using jUnit or have written your tests using the SeleneseTestCase class you must extend your test class. In addition you will have to add the old selenium-java-client-driver.jar file to the project. If you do not use SeleneseTestCase just extend jUnit TestCase.

For more information see http://seleniumhq.org/docs/03_webdriver.html.

The tests will end up looking like the code below.

package com.example.tests;


import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;
import org.openqa.selenium.*;
import org.openqa.selenium.htmlunit.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.ie.*;
import org.junit.*;
import static org.junit.Assert.*;


public class webDriverTest extends SeleneseTestCase {
WebDriver driver;
Selenium selenium;


public void setUp() {
  driver = new FirefoxDriver();
  selenium = new WebDriverBackedSelenium(driver,"http://www.lmnsolutions.com/");
}


public void tearDown() {
  driver.close();
}


public void testUntitled() {
  selenium.open("/");
  selenium.click("//div[@id='topnav']/ul/li[4]/a/span");
  selenium.waitForPageToLoad("30000");
  assertEquals("$1200", selenium.getText("//div[@id='twocol-col2']/div[2]/h5[5]"));
}
}



I hope this helps you out in converting over to Selenium 2.


© Copyright 2012 LMN Solutions

If you  have a question e-mail us or add a comment.






LMN Solutions - Find out more about us.


Friday, May 6, 2011

Selenium Training Announced

We have announced dates for our 2 day selenium class.

Please see http://lmnsolutions.com/training.html for more information.

Tuesday, April 19, 2011

Selenium Tip - Using Regular Expressions

This comes straight out of the LMN Selenium classes we offer. A tip to help you find html elements that have the same series of letters in them. This is a small screen shot from one of the applications we built to filter news articles for us, determine the location and put it on a map.

Notice the two rows that have the letters bomb. How would you verify the existence of each element?


<a target="_blank" href="http://news.google.com/news/url?fd=R&amp;sa=T&amp;url=http%3A%2F%2Fwww.topnews.in%2Fsuicide-bombing-iraqi-football-stadium-2261845&amp;usg=AFQjCNGt7-LevFBRrBlwKot-8QL5ymhpOA">Suicide bombing at Iraqi football stadium - TopNews</a>
<a target="_blank" href="http://news.google.com/news/url?fd=R&amp;sa=T&amp;url=http%3A%2F%2Fwww.abc.net.au%2Fnews%2Fstories%2F2010%2F05%2F15%2F2900299.htm%3Fsection%3Dworld&amp;usg=AFQjCNG9SJlQwiS55Jv77lp8Nb5OhVwOaQ">Deadly bomb blast hits packed football stadium - ABC Online</a>

Find the link with the word bombing and then the one with the word bomb.

Selenium IDE:

Command
Target
Value
verifyElementPresent
css=a:contains(“bomb”)
verifyElementPresent
css=a:contains(“^bomb$”)


Selenium RC - jUnit
verifyTrue(selenium.isElementPresent("css=a:contains(‘^bomb$’)"));

The ^ means start with. The $ means ends with. This is called regular expression language. This combination of caret bomb dollar sign is the compete expression and will find the exact word bomb.

For more information, questions or topics you would like to see here e-mail us.


Monday, April 18, 2011

Automated Testing with Selenium Training

Automated Testing with Selenium Training

Last month we started teaching a class on Selenium IDE and Selenium Remote Control. Watch this blog for upcoming announcements for more classes. The class is hosted in Reston, Virginia.

It has been a pleasure to teach others what I know about Selenium. We hope to blog more on Selenium testing tips in the near future.

Within fast moving agile software development teams it becomes important to test user interfaces as they are being coded. Automated Testing techniques using Selenium allow for test replay of important features as development progresses.
Selenium IDE and Selenium Remote Control are important tools for any tester and even developer to use in ensuring software quality and consistency. This interactive hands-on workshop provides an understanding and advanced techniques in the use of Selenium with hands on practice. The practice exercises are tailored to various skill levels and type of application being tested, from simple forms to Ozone Widget Framework applications.

Using presentations, guided configuration and automated test plans, the class teaches:
• Understand trade-offs of automated vs. manual testing.
• Record, edit and play back Selenium IDE tests against multiple types of web applications.
• Minimize test failure due to normal changes to code.
• Understanding of basic Selenium commands to get through common issues with web applications
• Move tests from IDE to Selenium RC.
• Use of Eclipse to run tests individually and as a group to generate test failure reports
• Understand the importance of making applications more testable to improve usability.

Topics
• Overview of automated testing
• Selenium IDE
• HTML Locator strategy
• Firefox Firebug
• Selenium Remote Control setup
• Eclipse and jUnit
• Moving IDE tests to Selenium RC
• Selenium RC practice workshop.
• Learn how to test in multiple browsers and generate metrics and reports.
• Discussion of setting up Selenium RC for continuous integration

Bonus Features
• Sample Selenium RC code
• Scripts to run jUnit suite tests on multiple browsers and generate reports and metrics.
• List of web resources and blogs for reference.
• CSS locator cheat sheet.

If you want to come to the class or have a question e-mail us.





LMN Solutions - Find out more about us.
info@lmnsolutions.com

Sunday, April 17, 2011

Please Test Everything

Please Test Everything


Let me welcome you to this blog about software testing. We hope to share our knowledge of software testing with you. This blog comes out of a class we host at LMN Solutions called Selenium Workshop for Testers. We hope to post information here that will aid those who have taken the class.

The title of the blog is aspirational and often sums up the wish of those who rely on the software tester to make sure applications work correctly. In addition we hope to cover the breadth of software testing; ranging from automated, performance, unit, functional, integration, web, mobile, imagery to any new forms of testing we learn about on the way. Some of the things we will cover around testing are Java, jUnit, Selenium, Watir, Cucumber, Ruby on Rails, Fitnesse, MarkLogic, GIS, Imagery testing and more.

Please subscribe and get ready for some testing tips, tricks and hacks.

Please contact us with any topics that would be of interest. lmn-testing@lmnsolutions.com

www.lmnsolutions.com