Selenium 2 Find By JQuery Selector

Add a new WebElement selection strategy to Selenium 2 by extending the By class.

public class ByJQuerySelector extends By {

	    private final String jQuerySelector;

	    public ByJQuerySelector(String selector) {
	      this.jQuerySelector = selector;
	    }

	    @Override
	    public List findElements(SearchContext context) {
	      //TODO:Implement
	      return null;
	    }

	    @Override
	    public WebElement findElement(SearchContext context) {
	      return (RemoteWebElement) ((JavascriptExecutor) context)
  	          .executeScript("return $('" + jQuerySelector+ "').get(0);");
	    }

	    @Override
	    public String toString() {
	      return "By.jQuerySelector: " + jQuerySelector;
	    }

}

Now you can select a WebElement with a JQuery selector.

	@Test
	public void example6(){
		driver.get("http://www.o2.co.uk/broadband");

		//Now I can use JQuery selectors to find elements on the page!
		By loc = new ByJQuerySelector("a[title=Sign In]");

		driver.findElement(loc).click();

		assertEquals("O2 - Sign in - View bills , balances and emails in your My O2 account:",driver.getTitle());
	}

Today’s blog post is from O2 Broadband. Special thanks for their support.

Posted in Java, jQuery, Selenium | Tagged , , , | Leave a comment

Selenium: Check for images loaded

Someone at my NCDevCon talk asked if there was a way to verify that images on the page loaded without error.  I didn’t know the answer off the top of my head but I found out how to do it.  Here are a few examples:

    @Test
    public void testImageLoaded(){
        driver.get("http://www.akc.org/breeds/affenpinscher/");
        WebElement content = driver.findElement(By.id("akccontent"));
        WebElement image = content.findElement(By.tagName("img"));
        
        boolean loaded = (Boolean) ((RemoteWebDriver) driver).executeScript(
                  "return arguments[0].complete", image);
              assertTrue(loaded);
    }
    
    @Test    
    public void testAllImagesLoaded(){
        driver.get("http://www.akc.org/breeds/breeds_a.cfm");
        List<WebElement> allImages = driver.findElements(By.tagName("img"));
        
        for (WebElement image : allImages) {
          boolean loaded = (Boolean) ((RemoteWebDriver) driver).executeScript(
              "return arguments[0].complete", image);
          assertTrue(loaded);
        }        
    }

The first test method checks that the first image tag found is loaded.  The second test loops over all image tags on the page and verifies each one.  This is using the .complete property of a DOM image through Javascript: true if the image is finished loading, false if not.

I haven’t had a chance to play with this much yet.  Please comment with your experience!  Thx!

Posted in NCDevCon, Programming, Selenium | Tagged , , , | Leave a comment

NCDevCon Presentation: Build A Better Functional Test Suite with Selenium WebDriver, JUnit and jQuery

selenium-example-project.zip

Posted in NCDevCon, Selenium | Tagged , , | Leave a comment

Installing Maven Plugin for Eclipse 3.7

Maven is a crazy useful tool for managing dependencies in Java applications. The M2E plug-in can resolve Maven dependencies and project settings inside of Eclipse. The Springsource Tool Suite IDE built on Eclipse includes M2E by default.

My NCDevCon example code (coming soon!) requires use of Maven. This Eclipse plug-in is by far the easiest way to automatically grab dependencies like Selenium 2.x, Spring, and other useful libraries.

Here is how to install the plug-in if your flavor of Eclipse doesn’t already include it.

Open Eclipse
Click on Help menu
Click on “Install New Software…”
For “Work with” combo box, pick “-All Available Sites-”
Type in “maven” in the box labeled “type filter text”
Click ONE of the M2E checkboxes (it might show up in more than one category)
Click Next
Agree to terms
Wait a minute
Restart Eclipse
Done!

That was easy, wasn’t it?

Posted in Eclipse, Java, Selenium | Tagged , , | Leave a comment

Hurricane Sale for NCDevCon – 20 special discounts available

http://ncdevcon.com/post.cfm/hurricane-sale-for-ncdevcon-20-special-discounts-available

At NCDevCon, we want to help you if you have been affected by Hurricane Irene in some way. Thanks to the generosity of our sponsors, we are making available 20 registrations, one for each inch of maximum rain, at 50% off to those who were in Irene’s path. This means you get both days of NCDevCon, along with lunch, T-Shirt and all the other benefits for only $30.

Posted in NCDevCon, Social | Tagged | Leave a comment

I’m Speaking at NCDEVCON

http://ncdevcon.com/

NCDevCon 2011

The Triangle Area ColdFusion User’s Group (TACFUG), associates, and sponsors are organizing the NCDevCon 2011 Conference (NCDevCon)

to be held September 17-18, 2011 on the Centennial Campus of NC State University in Raleigh, North Carolina.

