FluentSelenium Presentation Code Camp09

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    FluentSelenium Presentation Code Camp09 - Presentation Transcript

    1. Les DSL et "fluent interface" pour les tests ASP.NET avec Selenium FluentSelenium
    2. Content
      • Selenium and XPATH
      • Best practices for testing
      • FluentSelenium
      • Conclusion
    3. Selenium introduction Selenium is a suite of tools to automate web app testing across many platforms
      • It is developed by ThoughtWorks and is available as an open source project
      • It includes
        • Selenium IDE : Firefox add-on that records clicks, typing, and other actions to make a test, witch you can play back in the browser
        • Selenium Remote Control : Run your tests in multiple browsers and platforms. Tweak your tests in your prefered language (C#, Java, Perl, PHP, Python or Ruby)
      • Uses XPATH as its web query language
    4. Here's a web test written with selenium selenium.Open( "Forum/AllPosts.aspx" ); selenium.WaitForPageToLoad( "8000" ); selenium.Click( "newPost" ); selenium.WaitForPageToLoad( "8000" ); selenium.Type( "//*[contains(@id, 'txtAuthor')]" , "Luc" ); selenium.Type( "//*[contains(@id, 'txtSubject')]" , "Simple example of the library." ); selenium.Click( "//*[contains(@id, 'btnSavePost')]" ); selenium.WaitForPageToLoad( "8000" ); Assert .AreEqual( "Luc" , selenium.GetText( "//table[contains(@id, 'grdPosts')]//tr[2]/td[2]" ));
    5. Xpath introduction XPath is a structred XML query language Example : get the node of the employee with ID 123456 Employees/Employee[@EmployeeID='123456'] < Employees > < Employee EmployeeID = &quot; 123456 &quot; > < LastName > Laporte </ LastName > < FirstName > Jacques </ FirstName > </ Employee > < Employee EmployeeID = &quot; 654321 &quot; > < LastName > Gendron </ LastName > < FirstName > Pierre </ FirstName > </ Employee > </ Employees >
    6. Xpath introduction XPath is a structred XML query language Example : get the last name of the employee with ID 123456 : Employees/Employee[@EmployeeID='123456']/LastName < Employees > < Employee EmployeeID = &quot; 123456 &quot; > < LastName > Laporte </ LastName > < FirstName > Jacques </ FirstName > </ Employee > < Employee EmployeeID = &quot; 654321 &quot; > < LastName > Gendron </ LastName > < FirstName > Pierre </ FirstName > </ Employee > </ Employees >
    7. Selenium and XPath on HTML Because HTML is an XML derivative, XPath can be used to locate nodes in a HTML web page Example : ask selenium to click on the Save button : selenium.Click(“//input[@id='btnSubmit']”); selenium.WaitForPageToLoad(“5000”); < html > < body > < form > < div >Hello World !</ div > < input type = &quot; submit &quot; value = &quot; Save &quot; id = &quot; btnSubmit &quot; /> </ form > </ body > </ html >
    8. Complete simple web test with selenium
    9. Content
      • Selenium and XPATH
      • Best practices for testing
      • FluentSelenium
      • Conclusion
    10. Good testing practices
      • Test coverage
      • Test independance
      • Test clarity
    11. Test coverage Should we aim for 100% coverage?
    12. The trade offs
    13. What does this mean? Integrated tests Unit tests Test coverage
    14. Best practices of test coverage
      • Web tests are not cheap to write, maintain, or execute, don't strive for high coverage unless you need it
      • Favor coverage through testing of services and domain objects over UI testing
      • Use patterns that facilitate testing close to the UI layer such as MVC
      • Aim for coverage that gives you confidence in the quality of your deliverables
      • Test independance
      Keep tests independent because:
      • They will be easier to fix
      • They will be easier to read
      • They will not be impacted by updates in other tests
    15. Some things to consider...
      • For better independance consider using easily rebuildable dependencies:
        • Web server: Cassini
        • Database: Sqlite
      • For etxternal dependencies that cannot be relied on to be performant or predictable consider using a fake implementation.
    16. Test Clarity
      • Tests need to be easy to read because they need to be maintained.
      • Tests are code also. Team code quality rules should also be applied to tests.
    17. XPATH is dangerous, use it wisely Use ID-based queries when possible //*[@id = 'searchResultCount']
    18. Avoid exessive XPATH steps When requiring further qualification in searches only add necessary qualifiers Favor //*[@id='searchResults']//li[1] Over /html/body//div[@id='searchResults']/ul/li[1]
    19. XPATH queries are not clear Xpath expressions are the kind of literal who's meaning can be hard to decipher. Use constants. Favor selenium.GetText(SearchResultSummaryLocator); Over selenium.GetText( &quot;//*[@id='searchResultsSummary']&quot; );
    20. Keep the test code clean
      • Always revise the tests for clarity.
      • Hard to read tests are hard maintain
      • Tests serve as application behavior documentation
    21. The importance of language in tests
        Who needs to understand your tests?
      • Know your target audience
      • Developers
      • Users
      • Testers
      • Technical writers
      Write tests in your audiences language!
      • Use the appropriate level of abstraction
      • Unit tests
        • language of the code being tested
      • Integration tests
        • Language of the highest level of abstraction being tested
      • End-to-end tests
        • Users
        • Other actors (systems and services)
    22. So what are DSLs? Domain-specific languages – are any language (API, programming or written) that uses a domain oriented terminology.
      • Nunit and MSTest use a test DSL
      • Nhibernate and Linq use query oriented languages
      • Users speak in the language of their needs and tasks
      • Programmers tend to speak in terms of technical jargon
      In code this translates to the choice vocabulary used in class, method and variable names. Tests should use a DSL appropriate to the end user.
    23. Content
      • Selenium and XPATH
      • Best practices for testing
      • FluentSelenium
      • Conclusion
    24. Our solution FluentSelenium
    25. Some examples shopper.Goto( &quot;Shopping/ShopOnline.aspx&quot; ); shopper.For(WelcomeMessageBox).ShouldSee( &quot;Welcome to Shop-e online!&quot; ); shopper.ShouldSee(FeaturedProductArea); shopper.For(FeaturedProductTitle).ShouldSee( &quot;blank CDs (10)&quot; ); shopper.For(FeaturedProductUnitePriceField).ShouldSee( &quot;5.00$&quot; );
    26. selenium.Open( &quot;Shopping/ShopOnline.aspx&quot; ); selenium.WaitForPageToLoad( &quot;1000&quot; ); Assert .AreEqual( &quot;Welcome to Shop-e online!&quot; , selenium.GetText( &quot;welcome&quot; )); Assert .IsTrue(selenium.IsVisible( &quot;featuredProduct&quot; )); Assert .AreEqual( &quot;blank CDs (10)&quot; , selenium.GetText( &quot;//*[@id='featuredProduct']//*[@id='title']&quot; )); Assert .AreEqual( &quot;5,00$&quot; , selenium.GetText( &quot;//*[@id='featuredProduct']//*[@id='price']&quot; ));
    27. ... forumUser.Goto( &quot;Forum/AllPosts.aspx&quot; ); forumUser.For(addPostButton).Clicks(); forumUser.WaitFor(newPostPageLoadWait); forumUser.For(subjectTextBox).Enters( &quot;Simple example of the library.&quot; ); forumUser.For(messagetTextBox).Enters( &quot;blah&quot; ); forumUser.For(savePostButton).Clicks(); forumUser.For(authorRequiredMessage).ShouldSee( &quot;The author is required.&quot; );
    28. The User The User class is the root of the DSL. All web test operations spawn from it. It is initialized as follows: var selenium = new DefaultSelenium (....); var forumUser = new User (selenium); Variables of type User should be named according to the role of the application user.
    29. Pushing XPATH out of the tests FluentSelenium uses typed locator objects ElementLocator WelcomeMessageBox = ElementLocator .WithId( &quot;welcome&quot; ); InputLocator SearchCatalogText = InputLocator .WithId( &quot;searchText&quot; ); ButtonLocator SearchCatalogButton = ButtonLocator .WithId( &quot;searchButton&quot; ); ElementLocator FeaturedProductTitle = ElementLocator .WithXpath( &quot;//*[@id='featuredProduct']//*[@id='title']&quot; ); Locator types determine what operations are available with a “For” shopper.For(SearchCatalogText).Enters( &quot;mouse&quot; ); shopper.For(SearchCatalogButton).Clicks();
    30. Application navigation Navigating to a specific address: goto shopper.Goto( &quot;Shopping/ShopOnline.aspx&quot; ); Navigating by clicking on links and buttons: click shopper.For(DiscountsButton).Clicks(); Waiting for page loading: WaitFor PageLoadWaitCondition SearchResultPageLoad = PageLoadWaitCondition .For( &quot;Shopping/SearchResults.aspx&quot; ); shopper.WaitFor(SearchResultPageLoad); Waiting for special conditions can be done by writing a custom implementation of IWaitCondition
    31. Validating page content Presence or absence of an element shopper.ShouldSee(WelcomeMessageBox); shopper.ShouldNotSee(SearchResults); Content of an page element shopper.For(SearchResultsSummary).ShouldSee( &quot;1 match found&quot; ); Custom validation, any implementation of IContentValidator class AnyNumberValidator : IContentValidator { public void Validate( ContentTester contentTester) .... shopper.For(OrderNumber).ShouldSee(AnyNumber);
    32. Testing table content Testing the content of a table row f orumUser.For(allPostsTable).Row(2).ShouldSee( &quot;Luc&quot; , &quot;Hello&quot; ); Jim Nothing Luc Hello Bob Goodbye Testing the content of a table column forumUser.For(allPostsTable).Column(1).ShouldSee( &quot;Jim&quot;, &quot;Luc&quot;, “Bob” ); Jim Nothing Luc Hello Bob Goodbye
    33. Other table operations Checking cell content forumUser.For(allPostsTable).Row(2).Column(3).ShouldSee( &quot;Present&quot; ); Cells have content forumUser.For(allPostsTable).Row(2).Column(3).For(replyPostButton).Click();
    34. Extending Custom implementations:
        • Synchronization conditions with IWaitCondition
        • Custom content validation with IContentValidator
      Extending the User
        • Extend User and add new test methods
        • Use extension methods to add test methods to the User class
    35. Content
      • Selenium and XPATH
      • Best practices for testing
      • FluentSelenium
      • Conclusion
    36. FluentSelenium is...
      • A new open source project hosted on codeplex. You can download the source or contribute by visiting http://fluentselenium.codeplex.com
      • A simplified spin off of a framework developed for one of our clients. We expect to extend it with ideas and concepts that aren't yet implemented
      • A work in progress
      • A facilitator, not a solution
    37. Links of interest
      • http://www.pyxis-tech.com
      • http://seleniumhq.org
      • http://fluentselenium.codeplex.com
    38. Conclusions Questions?
    SlideShare Zeitgeist 2009

    + Pyxis TechnologiesPyxis Technologies Nominate

    custom

    74 views, 0 favs, 0 embeds more stats

    These are the slides we presented at the 2009 Montr more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 74
      • 74 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories