Showing posts with label WTFramework. Show all posts
Showing posts with label WTFramework. Show all posts

Monday, July 8, 2013

Changing a bit of unittests around the WTF project

Just a short update on WTF.  I've been updating the automated tests on the WTFramework project.  I'm pretty excited in getting CI up and running for WTF all out in the open.  You'll probably noticed, I've recently got WTF on Travis-CI running all it's integration tests upon every push.

Also, under the hood, I have changed the test case base to Unittest2, and Nose2 as the test runner.  I feel this will make it more extensible for Python 2.7+ users going forward.  It'll allow you to use various Nose2 plugins, and Unittest2 goodies.

I've also changed the Mocking framework from Mox to Mockito. I feel Mox causes too much implementation level dependencies with it's syntax of having to pass not only the expected returns, but also the expected order of the calls and number of times it needs to get called.  This creations a situation where my unit test will need to know what's going on under the hood, which sort of kills off a true TDD workflow.  Not having to worry about the order of my calls and how many times things get called allows my unit test to be less dependent on the underlying implementation.

You'll probably start seeing code that's tested by the new changes in WTF versions 0.2.25 and up.  If you're forking the WTF code, you can see these cool green checkmarks on the branches page to see which branches are safe for pulling.




Saturday, March 23, 2013

3 Useful Techniques to shortening your xpath

I recently added a new feature to the WTF chrome extension to allows your to check your mapped PageObject elements by highlighting it on the screen when you click on the 'check' button.  It's a very useful tool for optimizing your css and xpath expressions.


For this blog post, I thought I'd like to take some time to go over how you can simplify your XPath web element selectors.  I'll cover simplifying CSS selectors in a future post.

If you used some sort of xpath finder tool, you'll probably realize that you'll get a very index heavy detailed xpath.  For example, the below xpath expression is the generated output of the WTF tool while mapping the git URL read only input box on this page https://github.com/wiredrive/wtframework. The below xpath is not idea since it is very brittle and highly dependent on the element's parent hierarchy.
/html/body/div/div[2]/div/div/div/div[2]/div[4]/div/span[4]/input
We'll go over 3 things you can do to shorten and make your xpath expressions more robust.

3 Useful Xpath techniques

Using '//' to do a deep find.

The '//' operator in XPath is your friend in simplifying your XPath.  The '//' will perform a deep find for the next element.  You'll find this useful for searching through things that can be many levels deep, which will let you decouple finding your element from it's parent elements.

Using contains() within a property selector

Next thing is the '[' and ']'.  Besides allowing you to select an index, it also allows you to select on any attribute of that tag.  For example "//*[@id='searchButton']" will find an element with ID search button.  In combination with the '//' operator, the '[...]' will allow you to filter down your elements quickly.

Inside the '[...]',  we have the 'contains()' xpath function.  This is a standard xpath function most browsers support, and will allow you to do a search within that element's attribute, which you can denote by using the '@' sign.

The '..' parent selector

Finally, the we have the '..' selector.  This allows you to select a parent element.  This is very useful for selecting elements that do not have unique identifiers, but are located near something that is.

For example, let's say I wanted to select this folder icon that's next to 'bin' that really has no unique properties.



But we do know that the 'bin' link next to that icon has a unique title.


A cool trick we can do here is to first do a deep find to select the link, then traverse up 2 parents so we select the the row (<tr>).  From there we can do a deep find to find the icon inside that row.

//a[@title='bin']/../..//*[contains(@class, 'mini-icon-directory')]"

Conclusion

Between those 3 techniques, you'll find you can shorten most xpath, make them easier to understand, and make them less brittle to site structure changes.

There are many other useful methods for shorting xpath.  I'd recommend reading over them to see what's available.  http://www.w3schools.com/xpath/xpath_functions.asp

Thursday, March 7, 2013

Major Overhaul of WTF

When I started writing WTF I was a beginner in Python, so I followed a lot of Java programming practices.  Now that I have a better grasp of Python, I'm planning a major refactor of WTF.  I'd like to bring the naming in line, and using what I know about default parameters, to simplify a lot of the classes.

This will break a lot of tests for current users of WTF, I'll have to apologize for not studying the language in depth from the get go.  I hope you can bare with me, it'll be much more consistent with how other frameworks are written when I'm done.

I see this as an opportunity to really test out the development and branching strategy.  While I'm doing a massive refactor of WTF at home, I'm still consuming WTF at work and making changes from there as well to the old code base.  As many of the things will be changing around, I think I'll be able to put the Git Flow model of branching through some serious experimenting as I tackle the merge issues.

Sunday, February 24, 2013

Sneak peak at the WTF chrome extension

Update 2012-02-28: The chrome plugin is now released.  You can find it by downloading/cloning the latest version of WTFramework. https://github.com/wiredrive/wtframework

Here's a sneak peek at the WTF chrome extension I'm working on.    It'll provide an easy way for chrome users to generate some PageObject template code compatible with the WTFramework.  Users could use this page to quickly create a PageObject, pick their page validation method, and select the elements on the page they wish to have mapped to their page object.



Thursday, February 7, 2013

WTF is now open source!

I'm happy to announce that Web Test Framework, WTF, is now open source.  You can find the source and installation instructions here:

https://github.com/wiredrive/wtframework

I've taken a lot of product agnostic framework code I've been working on the last couple months and separated it out from  our test scripts into a reusable framework.  I hope that by doing this, we could take web testing into a structured approach with easy to use generators and integrated tools like how various MVC frameworks like Rails and Django have revolutionized web development.

Please check it out and let me know what you think.  I'll be working on trying to get this framework documented and making it more user friendly.