Design patterns in automated testing

Slides:



Advertisements
Similar presentations
In-Box A/R As Of. In-Box VBS Menu WMN2001S Page 2.
Advertisements

1
Feichter_DPG-SYKL03_Bild-01. Feichter_DPG-SYKL03_Bild-02.
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (Parallel Algorithms) Robin Pomplun.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
RXQ Customer Enrollment Using a Registration Agent (RA) Process Flow Diagram (Move-In) Customer Supplier Customer authorizes Enrollment ( )
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination. Introduction to the Business.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
We need a common denominator to add these fractions.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
Create an Application Title 1A - Adult Chapter 3.
Process a Customer Chapter 2. Process a Customer 2-2 Objectives Understand what defines a Customer Learn how to check for an existing Customer Learn how.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 10 second questions
Rhesy S.ppt proRheo GmbH
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Week 2 The Object-Oriented Approach to Requirements
Anything But Typical Learning to Love JavaScript Prototypes Page 1 © 2010 Razorfish. All rights reserved. Dan Nichols March 14, 2010.
1 Refactoring with Contracts Shmuel Tyszberowicz School of Computer Science The Academic College of Tel Aviv Yaffo Maayan Goldstein School of Computer.
PP Test Review Sections 6-1 to 6-6
NI LabVIEW Object-Oriented Programming
EU market situation for eggs and poultry Management Committee 20 October 2011.
Bright Futures Guidelines Priorities and Screening Tables
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
CS 6143 COMPUTER ARCHITECTURE II SPRING 2014 ACM Principles and Practice of Parallel Programming, PPoPP, 2006 Panel Presentations Parallel Processing is.
2 |SharePoint Saturday New York City
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
VOORBLAD.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Sample Service Screenshots Enterprise Cloud Service 11.3.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Adding Up In Chunks.
Chapter 10 Software Testing
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Note to the teacher: Was 28. A. to B. you C. said D. on Note to the teacher: Make this slide correct answer be C and sound to be “said”. to said you on.
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Analyzing Genes and Genomes
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Energy Generation in Mitochondria and Chlorplasts

Presentation transcript:

Design patterns in automated testing Bindu Laxminarayan bindu@hexbytes.com

Design Patterns in Automated Testing Test Automation Design Patterns Zen Cart Shopping Application Component Pattern Template Design Pattern Domain Test Object Pattern Page Object Pattern References Questions Design Patterns in Automated Testing

Test Automation Test automation is the use of software to control the execution of tests, the comparison of actual outcomes to predicted outcomes, the setting up of test preconditions, and other test control and test reporting functions. -Wikipedia How is automation different for each level. Design Patterns in Automated Testing

Levels And Common problems Types/Levels of Automation: Unit Integration UI Automation Service Level(Web Services) Common Issues Maintainability Reusability Availability of Time Reliability Modularization Maintainability –small changes to the software, Design Patterns in Automated Testing

Design Patterns In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into code.-Wikipedia Design Patterns in Automated Testing

Classification of Design Patterns Creational Abstracts the instantiation process More flexibility in what gets created, who creates it, how it gets created, and when. – Abstract Factory Structural Class and Object Composition Use inheritance to compose interfaces or implementations Compose objects during run time to obtain new functionality. - Component Behavioral Communication between objects. - Template Creational patterns- abstract the instantiation process. They help make a system independent of how its objects are created, composed, and represented. Depends more on composition than inheritance. The emphasis shifts away from hard coding a fixed set of behaviors toward defining a smaller set of fundamental behaviors that can be composed into any number of complex ones. Abstract Factory, Builder Pattern Structural Patterns – Concerned with how classes and objects are composed from larger structures. Useful when independently developed class libraries work together. Adapter, Composite Behavior patterns are concerned with the algorithms and the assignment of responsibilities between objects. These patterns characterize the complex control flow that’s difficult to follow at run-time. You concentrate more on the way objects are communicted. – Template and Interpreter pattern Design Patterns in Automated Testing

