Master
ThoughtWorks
Menú
Cerrar
  • Nuestros Servicios
    • Visión general
    • Experiencia del Cliente, Producto y Diseño
    • Estrategia, Ingeniería y Análisis de Datos
    • Transformación Digital y Operaciones
    • Modernización Empresarial, Plataformas y la Nube
  • ¿Con quién trabajamos?
    • Visión general
    • Sector Automotriz
    • Servicios Médicos
    • Sector Público
    • Cleantech y Servicios Públicos
    • Medios y Publicidad
    • E-commerce y Retail
    • Servicios Financieros y Aseguradoras
    • Organizaciones sin fines de lucro
    • Viajes y Transporte
  • Insights
    • Visión general
    • Destacados

      • Tecnología

        Una exploración profunda de tecnología empresarial y excelencia en ingeniería

      • Negocios

        Mantenerse actualizado con los últimos insights empresariales y de industria para líderes digitales

      • Cultura

        El espacio para encontrar contenido y tips de desarrollo profesional, y nuestra visión sobre la justicia social y la inclusión

    • Publicaciones Digitales y Herramientas

      • Radar Tecnológico

        Nuestra guía de tendencias tecnológicas actuales

      • Opiniones

        Una publicación para líderes digitales

      • Digital Fluency Model

        Un modelo para priorizar las capacidad digitales necesarias para navegar en la incertidumbre

      • Decoder

        Una guía tecnológica de la A a la Z para líderes de negocio

    • Todos los Insights

      • Artículos

        Opiniones profesionales que ayudarán al crecimiento de tu negocio

      • Blogs

        Opiniones personales de ThoughtWorkers de todo del mundo

      • Libros

        Navega a través de nuestra extensa biblioteca

      • Podcasts

        Emocionantes charlas sobre las últimas tendencias en negocios y tecnología

  • Carreras
    • Visión general
    • Proceso de Aplicación

      Descubre lo que te espera durante nuestro proceso de selección

    • Graduados y cambio de carreras

      Empieza tu carrera en tecnología con el pie derecho

    • Ofertas de trabajo

      Encuentra puestos vacantes en tu región

    • Mantente conectado

      Suscríbete a nuestro boletín mensual

  • Acerca de Nosotros
    • Visión general
    • Nuestro Propósito
    • Premios y Reconocimientos
    • Diversidad, equidad e inclusión
    • Nuestros líderes
    • Asociaciones
    • Noticias
    • Conferencias y eventos
  • Contacto
Spain | Español
  • United States United States
    English
  • China China
    中文 | English
  • India India
    English
  • Canada Canada
    English
  • Singapore Singapore
    English
  • United Kingdom United Kingdom
    English
  • Australia Australia
    English
  • Germany Germany
    English | Deutsch
  • Brazil Brazil
    English | Português
  • Spain Spain
    English | Español
  • Global Global
    English
Blogs
Selecciona un tema
Ver todos los temasCerrar
Tecnología 
Gestión de Proyectos Agiles La Nube Entrega Continua Ciencia e Ingenieria de Datos Defendiendo el Internet Libre Arquitectura Evolutiva Experiencia de Usuario IoT  Lenguajes, Herramientas y Frameworks Modernización de sistemas heredados Machine Learning & Artificial Intelligence Microservicios Plataformas Seguridad Pruebas de Software Estrategia Digital 
Negocio 
Servicios Financieros Salud Global Innovación Ventas  Transformación 
Carreras 
Hacks Para Tu Carrera Diversidad e Inclusión Cambio Social 
Blogs

Temas

Elegir tema
  • Tecnología
    Tecnología
  • Tecnología Visión General
  • Gestión de Proyectos Agiles
  • La Nube
  • Entrega Continua
  • Ciencia e Ingenieria de Datos
  • Defendiendo el Internet Libre
  • Arquitectura Evolutiva
  • Experiencia de Usuario
  • IoT
  • Lenguajes, Herramientas y Frameworks
  • Modernización de sistemas heredados
  • Machine Learning & Artificial Intelligence
  • Microservicios
  • Plataformas
  • Seguridad
  • Pruebas de Software
  • Estrategia Digital
  • Negocio
    Negocio
  • Negocio Visión General
  • Servicios Financieros
  • Salud Global
  • Innovación
  • Ventas
  • Transformación
  • Carreras
    Carreras
  • Carreras Visión General
  • Hacks Para Tu Carrera
  • Diversidad e Inclusión
  • Cambio Social
Pruebas de SoftwareTecnología

Writing Twist tests with Page Object pattern

ThoughtWorks ThoughtWorks

Published: May 6, 2013

Page object pattern maps UI pages to classes and related actions to methods in that class. This allows for better grouping of page actions. All the actions specific to each page will be in a single class. Page object pattern has few advantages:

  • Better reusability
  • Improved test readability
  • Models the UI in tests

This page explains page object pattern in detail.

Twist tests and page object pattern

In this blog post, I will explain about how to use page object pattern while writing Twist tests. Let us consider a test scenario in which we are searching for a product in Amazon and adding the product to shopping cart.

In Twist, each step lives in a fixture class and this can represent actions specific to that page. In the above example, we have two page classes, "On Homepage" and "On shopping cart page". Now before each step executes, we should navigate to the specific pages, so that the step can perform its task without worrying about navigating to the page.

Before Twist 13.1, your step would be something like this:

public void searchForAndAddToCart(String product) throws Exception {
   String url = "http://amazon.com";
   if (!browser.getCurrentUrl().equals(url)) {
   browser.get(url);
   }
   // Implementation for search and add to cart
 }

Or in your scenario, you could navigate before each step, something like this:

The trouble here is that for each step that gets added to the fixture class, the navigation has to be completed before it can perform the action. This becomes a problem when more and more actions get added to the fixture class. It can be easily solved by using "Execution hooks" which are introduced in Twist 13.1.

Twist provides global, scenario level execution hook and a fixture level hook. Fixture level hooks are local to the fixture class. In this example, we will use a fixture level hook.

public void searchForAndAddToCart(String product) throws Exception { 
      // Implementation for search and add to cart
}
@BeforeEachStep 
public void beforeEachStep() {
      String url = "http://amazon.com"; 
      if (!browser.getCurrentUrl().equals(url)) {
          browser.get(url);
      }
}

"beforeEachStep()" method will be executed before every step executes in that fixture. We will navigate to the required page in this hook. With this, the step implementation doesn’t need to worry about the navigation.

Similarly, to verify items are added to shopping cart, “before hook” ensures you are on the shopping cart page before the verification code is executed.

public void verifyShoppingCartContains(String string1) throws Exception { 
      // Code to do the verification
} 
@BeforeEachStep 
public void beforeEachStep() { 
      String url = "https://www.amazon.com/gp/cart/view.html/"; 
      if (!browser.getCurrentUrl().equals(url)) { 
      browser.get(url);
      } 
} 

This method also improves reusability of steps across scenarios. For instance, we can use "Verify shopping cart contains product" from any scenario file without thinking about its navigation. This also simplifies the scenario, as shown below,

 

See what's new in Twist 13.1 on our community site or Try Twist now.

 

 

Master
Política de Privacidad | Declaración sobre la esclavitud moderna | Accesibilidad
Connect with us
×

WeChat

QR code to ThoughtWorks China WeChat subscription account
© 2021 ThoughtWorks, Inc.