SlideShare a Scribd company logo
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 !

More Related Content

What's hot (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
aragozin
 
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 Java
Altoros
 
High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018
Vlad 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 Scalability
ZendCon
 
Woa. Reloaded
Woa. ReloadedWoa. Reloaded
Woa. Reloaded
Emiliano Pecis
 
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
Alex Theedom
 
SQL in the Hybrid World
SQL in the Hybrid WorldSQL in the Hybrid World
SQL in the Hybrid World
Tanel Poder
 
Developing PostgreSQL Performance, Simon Riggs
Developing PostgreSQL Performance, Simon RiggsDeveloping PostgreSQL Performance, Simon Riggs
Developing PostgreSQL Performance, Simon Riggs
Fuenteovejuna
 
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 framework
Felipe
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance Tips
Vlad Mihalcea
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
Chris 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’t
PGConf APAC
 
BDD using JBehave
BDD using JBehaveBDD using JBehave
BDD using JBehave
Ajit Skanda Kumaraswamy
 
Alfresco tuning part2
Alfresco tuning part2Alfresco tuning part2
Alfresco tuning part2
Luis Cabaceira
 
Web api scalability and performance
Web api scalability and performanceWeb api scalability and performance
Web api scalability and performance
Himanshu Desai
 
Java 9 Functionality and Tooling
Java 9 Functionality and ToolingJava 9 Functionality and Tooling
Java 9 Functionality and Tooling
Trisha Gee
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
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
aragozin
 
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 Java
Altoros
 
High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018
Vlad 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 Scalability
ZendCon
 
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
Alex Theedom
 
SQL in the Hybrid World
SQL in the Hybrid WorldSQL in the Hybrid World
SQL in the Hybrid World
Tanel Poder
 
Developing PostgreSQL Performance, Simon Riggs
Developing PostgreSQL Performance, Simon RiggsDeveloping PostgreSQL Performance, Simon Riggs
Developing PostgreSQL Performance, Simon Riggs
Fuenteovejuna
 
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 framework
Felipe
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance Tips
Vlad Mihalcea
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
Chris 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’t
PGConf APAC
 
Web api scalability and performance
Web api scalability and performanceWeb api scalability and performance
Web api scalability and performance
Himanshu Desai
 
Java 9 Functionality and Tooling
Java 9 Functionality and ToolingJava 9 Functionality and Tooling
Java 9 Functionality and Tooling
Trisha Gee
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
Steven Smith
 

Similar to Migration strategies 4 (20)

How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
TEST Huddle
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
Dave 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 Coherence
aragozin
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=Hibernate
Jay 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 Frameworks
Dimitry 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 2014
Red Gate Software
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats 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 Rspec
jeffrey1ross
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
Dave Haeffner
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
Dennis van der Stelt
 
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 Successfully
Dave Haeffner
 
Developers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomonDevelopers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomon
Ineke Scheffers
 
Automated product categorization
Automated product categorization   Automated product categorization
Automated product categorization
Warply
 
Automated product categorization
Automated product categorizationAutomated product categorization
Automated product categorization
Andreas Loupasakis
 
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
Speedment, 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 database
Speedment, Inc.
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
TEST Huddle
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
Dave 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 Coherence
aragozin
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=Hibernate
Jay 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 Frameworks
Dimitry 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 2014
Red Gate Software
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats 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 Rspec
jeffrey1ross
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
Dave 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 Successfully
Dave Haeffner
 
Developers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomonDevelopers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomon
Ineke Scheffers
 
Automated product categorization
Automated product categorization   Automated product categorization
Automated product categorization
Warply
 
Automated product categorization
Automated product categorizationAutomated product categorization
Automated product categorization
Andreas Loupasakis
 
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
Speedment, 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 database
Speedment, Inc.
 

Recently uploaded (20)

How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 

Migration strategies 4

  • 1. Rejuvenate the legacy automation code (Selenium + XPath) in IE Wenhua Wang Senior Software Automation Engineer Marin Software Company Email: [email protected]; [email protected]
  • 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.