Zen Cart Home Page Design Patterns in Automated Testing

Login Page Design Patterns in Automated Testing

Product Page Design Patterns in Automated Testing

Checkout Page Design Patterns in Automated Testing

Component Pattern Structural Pattern All objects are defined as separate components Useful when the pages are formed dynamically(Multi variant Testing) Tests are created by calling these components. Scenario: Search for a product and verify that the price of the product starts with $ Design Patterns in Automated Testing

UML Diagram Design Patterns in Automated Testing

Search Bar public List<WebElement> searchResults(String word){ webdriver.findElement(By.id(“search”)). sendKeys(word); Webdriver.findElement(By.id(“srchBtn”)). click(); List<WebElement> products = this.webdriver.findElements(By.id("productId")); return products; } Design Patterns in Automated Testing

Product Page public String getPrice(){ String productPrice = this.webdriver.findElement(By.id("price")) .getText(); return productPrice; } Design Patterns in Automated Testing

Test public void HomePageToProductPageTest(){ SearchBar searchBox = new SearchBar(driver); List<WebElement> webelements = searchBox.searchResults("books"); webelements.get(0).click(); ProductPage productPage = new ProductPage(driver); Assert.assertTrue(productPage.getPrice().startsWith ("$")); } Design Patterns in Automated Testing

Advantages Maintainability – Functionality is defined in each component Reusability – Tests call the component Time – Common functionality defined in the components. Reliability – All Tests calling the same component will fail. Modularization – Functionality of each component is defined. Design Patterns in Automated Testing

Template Pattern Behavioral Pattern A template method defines the program skeleton of an algorithm. Subclasses redefine certain steps of an algorithm without changing the algorithm’s structure. Scenario: Tests to checkout a product with different credit card. Add product to the Cart Go to the Cart page Check out with different credit cards Design Patterns in Automated Testing

UML Diagram Design Patterns in Automated Testing

