Mastering Selenium WebDriver 3.0
eBook - ePub

Mastering Selenium WebDriver 3.0

Boost the performance and reliability of your automated checks by mastering Selenium WebDriver, 2nd Edition

Mark Collin

Compartir libro
  1. 376 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Mastering Selenium WebDriver 3.0

Boost the performance and reliability of your automated checks by mastering Selenium WebDriver, 2nd Edition

Mark Collin

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

Complement Selenium with useful additions that fit seamlessly into the rich and well-crafted API that Selenium offersAbout This Book• Understand the power, simplicity, and limitations of the core Selenium framework• Write clear, readable, and reliable tests that perform complex test automation tasks• Work with ChromeDriver and GeckoDriver in headless modeWho This Book Is ForIf you are a software tester or a developer with working experience in Selenium and competency with Java, who is interested in automation and are looking forward to taking the next step in their learning journey, then this is the book for you.What You Will Learn• Provide fast, useful feedback with screenshots• Create extensible, well-composed page objects• Utilize ChromeDriver and GeckoDriver in headless mode• Leverage the full power of Advanced User Interactions APIs• Use JavascriptExecutor to execute JavaScript snippets in the browser through Selenium• Build user interaction into your test script using JavascriptExecutor• Learn the basics of working with AppiumIn DetailThe second edition of Mastering Selenium 3.0 WebDriver starts by showing you how to build your own Selenium framework with Maven. You'll then look at how you can solve the difficult problems that you will undoubtedly come across as you start using Selenium in an enterprise environment and learn how to produce the right feedback when failing. Next, you'll explore common exceptions that you will come across as you use Selenium, the root causes of these exceptions, and how to fix them. Along the way, you'll use Advanced User Interactions APIs, running any JavaScript you need through Selenium; and learn how to quickly spin up a Selenium Grid using Docker containers. In the concluding chapters, you'll work through a series of scenarios that demonstrate how to extend Selenium to work with external libraries and applications so that you can be sure you are using the right tool for the job.Style and approachThis book is a pragmatic guide that takes you through the process of creating a test framework with Selenium 3. It then shows you how you can extend this framework to overcome common obstacles that you will come across whilst using Selenium.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Mastering Selenium WebDriver 3.0 un PDF/ePUB en línea?
Sí, puedes acceder a Mastering Selenium WebDriver 3.0 de Mark Collin en formato PDF o ePUB, así como a otros libros populares de Computer Science y Quality Assurance & Testing. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2018
ISBN
9781788293686

Creating a Fast Feedback Loop

One of the main problems you hear people talking about with Selenium is how long it takes to run all of their tests; I have heard figures ranging from a couple of hours to a couple of days. In this chapter, we will have a look at how we can speed things up and get the tests that you are writing to run both quickly and regularly.
Another problem that you may come across is getting other people to run your tests; this is usually because it is a pain to set up the project to work on their machine and it's too much effort for them. As well as making things run quickly, we are going to make it very easy for others to check out your code and get themselves up and running.
How does this create a fast feedback loop?
Well, first of all, allow me to explain what a fast feedback loop is. As developers change or refactor code, it's possible that they may make a mistake and break something. The feedback loop starts off when they commit code and is complete when they know whether their code changes have worked as expected, or something has been broken. We want to make this feedback loop as fast as possible, so ideally a developer will be running all of the tests that are available before every check in. They will then know whether the changes they made to the code have broken something before the code leaves their machine.
Eventually, we want to get to the point where developers are updating tests that fail because the functionality has changed as they go. The eventual code to turn the tests into living documentation, we will talk about a bit more about in Chapter 2, Producing the Right Feedback When Failing.
In this chapter, we are going to start by creating a basic test framework. What am I going to need? The software and browser versions used to write the code in this chapter are as follows:
  • Java SDK 8
  • Maven 3.5.3
  • Chrome 66
  • Firefox 60
It's a good idea to make sure that you atleast update to these versions to make sure everything works for you.

Making it easy for developers to run tests

Ideally, we want our tests to run every time somebody pushes code to the central code repository; part of doing this is ensuring that it's very easy to run our tests. If somebody can just check out our code base and run one command and have all of the tests just work, it means they are far more likely to run them.
We are going to make this easy by using Apache Maven. To steal a quote from the Maven documentation:
"Maven is an attempt to apply patterns to a project's build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices."
Maven is a tool that can be used to build and manage Java projects (including downloading any dependencies that you require) and is used in many companies as part of the standard enterprise infrastructure. Maven is not the only solution to this problem (for example, Gradle is a very powerful alternative that is on par with Maven in many areas and exceeds it in a few), but it is one that you are most likely to see on the ground and one that most Java developers will have used at some point in their careers.
One of the major plus points is that it encourages developers to use a standardized project structure that makes it easy for people who know Maven to navigate around the source code; it also makes it very easy to plug into a CI system (such as Jenkins or TeamCity), as all the major ones understand Maven POM files.
How does this make it easy for developers to run tests? Well, when we have set our project up using Maven, they should be able to check out our test code and simply type mvn clean verify into a Terminal window. This will automatically download all dependencies, set up the class path, and run all of the tests.
It doesn't really get much easier than that.

Building our test project with Apache Maven

Getting a full working Maven install up and running is not within the scope of this book. It's okay though, don't panic! The Apache Software Foundation has you covered, it has a guide to setting up Maven up in just five minutes! See the following link:
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
If you are running the Debian derivative of Linux, it is as easy as using this command:
sudo apt-get install maven 
Or if you are running a Mac with Homebrew, it is just this code:
brew install maven 
Once you have Maven installed and working, we will start our Selenium project with a basic POM file. We are going to start by creating a basic Maven directory structure and then creating a file called pom.xml in it. Take a look at the following screenshot:
There are two main testing frameworks that you will come across in a Java environment; JUnit and TestNG. I personally find TestNG to be easier to get up and running out of the box, but I find JUnit to be more extensible. TestNG certainly seems to be popular on the Selenium mailing list, with many threads asking questions about it; you don't often see JUnit questions any more.
I'm not going to suggest either one as the right choice, as they are both capable frameworks that you will probably come ac...

Índice