The conference will cover a wide variety of web development and design topics including ColdFusion, Web and Mobile.

Registration for the event will be $60 which includes:

  •  Entry to the weekend event and all presentations
  •  Lunch (both days)
  •  Coffee, drinks and snacks (both days)
  •  Conference shirt

Dates:

September 17 – 18, 2011

Registration:

http://ncdevcon.eventbrite.com/

 

Speaker List

James Brown

  • Building lightning fast mobile & desktop web applications

Tim Cunningham

  • AngluarJS – What HTML would have been if it had been designed for building web applications
  • PDF Black Magic

Oguz Demirkapi

  • Multi lingual applications and i18N and L10N

Shawn Dunning

  • Are QR codes really useful?

Nolan Erck

  • Intro to Model-View-Controllers without a Framework
  • Modularity shoot-out: CFInclude vs CFModule vs Custom Tags, vs CFFunction

Ben Farrell

  • Ben submitted so many cool presentations we’re having trouble picking one. Or two. But he will be there!

Dave Ferguson

  • Application intrusion, detection and tracking

Cole Gillespie

  • jQuery mobile music discovery with the Bandcamp API

David Henry

  • Build a better functional test suite with Selenium RC, JUnit, and jQuery

Doug Hughes

  • Building your first cross platform mobile application

Les James

  • Tame your CSS3 with Sass

Garrett Johnson

  • nodeJS – What is it and why you should care

Michael Kimsal

  • Going solo – Making it as a web freelancer

Brian Klaas

  • Improving application performance with 3 simple functions

Brian Kotek

  • The Swiz Enterprise ActionScript Framework

Sidney Maestre

  • Show me the money with PayPal APIs

Rachel Nabors

  • Comics and Design: How to tell stories with pictures and words

Daria Norris

  • Intro to caching

Birgit Pauli-Haack

  • Beginners’ guide to application load testing

Adrian Pomiliio

  • Flex(ing) with HTML5
  • HTML5 Deep Dive

Andrew Powell

  • Geolocation 101

Anant Pradhan

  • Make your site search-able with CF9 and Solr

Jason Purdy

  • Making cents out of Google Analytics

Dee Sadler

  • Designing for mobile
  • Developing mobile application with Dreamweave and jQuery

Andrew Schwabe

  • Facebook apps with CFML

Bucky Schwarz

  • Writing JavaScript that doesn’t suck

Dan Skaggs

  • OOP: What is it and why should I care?

Bilal Soylu

  • Applied application security
  • Building modern smart phone apps with ColdFusion and Sencha Touch

Denard Springle

  • jQuery, CSS3 and ColdFusion
Posted in jQuery, Main, Selenium, Social | Tagged , , | Leave a comment

Create a .zip or .tar.gz archive in Ubuntu Linux (command line)

With Gnome, this is as easy as opening a file browser > select file(s) > right click > Compress…

Here are the simple cases for the command line.  For many more advanced options, check the man pages for zip and tar.

zip -r my_archive.zip /path/of/files/to/compress/

tar -zcvf my_archive.tar.gz /path/of/files/to/compress/

…and to uncompress an archive on the command line:

unzip my_archive.zip

tar -xvf my_archive.tar.gz

I know this is really basic stuff, right?  Perhaps now that I’ve blogged it I won’t forget again.

Posted in Linux & Friends | Tagged , | Leave a comment

Ajaxily? Ajaxidly? Ajaxifically?

Today I used the word “Ajax” as an adverb with a straight face. Is that bad?

Posted in html/js, jQuery | Tagged , | Leave a comment

Dear Paypal

Dear Paypal,

Please add more informative error messages to your Instant Payment Notification (IPN) Simulator developer tool. The message “IPN delivery failed. Unable to connect to the specified URL. Please verify the URL and try again.” is not sufficient to express that the tool only works on ports 80 and 443. Furthermore it would be nice of you to mention this restriction somewhere in the documentation for IPN. http://myserver.com:8500/paypalIPN.cfm just doesn’t work.

Sincerely,
David Henry

….

Dear Linksys Router, Apache, Tomcat, CF, Railo, and Mura,

I would like to apologize for all of the harsh language, death threats, and curses that I directed at each of you this weekend whilst debugging a site using the PayPal IPN feature. The comments were inappropriate and undeserved. I hope that we can put this behind us and continue forward with our excellent working relationship.

Sincerely,
David Henry

Posted in Programming | Tagged , | Leave a comment

Speling Cownts

Somewhere in the shuffle of upgrading from Ubuntu 10.10 to 11.04 and switching from OpenOffice to LibreOffice I lost/broke my spell check in all programs. No warning, no errors, no indication that I was spelling things ‘creatively’, nothin.

I wonder how many emails I sent with glaring errors in them before I noticed?

To fix:

sudo apt-get install myspell-en-us

Posted in Linux & Friends | Tagged , , , | Leave a comment