Checkout public void purchaseOrder(){ addProduct(); goToCart(); applyPayment(); } protected void addProduct(){ Webdriver.get("http://www.shopping.com/"+productId+"/product.html"); protected void goToCart(){ Webdriver.get("http://wwww.shopping.com/cart.html"); abstract protected void applyPayment(); Design Patterns in Automated Testing

Apply Payment @Override public void applyPayment() { webdriver.findElement(By.id("discov er")).click(); webdriver.findElement(By.id("cardno ")).sendKeys("4444333322221111"); webdriver.findElement(By.id("expmon ")).sendKeys("10"); webdriver.findElement(By.id("expyr" )).sendKeys("2014"); webdriver.findElement(By.id("submit ")).click(); } @Override public void applyPayment() { Webdriver.findElement(By.id("visa" )).click(); webdriver.findElement(By.id("cardn o")).sendKeys("1111222233334444"); webdriver.findElement(By.id("expmo n")).sendKeys("10"); webdriver.findElement(By.id("expyr ")).sendKeys("2014"); webdriver.findElement(By.id("submi t")).click(); } Design Patterns in Automated Testing

Tests @Test public void checkout1(){ WebDriver driver = new FirefoxDriver(); driver.get("http://www.shopping .com"); CheckOut checkout = new Visa(driver); checkout.setProductId(123); checkout.purchaseOrder(); } @Test public void checkout2(){ WebDriver driver = new FirefoxDriver(); driver.get("http://www.shopping .com"); CheckOut checkout = new Discover(driver); checkout.setProductId(123); checkout.purchaseOrder(); } Design Patterns in Automated Testing

Advantages Maintainability – Subclasses override the functionality if needed Reusability – No code duplication between the classes Time – Common functionality defined in the base classes and subclasses only define the override behavior if necessary. Easy to extend. Reliability – Tests fail only if the defined behavior is no more relevant Modularization – Behavior of the component is defined only once in the method/class Design Patterns in Automated Testing

Domain Test Object Encapsulates an application's visual components into objects that can be reused by many tests. Used for testing the expected data – not how they are visually represented. Scenario: Verify whether the products are correctly added to the cart (not the order of the products) and the prices are displayed correctly Design Patterns in Automated Testing

UML Diagram Design Patterns in Automated Testing

Cart Items public String getProduct() { return product; } public void setProduct(String product) { this.product = product; public String getPrice() { return price; public void setPrice(String price) { this.price = price; Design Patterns in Automated Testing

Cart Page public List<CartItems> getCartIems(){ List<CartItems> cart = null ; List<WebElement> cartPro = webdriver.findElement(By.id("products")).findElements(By.classN ame("cartProduct")); CartItems tempItem = new CartItems(); for(WebElement cartItem: cartPro){ tempItem.setPrice(cartItem.getAttribute("price")); tempItem.setProduct(cartItem.getAttribute("name")); cart.add(tempItem); tempItem = null; } return cart; Design Patterns in Automated Testing

Test public void testCartIem(){ String productName = "product1"; String price = "10"; WebDriver driver = new FirefoxDriver(); driver.get("http://www.shopping.com"); driver.findElement(By.id("1234")).click(); driver.findElement(By.id("addToCart")).click(); List<CartItems> cartItems = new CartPage(driver).getCartIems(); boolean isfound = false; for(CartItems cart : cartItems){ if(cart.getProduct().equals(productName)){ isfound=true; Assert.assertTrue(cart.getPrice().equals(price));} } Assert.assertTrue(isfound); } Design Patterns in Automated Testing

Advantages Maintainability – Functionality is separated from the visual representation Reusability – Increases when used with other patterns. Time – Functionality can be tested early. Reliability – Tests fail only if functionality changes. Modularization – Increases when used with other patterns. Design Patterns in Automated Testing

Page Object pattern Pages are defined as classes Uses composition to embed the components and to form a page Mostly used with Selenium. Scenario: Customer placing an order in ZenCart. Design Patterns in Automated Testing

Uml Diagram Design Patterns in Automated Testing

Product Page @FindBy(id="addToCart") WebElement addToCart; public CartPage addtocart(){ addToCart.click(); return new CartPage(); } Cart Page @FindBy(id="goToCheckout") WebElement checkout; public PaymentPage goToCheckout(){ checkout.click(); return new PaymentPage(); } Design Patterns in Automated Testing

Payment Page private void applycreditCard(){ creditCardNumber.sendKeys("1234123412341234"); ccExpMonth.sendKeys("12"); ccExpYear.sendKeys("2014"); submit.click(); } public OrderConfirmationPage applypayment(){ applycreditCard(); return new OrderConfirmationPage(); Design Patterns in Automated Testing

Order Confirmation @FindBy(id="ordernumber") WebElement orderNumber; public String getOrderNumber(){ return orderNumber.getText(); } Design Patterns in Automated Testing

Test WebDriver driver = new FirefoxDriver(); public void OrderPlacement(){ WebDriver driver = new FirefoxDriver(); driver.get("http://www.shopping.com/productid=1234"); ProductPage product = PageFactory.initElements(driver, ProductPage.class); CartPage cart = product.addtocart(); PaymentPage payment = cart.goToCheckout(); OrderConfirmationPage order = payment.applypayment(); Assert.assertTrue("order is null",order.getOrderNumber()!=null); } Design Patterns in Automated Testing

Advantages of Design Patterns Reuse Improves Communication Easy to Extend Easy to Fix Design Patterns in Automated Testing

References http://www.seleniumhq.org Design Patterns – Elements of Reusable Object- Oriented Software http://www.autotestguy.com Design Patterns in Automated Testing

Questions ???? Design Patterns in Automated Testing

Thank you Bindu Laxminarayan bindu@hexbytes.com Design Patterns in Automated Testing