SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Rejuvenate the legacy automation code
         (Selenium + XPath) in IE


                       Wenhua Wang
               Senior Software Automation Engineer
                    Marin Software Company
Email: wenhua.wang@marinsoftware.com; wenhua.wang2011@gmail.com
Outline


• Why do we rejuvenate the legacy code ?
   • Requirement changes, e.g., cross browser testing.
   • Limited resources, e.g., budgets.
   • Short release cycles, e.g., agile development.

• How to rejuvenate the legacy code ?
   • Work at the code level.
   • Work at the library level.
• Best practices.
• Q&A
Why rejuvenate the legacy code


• Requirement changes
   • The legacy automation testing code (selenium + XPath)
     was originally developed for regression testing in
     Firefox.
   • Cross browser testing was required, after front end
     updated jQuery (1.7.2).
Our automation testing limitations


• The legacy code can not work in IE.
   • Worked in Firefox 11
   • Worked in Chrome 17
   • Can not work in IE9




•   Automation testing results analysis in IE9:
     •   Tests were failed due to the timeout at the beginning of each test.
         Example: selenium.isElementPresent(“//a[@href=„/campaigns‟]”);

     •   As a result, there was no testing logic exercised at all. The testing
         results can not help us in evaluating the quality of our application.
Develop new automation testing code


• Implement new automation testing code,
   • if you have little legacy code, or
   • if you have enough budgets and time.
• Implementing new automation testing code is not practical
  in Marin, because
   •   Marin has lots of legacy code (invested between 2007 and 2013).
   •   Marin has short release cycles, i.e., release every 4 weeks .
   •   QA has to perform 3300+ tests each regression week.
   •   QA does not have that budget.
                  Table 1. The Legacy Code Statistics in Marin

                  Lines     Branches Methods              Class
                 109,021      23,324       6,325            276
                                              Statistics are from Emma
Reuse the legacy code


• Reusing the legacy code may be a better choice.
   • Software reuse is the most promising strategy for increasing
     productivity and improving quality in the software industry
     (http://en.wikipedia.org/wiki/Code_reuse).


• What we have ?
   • Locators have already been externalized from the testing code.
   • Locators were implemented by XPaths.



              Testing
                                        Locators
               code
Outline


• Why do we rejuvenate the legacy code ?
   • Requirement changes, e.g., cross browser testing.
   • Limited resources, e.g., budgets.
   • Short release cycles, e.g., agile development.

• How to rejuvenate the legacy code ?
   • Work at the code level.
   • Work at the library level.
• Best practices.
• Q&A
Summary


• Migrate XPaths to CSS selectors
  • Blocked by the limitation of CSS selectors.
     • E.g., Can not handle parent elements
  • High workload

• Migrate XPaths to jQuery selectors
  • Solved the limitation of CSS selectors.
  • Still tedious.
• Javascript-xpath library
  • Minimized workload.
How to rejuvenate the legacy code


• Migrate XPaths to CSS selectors.
   •   Better performance and easy to use.
       DOI=http://sauceio.com/index.php/2011/05/why-css-locators-are-the-way-to-go-
       vs-xpath/

   •   Supported by popular browsers, e.g., IE, Firefox, Chrome.


• Map XPaths and CSS selectors.
   •   DOI=http://plasmasturm.org/log/444/
   •   Examples:
        • //a[@id='chartButton'] => a[id='chartButton']
        • //div[@class='container']//a[@class='remove']" =>
          div[class='container'] a[class='remove']“
How to rejuvenate the legacy code


 • Example from Marin
    “LOGOUT_LINK” locator:
    "//a[@href='/index/logout']"; => "a[href='/index/logout']";
    Testing Code:
    selenium.click(AppPage.LOGOUT_LINK);                      Change locators only


                          No need to change the
                              testing code



• Problem: CSS selectors can not handle
  parent elements.
   In Marin, a lot of automation tests locate
   elements through parent elements. As a
   result, migration to CSS was blocked here.
Real life example of using a parent element in locators


selenium.click(gridPage.checkboxByName(“Marin Marketer”));
public String checkboxByName(String name) {
       return   "//a[text()='" + name + "']/../../td/input[@name='id[]']";}
Example of locating elements through parent elements

selenium.click(gridPage.checkboxByName(“Marin Marketer”));
public String checkboxByName(String name) {
         return   "//a[text()='" + name + "']/../../td/input[@name='id[]']";}
Scenario for explaining the logic in the above XPath:
    1.   Locate a link element whose text is “Marin Marketer” in the grid. Name it
         as “MML” in this example.
         XPath: //a[text()=' Marin Marketer ']
    2.   Go to the grand parent of “MML”. Name it as “GP” .
         XPath: //a[text()=' Marin Marketer ']/../..
    3.   Go to the first td child of “GP”. Name it as “first_td” .
         XPath: //a[text()=' Marin Marketer ']/../../td
    4.   Locate the input element of “first_td” with “id[]” name.
         XPath: //a[text()=' Marin Marketer ']/../../td/input[name='id[]']
Address the limitation of CSS selectors


1. Refactor the testing code.
   •   Develop new testing code to move the logic (discussed in slides
       11-12) from the XPath to the testing code. Retire some legacy
       code, as shown in the following.
       selenium.click(gridPage.checkboxByName(“Marin Marketer”));
                                                              Develop new code
       public String checkboxByName(String name) {
         return "//a[text()='" + name + "']/../../td/input[@name='id[]']";}
   •   This strategy downgrades the productivity.               Use new locators

   Our legacy code heavily uses XPath to locate elements through
   parent elements. As a result, this strategy takes much time to change
   our testing code everywhere.
Address the limitation of CSS selectors


2. Use jQuery selectors to handle parent elements, which
   helps control changes in the testing code.
   •    Supported by popular browsers, e.g., IE, Firefox, Chrome.
   •    Easy to handle parent elements.
        •   http://api.jquery.com/category/selectors/


   Pros:
   •   Migrate XPath locators easily.
   •   Effectively control changes in the testing code, compared with
       CSS selectors.
Use jQuery to handle parent elements


Use jQuery to handle the parent element (example in slides 11-12).
Legacy code:
public String checkboxByName(String name) {
return    "//a[text()='" + name + "']/../../td/input[@name='id[]']"; }
New code:
public String checkboxByName(String name) {
return "selenium.browserbot.getCurrentWindow().$("a:contains('"+ name
+"')").parent().parent().children('td:first').children("input[name='id[]']").click()"; }


 The above new jQuery selector has been verified in both selenium and
 the chrome console.
Use jQuery to handle parent elements



Use jQuery to handle the parent element (example in slides 12-13).
Legacy code:
selenium.click(gridPage.checkboxByName(“Marin Marketer”));
New code:
selenium.getEval(gridPage.checkboxByName(“Marin Marketer”));



Cons:
    •   Still taints the testing code a little.
    •   Workload is still high.
        There are 8102 locators to migrate.
Rejuvenate legacy code at library level


• Why work at the library level ?
    • Do not change testing code and locators, which does not require
      development and debugging work.
    • It dramatically reduces the workload.
• Ajaxslt vs Javascript-xpath
   • “Ajaxslt” library is unbearably slow in IE.
    • Cybozu Labs released “Javascript-xpath” library in 2007.
       • “Javascript-xpath” is 5 times faster than “Ajaxslt” in IE8.
       • “Javascript-xpath” is 3 times faster than “Ajaxslt” in Firefox3.
        DOI=http://www.bonitasoft.org/blog/tutorial/how-to-get-faster-selenium-test-cases-
    execution/

• Switch from Ajaxslt to Javascript-xpath
    selenium.start();
    selenium.useXpathLibrary("javascript-xpath");
Ajaxslt vs Javascript-xpath in empirical studies

• Result s from one empirical study:
   • With Firefox 11 browser, “Javascript-xpath” is similar to “Ajaxslt” in
     Marin application.
   • With IE 9 browser, “Javascript-xpath” is 5.08 times faster than
     “Ajaxslt” in Marin application.
                Table 2. Performance comparisons

    Ajaxslt +         Javascript-      Ajaxslt + IE9    Javascript-
    Firefox           xpath+Firefox                     xpath+IE9
    4.46m             4.62m            4 7.34m          9.31m

• Note:
   Ajaxslt + IE9 produced false positives everywhere. We got timeout
   failures at the beginning of each test. It means the testing results is
   useless.
Why explored techniques to minimize code maintenance


• QA delivers quality.
   • Quality is measured by passed tests and failed tests.
   • “Don't Forget: You're A Tester” -- Zac Campbell.
      http://www.meetup.com/seleniumsanfrancisco/events/98453302/

• Coding and debugging is time consuming.
   • It takes time to learn internal knowledge.
   • Tricks are lurking in the legacy code (different publisher
     policies and strict DB policies in our own companies).
   • People are error-prone.
• Save time to do develop new tests.
   • Avoid coding the same tests 2+ times.
Outline


• Why do we rejuvenate the legacy code ?
   • Requirement changes, e.g., cross browser testing.
   • Limited resources, e.g., budgets.
   • Short release cycles, e.g., agile development.

• How to rejuvenate the legacy code ?
   • Work at the code level.
   • Work at the library level.
• Best practices.
• Q&A
Best Practices


• Externalize locators.
   • This decouples the testing logic from web page
     structures.
   • It minimizes the impacts from web page UI changes
     that happen often in reality.
• Simplify locators.
   • Use logic-none locators, like ids and names.
   • Use logic-less locators, like CSS path selectors.
      • In reality, sometimes, there is no id/name or there
        are duplicated ids/names. In this case, we have to
        use path selectors.
      • Use the simplest path selectors, if this happens.
Best Practices


• Develop automation tests with well
  supported techniques.
   • This gives us the flexibility to handle new requirements.
     For example, CSS, jQuery are well supported in various
     browsers. They are good choices for cross-browser
     testing.
• Consider existing resources first, like
  “Javascript-xpath” library.
   • Save a lot of efforts.
   • Reusing existing efforts is critical for the agile
     development.
Thanks !

Contenu connexe

Tendances

High Performance Computing - Cloud Point of View
High Performance Computing - Cloud Point of ViewHigh Performance Computing - Cloud Point of View
High Performance Computing - Cloud Point of Viewaragozin
 
Open Policy Agent for governance as a code
Open Policy Agent for governance as a code Open Policy Agent for governance as a code
Open Policy Agent for governance as a code Alexander Tokarev
 
Casual mass parallel data processing in Java
Casual mass parallel data processing in JavaCasual mass parallel data processing in Java
Casual mass parallel data processing in JavaAltoros
 
High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018Vlad Mihalcea
 
Solving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and ScalabilitySolving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and ScalabilityZendCon
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016Alex Theedom
 
SQL in the Hybrid World
SQL in the Hybrid WorldSQL in the Hybrid World
SQL in the Hybrid WorldTanel Poder
 
Developing PostgreSQL Performance, Simon Riggs
Developing PostgreSQL Performance, Simon RiggsDeveloping PostgreSQL Performance, Simon Riggs
Developing PostgreSQL Performance, Simon RiggsFuenteovejuna
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...Malin Weiss
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]Malin Weiss
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play frameworkFelipe
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsVlad Mihalcea
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql TuningChris Adkin
 
Lessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’tLessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’tPGConf APAC
 
Web api scalability and performance
Web api scalability and performanceWeb api scalability and performance
Web api scalability and performanceHimanshu Desai
 
Java 9 Functionality and Tooling
Java 9 Functionality and ToolingJava 9 Functionality and Tooling
Java 9 Functionality and ToolingTrisha Gee
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 

Tendances (20)

High Performance Computing - Cloud Point of View
High Performance Computing - Cloud Point of ViewHigh Performance Computing - Cloud Point of View
High Performance Computing - Cloud Point of View
 
Open Policy Agent for governance as a code
Open Policy Agent for governance as a code Open Policy Agent for governance as a code
Open Policy Agent for governance as a code
 
Casual mass parallel data processing in Java
Casual mass parallel data processing in JavaCasual mass parallel data processing in Java
Casual mass parallel data processing in Java
 
High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018
 
Solving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and ScalabilitySolving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and Scalability
 
Woa. Reloaded
Woa. ReloadedWoa. Reloaded
Woa. Reloaded
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016
 
SQL in the Hybrid World
SQL in the Hybrid WorldSQL in the Hybrid World
SQL in the Hybrid World
 
Developing PostgreSQL Performance, Simon Riggs
Developing PostgreSQL Performance, Simon RiggsDeveloping PostgreSQL Performance, Simon Riggs
Developing PostgreSQL Performance, Simon Riggs
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance Tips
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
 
Lessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’tLessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’t
 
BDD using JBehave
BDD using JBehaveBDD using JBehave
BDD using JBehave
 
Alfresco tuning part2
Alfresco tuning part2Alfresco tuning part2
Alfresco tuning part2
 
Web api scalability and performance
Web api scalability and performanceWeb api scalability and performance
Web api scalability and performance
 
Java 9 Functionality and Tooling
Java 9 Functionality and ToolingJava 9 Functionality and Tooling
Java 9 Functionality and Tooling
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 

Similaire à Migration strategies 4

How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium SuccessfullyDave Haeffner
 
Performance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle CoherencePerformance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle Coherencearagozin
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=HibernateJay Shah
 
Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)Ryan Cuprak
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Applitools
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksDimitry Polivaev
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...Speedment, Inc.
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Red Gate Software
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchMats Bryntse
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspecjeffrey1ross
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with SeleniumDave Haeffner
 
Untying the Knots of Web Dev with Internet Explorer
Untying the Knots of Web Dev with Internet Explorer Untying the Knots of Web Dev with Internet Explorer
Untying the Knots of Web Dev with Internet Explorer Sarah Dutkiewicz
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium SuccessfullyDave Haeffner
 
Developers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomonDevelopers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomonIneke Scheffers
 
Automated product categorization
Automated product categorizationAutomated product categorization
Automated product categorizationAndreas Loupasakis
 
Automated product categorization
Automated product categorization   Automated product categorization
Automated product categorization Warply
 
How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseSpeedment, Inc.
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSilicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSpeedment, Inc.
 

Similaire à Migration strategies 4 (20)

How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Performance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle CoherencePerformance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle Coherence
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=Hibernate
 
Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source Frameworks
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspec
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
 
Untying the Knots of Web Dev with Internet Explorer
Untying the Knots of Web Dev with Internet Explorer Untying the Knots of Web Dev with Internet Explorer
Untying the Knots of Web Dev with Internet Explorer
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Developers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomonDevelopers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomon
 
Automated product categorization
Automated product categorizationAutomated product categorization
Automated product categorization
 
Automated product categorization
Automated product categorization   Automated product categorization
Automated product categorization
 
How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your database
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSilicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your database
 

Dernier

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Dernier (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Migration strategies 4

  • 1. Rejuvenate the legacy automation code (Selenium + XPath) in IE Wenhua Wang Senior Software Automation Engineer Marin Software Company Email: wenhua.wang@marinsoftware.com; wenhua.wang2011@gmail.com
  • 2. Outline • Why do we rejuvenate the legacy code ? • Requirement changes, e.g., cross browser testing. • Limited resources, e.g., budgets. • Short release cycles, e.g., agile development. • How to rejuvenate the legacy code ? • Work at the code level. • Work at the library level. • Best practices. • Q&A
  • 3. Why rejuvenate the legacy code • Requirement changes • The legacy automation testing code (selenium + XPath) was originally developed for regression testing in Firefox. • Cross browser testing was required, after front end updated jQuery (1.7.2).
  • 4. Our automation testing limitations • The legacy code can not work in IE. • Worked in Firefox 11 • Worked in Chrome 17 • Can not work in IE9 • Automation testing results analysis in IE9: • Tests were failed due to the timeout at the beginning of each test. Example: selenium.isElementPresent(“//a[@href=„/campaigns‟]”); • As a result, there was no testing logic exercised at all. The testing results can not help us in evaluating the quality of our application.
  • 5. Develop new automation testing code • Implement new automation testing code, • if you have little legacy code, or • if you have enough budgets and time. • Implementing new automation testing code is not practical in Marin, because • Marin has lots of legacy code (invested between 2007 and 2013). • Marin has short release cycles, i.e., release every 4 weeks . • QA has to perform 3300+ tests each regression week. • QA does not have that budget. Table 1. The Legacy Code Statistics in Marin Lines Branches Methods Class 109,021 23,324 6,325 276 Statistics are from Emma
  • 6. Reuse the legacy code • Reusing the legacy code may be a better choice. • Software reuse is the most promising strategy for increasing productivity and improving quality in the software industry (http://en.wikipedia.org/wiki/Code_reuse). • What we have ? • Locators have already been externalized from the testing code. • Locators were implemented by XPaths. Testing Locators code
  • 7. Outline • Why do we rejuvenate the legacy code ? • Requirement changes, e.g., cross browser testing. • Limited resources, e.g., budgets. • Short release cycles, e.g., agile development. • How to rejuvenate the legacy code ? • Work at the code level. • Work at the library level. • Best practices. • Q&A
  • 8. Summary • Migrate XPaths to CSS selectors • Blocked by the limitation of CSS selectors. • E.g., Can not handle parent elements • High workload • Migrate XPaths to jQuery selectors • Solved the limitation of CSS selectors. • Still tedious. • Javascript-xpath library • Minimized workload.
  • 9. How to rejuvenate the legacy code • Migrate XPaths to CSS selectors. • Better performance and easy to use. DOI=http://sauceio.com/index.php/2011/05/why-css-locators-are-the-way-to-go- vs-xpath/ • Supported by popular browsers, e.g., IE, Firefox, Chrome. • Map XPaths and CSS selectors. • DOI=http://plasmasturm.org/log/444/ • Examples: • //a[@id='chartButton'] => a[id='chartButton'] • //div[@class='container']//a[@class='remove']" => div[class='container'] a[class='remove']“
  • 10. How to rejuvenate the legacy code • Example from Marin “LOGOUT_LINK” locator: "//a[@href='/index/logout']"; => "a[href='/index/logout']"; Testing Code: selenium.click(AppPage.LOGOUT_LINK); Change locators only No need to change the testing code • Problem: CSS selectors can not handle parent elements. In Marin, a lot of automation tests locate elements through parent elements. As a result, migration to CSS was blocked here.
  • 11. Real life example of using a parent element in locators selenium.click(gridPage.checkboxByName(“Marin Marketer”)); public String checkboxByName(String name) { return "//a[text()='" + name + "']/../../td/input[@name='id[]']";}
  • 12. Example of locating elements through parent elements selenium.click(gridPage.checkboxByName(“Marin Marketer”)); public String checkboxByName(String name) { return "//a[text()='" + name + "']/../../td/input[@name='id[]']";} Scenario for explaining the logic in the above XPath: 1. Locate a link element whose text is “Marin Marketer” in the grid. Name it as “MML” in this example. XPath: //a[text()=' Marin Marketer '] 2. Go to the grand parent of “MML”. Name it as “GP” . XPath: //a[text()=' Marin Marketer ']/../.. 3. Go to the first td child of “GP”. Name it as “first_td” . XPath: //a[text()=' Marin Marketer ']/../../td 4. Locate the input element of “first_td” with “id[]” name. XPath: //a[text()=' Marin Marketer ']/../../td/input[name='id[]']
  • 13. Address the limitation of CSS selectors 1. Refactor the testing code. • Develop new testing code to move the logic (discussed in slides 11-12) from the XPath to the testing code. Retire some legacy code, as shown in the following. selenium.click(gridPage.checkboxByName(“Marin Marketer”)); Develop new code public String checkboxByName(String name) { return "//a[text()='" + name + "']/../../td/input[@name='id[]']";} • This strategy downgrades the productivity. Use new locators Our legacy code heavily uses XPath to locate elements through parent elements. As a result, this strategy takes much time to change our testing code everywhere.
  • 14. Address the limitation of CSS selectors 2. Use jQuery selectors to handle parent elements, which helps control changes in the testing code. • Supported by popular browsers, e.g., IE, Firefox, Chrome. • Easy to handle parent elements. • http://api.jquery.com/category/selectors/ Pros: • Migrate XPath locators easily. • Effectively control changes in the testing code, compared with CSS selectors.
  • 15. Use jQuery to handle parent elements Use jQuery to handle the parent element (example in slides 11-12). Legacy code: public String checkboxByName(String name) { return "//a[text()='" + name + "']/../../td/input[@name='id[]']"; } New code: public String checkboxByName(String name) { return "selenium.browserbot.getCurrentWindow().$("a:contains('"+ name +"')").parent().parent().children('td:first').children("input[name='id[]']").click()"; } The above new jQuery selector has been verified in both selenium and the chrome console.
  • 16. Use jQuery to handle parent elements Use jQuery to handle the parent element (example in slides 12-13). Legacy code: selenium.click(gridPage.checkboxByName(“Marin Marketer”)); New code: selenium.getEval(gridPage.checkboxByName(“Marin Marketer”)); Cons: • Still taints the testing code a little. • Workload is still high. There are 8102 locators to migrate.
  • 17. Rejuvenate legacy code at library level • Why work at the library level ? • Do not change testing code and locators, which does not require development and debugging work. • It dramatically reduces the workload. • Ajaxslt vs Javascript-xpath • “Ajaxslt” library is unbearably slow in IE. • Cybozu Labs released “Javascript-xpath” library in 2007. • “Javascript-xpath” is 5 times faster than “Ajaxslt” in IE8. • “Javascript-xpath” is 3 times faster than “Ajaxslt” in Firefox3. DOI=http://www.bonitasoft.org/blog/tutorial/how-to-get-faster-selenium-test-cases- execution/ • Switch from Ajaxslt to Javascript-xpath selenium.start(); selenium.useXpathLibrary("javascript-xpath");
  • 18. Ajaxslt vs Javascript-xpath in empirical studies • Result s from one empirical study: • With Firefox 11 browser, “Javascript-xpath” is similar to “Ajaxslt” in Marin application. • With IE 9 browser, “Javascript-xpath” is 5.08 times faster than “Ajaxslt” in Marin application. Table 2. Performance comparisons Ajaxslt + Javascript- Ajaxslt + IE9 Javascript- Firefox xpath+Firefox xpath+IE9 4.46m 4.62m 4 7.34m 9.31m • Note: Ajaxslt + IE9 produced false positives everywhere. We got timeout failures at the beginning of each test. It means the testing results is useless.
  • 19. Why explored techniques to minimize code maintenance • QA delivers quality. • Quality is measured by passed tests and failed tests. • “Don't Forget: You're A Tester” -- Zac Campbell. http://www.meetup.com/seleniumsanfrancisco/events/98453302/ • Coding and debugging is time consuming. • It takes time to learn internal knowledge. • Tricks are lurking in the legacy code (different publisher policies and strict DB policies in our own companies). • People are error-prone. • Save time to do develop new tests. • Avoid coding the same tests 2+ times.
  • 20. Outline • Why do we rejuvenate the legacy code ? • Requirement changes, e.g., cross browser testing. • Limited resources, e.g., budgets. • Short release cycles, e.g., agile development. • How to rejuvenate the legacy code ? • Work at the code level. • Work at the library level. • Best practices. • Q&A
  • 21. Best Practices • Externalize locators. • This decouples the testing logic from web page structures. • It minimizes the impacts from web page UI changes that happen often in reality. • Simplify locators. • Use logic-none locators, like ids and names. • Use logic-less locators, like CSS path selectors. • In reality, sometimes, there is no id/name or there are duplicated ids/names. In this case, we have to use path selectors. • Use the simplest path selectors, if this happens.
  • 22. Best Practices • Develop automation tests with well supported techniques. • This gives us the flexibility to handle new requirements. For example, CSS, jQuery are well supported in various browsers. They are good choices for cross-browser testing. • Consider existing resources first, like “Javascript-xpath” library. • Save a lot of efforts. • Reusing existing efforts is critical for the agile development.