Automated integration tests forAJAX applicationsOverviewDEVELOPER GARAGE 2012April 17, Nizhny Novgorod
Justification Who is part of development team?Who is using … automated integration (functional) testing unit-testing m...
Agenda•Motivation•Challenges•Solutions & tricks•Experience•Conclusion                      3
Motivation – goals•Reliability of the product at any moment•Less time for bugs – more time for development•Feel free to ad...
Motivation – issues•Manual testing is slow•Hard to determine guilty commit                                   5
Reliability at any momentWorst case is:The goal is:                             6
Automated tests for AJAX    web-applications                           7
Challenges - I•Recent framework compared to unit testing•Full-featured container required•New approach (API)•Lack of tools...
Challenges - II•Asynchronous behavior•Tricky to configure Hudson/Jenkins•Complicated staging environment configuration•Lac...
SolutionsChallenges• Recent framework compared to unit testing• Tricky to configure Hudson/Jenkins• Lack of experienced QA...
SolutionsChallenges• Complicated staging environment configurationSolution• Test driven application architecture – plannin...
SolutionsChallenge•Requires full-featured container•Requires new approach (API)Solution•Use Selenium, jWebUnit            ...
SolutionsChallenge Tools… Just few of themSolution jWebUnit  −In case of simple ajax  −Turn off javascript if not needed...
SolutionsChallenge• Relatively faster, but… relatively slowSolution• Still much faster than manual tests• Define AllInOne ...
SolutionsChallenge• Hard to determine guilty commit• Intend to add new features safelySolution• Test all before commit- or...
SolutionsChallenge•Asynchronous behaviorSolution•Use wait() approach•Use Thread.sleep() after each action•Be aware of DOM ...
ExperienceOur experience with AJAX apps testing:•GWT application (100% AJAX) •GWTTestCase is not recommended for  function...
The architecture                            Server-side running in                              test environment          ...
Source code example (jWebUnit) – 1/3public class TestShoppingCart extends BaseTest {  @Test  public void test() {    begin...
Source code example (jWebUnit) – 2/3public class TestShoppingCart extends BaseTest {  @Test  public void test() {    begin...
Source code example (jWebUnit) – 3/3public class TestShoppingCart extends BaseTest {  @Test  public void test() {    begin...
Source code example (Selenium) – 1/2public class TestManageChart extends CatalogMerchTestBase {    @Test    public void te...
Source code example (Selenium) – 2/2public class TestManageChart extends CatalogMerchTestBase {    @Test    public void te...
ExperienceTime spent. Grouped by task type25201510                                   Before  5                            ...
Conclusion & QuestionsIt’s functional testingIt’s worth it!Note:Write code with low TCO!Perform code review!Don’t let...
Auriga At a Glance World leader in R&D outsourcing    - #1 Engineering Services Outsourcing (ESO) provider    - #15 in To...
Contacts              Thank You!      Sergey.Karpushin@auriga.com                                    27
Upcoming SlideShare
Loading in …5
×

Automated integration tests for ajax applications (с. карпушин, auriga)

1,027 views
902 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,027
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Automated integration tests for ajax applications (с. карпушин, auriga)

  1. 1. Automated integration tests forAJAX applicationsOverviewDEVELOPER GARAGE 2012April 17, Nizhny Novgorod
  2. 2. Justification Who is part of development team?Who is using … automated integration (functional) testing unit-testing manual testing… to track quality? Why or how? 2
  3. 3. Agenda•Motivation•Challenges•Solutions & tricks•Experience•Conclusion 3
  4. 4. Motivation – goals•Reliability of the product at any moment•Less time for bugs – more time for development•Feel free to add new features – it’s safe 4
  5. 5. Motivation – issues•Manual testing is slow•Hard to determine guilty commit 5
  6. 6. Reliability at any momentWorst case is:The goal is: 6
  7. 7. Automated tests for AJAX web-applications 7
  8. 8. Challenges - I•Recent framework compared to unit testing•Full-featured container required•New approach (API)•Lack of tools•Relatively faster, but …. relatively slow 8
  9. 9. Challenges - II•Asynchronous behavior•Tricky to configure Hudson/Jenkins•Complicated staging environment configuration•Lack of experienced QA engineers 9
  10. 10. SolutionsChallenges• Recent framework compared to unit testing• Tricky to configure Hudson/Jenkins• Lack of experienced QA engineersSolution• Well… Everything happens for the first time• Research, study and teach 10
  11. 11. SolutionsChallenges• Complicated staging environment configurationSolution• Test driven application architecture – planning in advance is a key• Use IoC based approach for applications 11
  12. 12. SolutionsChallenge•Requires full-featured container•Requires new approach (API)Solution•Use Selenium, jWebUnit 12
  13. 13. SolutionsChallenge Tools… Just few of themSolution jWebUnit −In case of simple ajax −Turn off javascript if not needed (save 30 seconds) Selenium −Need to control items visibility −Need to test against real browser 13
  14. 14. SolutionsChallenge• Relatively faster, but… relatively slowSolution• Still much faster than manual tests• Define AllInOne suite for quick check• Run full set of tests on CI• Use distributed technologies (i.e. Selenium Grid) 14
  15. 15. SolutionsChallenge• Hard to determine guilty commit• Intend to add new features safelySolution• Test all before commit- or at least -• Email notification from CI that commit produced regression 15
  16. 16. SolutionsChallenge•Asynchronous behaviorSolution•Use wait() approach•Use Thread.sleep() after each action•Be aware of DOM inconsistency 16
  17. 17. ExperienceOur experience with AJAX apps testing:•GWT application (100% AJAX) •GWTTestCase is not recommended for functional testing•Regular WEB 2.0 application 17
  18. 18. The architecture Server-side running in test environment AJAX Test Cases HTML + JavaScript container Test Cases Test Case running client-side jUnit-style tests Selenium, jWebUnit 18
  19. 19. Source code example (jWebUnit) – 1/3public class TestShoppingCart extends BaseTest { @Test public void test() { beginAt("/cart/index"); tester.assertTextPresent("Your cart is empty."); tester.setScriptingEnabled(true); beginAt("/album/list?sort=albumName&max=20"); tester.assertElementPresentByXPath("//div[@class=list]"); tester.assertElementPresentByXPath("//div[@id=‘c and .=0 items]"); tester.clickElementByXPath("//div[@class=album-buy]/input[contains(@value,Buy Album)]"); tester.assertElementPresentByXPath("//div[@id=‘c and .=1 item]"); tester.clickElementByXPath("//div[@id=cart]//a"); tester.assertElementPresentByXPath("//div[@id=ribbon-single-line]/h1[contains(., Shopping Cart)]"); 19
  20. 20. Source code example (jWebUnit) – 2/3public class TestShoppingCart extends BaseTest { @Test public void test() { beginAt("/cart/index"); tester.assertTextPresent("Your cart is empty."); tester.setScriptingEnabled(true); beginAt("/album/list?sort=albumName&max=20"); tester.assertElementPresentByXPath("//div[@class=list]"); tester.assertElementPresentByXPath("//div[@id=‘c and .=0 items]"); tester.clickElementByXPath("//div[@class=album-buy]/input[contains(@value,Buy Album)]"); tester.assertElementPresentByXPath("//div[@id=‘c and .=1 item]"); tester.clickElementByXPath("//div[@id=cart]//a"); tester.assertElementPresentByXPath("//div[@id=ribbon-single-line]/h1[contains(., Shopping Cart)]"); 20
  21. 21. Source code example (jWebUnit) – 3/3public class TestShoppingCart extends BaseTest { @Test public void test() { beginAt("/cart/index"); tester.assertTextPresent("Your cart is empty."); tester.setScriptingEnabled(true); beginAt("/album/list?sort=albumName&max=20"); tester.assertElementPresentByXPath("//div[@class=list]"); tester.assertElementPresentByXPath("//div[@id=‘c and .=0 items]"); tester.clickElementByXPath("//div[@class=album-buy]/input[contains(@value,Buy Album)]"); tester.assertElementPresentByXPath("//div[@id=‘c and .=1 item]"); tester.clickElementByXPath("//div[@id=cart]//a"); tester.assertElementPresentByXPath("//div[@id=ribbon-single-line]/h1[contains(., Shopping Cart)]"); 21
  22. 22. Source code example (Selenium) – 1/2public class TestManageChart extends CatalogMerchTestBase { @Test public void testManageChart() throws Throwable { driver.get(baseUrl + "#top.store[1].manage_charts"); waitV("btn-add-chart”); WebElement elm = driver.findElement(By.id("btn-add-chart")); click(elm); Alert alert = getAlert(); alert.sendKeys(newChartName); alert.dismiss(); waitInvAjax(); 22
  23. 23. Source code example (Selenium) – 2/2public class TestManageChart extends CatalogMerchTestBase { @Test public void testManageChart() throws Throwable { driver.get(baseUrl + "#top.store[1].manage_charts"); waitV("btn-add-chart"); WebElement elm = driver.findElement(By.id("btn-add-chart")); click(elm); Alert alert = getAlert(); alert.sendKeys(newChartName); alert.dismiss(); waitInvAjax(); 23
  24. 24. ExperienceTime spent. Grouped by task type25201510 Before 5 After 0 24
  25. 25. Conclusion & QuestionsIt’s functional testingIt’s worth it!Note:Write code with low TCO!Perform code review!Don’t let user story overstep the sprint! 25
  26. 26. Auriga At a Glance World leader in R&D outsourcing - #1 Engineering Services Outsourcing (ESO) provider - #15 in Top-20 Global Outsourcing Vendors - Global Services 100 and Global Outsourcing 100 company - Top 10 Offshore Eastern and Central Europe - Top 10 Software R&D Service Providers In business since 1990 - First in Russia to do offshore software services 300 employees Headquartered in the U.S. - Incorporated in the U.S. in 1993 Engineering centers in - Russia: Moscow, Nizhny Novgorod, Rostov-on-Don - EU: Vilnius, Lithuania Main Domains: Technologies and Verticals - System Level, Embedded - Technology (s/w and h/w) - Mobile - Finance - Document Management - Healthcare - Portals - Telecom - Social Web - Logistics - Media and Web - Government - Security 26
  27. 27. Contacts Thank You! Sergey.Karpushin@auriga.com 27

×