Selenium WebDriver Tutorial #2 - Selenium WebDriver Architecture

Software Testing Mentor
11 May 202012:20

Summary

TLDREste tutorial de Selenium WebDriver explica la arquitectura de Selenium, crucial para comprender cómo se desarrollan y ejecutan los scripts de automatización. Se describe cómo las bibliotecas de cliente de Selenium permiten escribir código en múltiples lenguajes de programación y cómo estos se traducen al protocolo JSON para interactuar con el navegador a través del WebDriver. Se ilustra con ejemplos cómo se ejecutan comandos en el navegador, y se menciona la importancia de descargar y configurar los controladores de navegador compatibles. Finalmente, se toca el tema de la API REST de Selenium WebDriver y se guía al espectador hacia la documentación oficial para un entendimiento más profundo.

Takeaways

  • 🧩 Comprender la arquitectura de Selenium es crucial para comprender cómo se ejecutan y configuran los scripts de automatización en diferentes entornos de desarrollo.
  • 🌐 Selenium soporta múltiples lenguajes de programación, como Java, Python, Ruby, C# y JavaScript, lo que permite a los usuarios escribir scripts en el lenguaje de su elección.
  • 💻 La librería cliente de Selenium es esencial para interpretar el código escrito en los distintos lenguajes de programación y convertirlo en un formato que el WebDriver pueda entender.
  • 🔄 El JSON Wire Protocol actúa como un puente entre el código escrito por el usuario y el WebDriver, permitiendo la comunicación bidireccional entre ellos.
  • 🌐 Los controladores del navegador, como ChromeDriver, GeckoDriver y SafariDriver, son necesarios para que Selenium interactúe con los navegadores reales y ejecute las acciones definidas en los scripts.
  • 🔍 La comunicación entre el WebDriver y los controladores del navegador se realiza a través de solicitudes HTTP, que pueden ser GET o POST, dependiendo de la operación que se esté realizando.
  • 🛠️ Para comenzar con Selenium, es necesario descargar e instalar los controladores del navegador correspondientes al navegador en el que se deseen ejecutar los tests.
  • 🔗 El Selenium WebDriver es en realidad una API REST que maneja las solicitudes y respuestas en formato JSON, permitiendo la interacción con los elementos del navegador.
  • 📚 La especificación W3 WebDriver ofrece detalles sobre cómo se implementan los métodos y acciones del WebDriver, lo que puede ser útil para aquellos interesados en los aspectos técnicos internos.
  • 💼 Conocer la arquitectura de alto nivel de Selenium es beneficioso para los entrevistas y para entender el flujo general de la automatización de pruebas sin profundizar en los detalles técnicos.

Q & A

  • ¿Qué es Selenium y por qué es importante entender su arquitectura?

    -Selenium es una herramienta de automatización de pruebas web que permite la interacción con diferentes navegadores a través de diferentes lenguajes de programación. Es importante entender su arquitectura porque ayuda a comprender cómo se configura el desarrollo y cómo los scripts interactúan con los navegadores, lo que es crucial para cualquier marco de automatización.

  • ¿Qué es la librería cliente de Selenium y qué función cumple?

    -La librería cliente de Selenium es un conjunto de herramientas que permite escribir código en varios lenguajes de programación soportados por Selenium, como Java, Python, Ruby, C# y JavaScript. Ayuda a interpretar el código escrito y a traducirlo al formato JSON para su posterior envío al WebDriver a través del protocolo JSON Wire.

  • ¿Qué es el protocolo JSON Wire y cómo se relaciona con Selenium?

    -El protocolo JSON Wire es una capa de comunicación que permite que los comandos escritos en lenguajes de programación sean enviados al WebDriver en formato JSON a través de HTTP. Es fundamental en Selenium para la comunicación entre el código de automatización y los controladores del navegador.

  • ¿Cuál es el papel del WebDriver en la arquitectura de Selenium?

    -El WebDriver en la arquitectura de Selenium actúa como un intermediario entre la librería cliente y el navegador real. Recibe los comandos en formato JSON, los traduce y los ejecuta en el navegador, devolviendo los resultados de las acciones realizadas.

  • ¿Qué es un controlador de navegador y cómo se relaciona con Selenium?

    -Un controlador de navegador es un componente específico para cada navegador (como ChromeDriver para Chrome, GeckoDriver para Firefox, etc.) que permite a Selenium interactuar con el navegador. Es necesario descargar y configurar el controlador correspondiente al navegador que se desea automatizar.

  • ¿Cómo se ejecuta un script de Selenium y qué sucede si encuentra un error?

    -Un script de Selenium se ejecuta iniciando el navegador, ejecutando las acciones definidas en el script (como buscar texto en Google) y respondiendo según el éxito de la acción. Si se encuentra un error, como un elemento no encontrado, el controlador del navegador devuelve el error al WebDriver, que a su vez lo envía al IDE en formato JSON.

  • ¿Qué es la API de Selenium WebDriver y cómo se relaciona con la automatización de pruebas?

    -La API de Selenium WebDriver es una interfaz de programación que permite a los desarrolladores escribir código para automatizar las pruebas en un navegador web. Es una REST API que maneja las solicitudes y respuestas en formato JSON, facilitando la interacción con los elementos del navegador.

  • ¿Dónde puedo encontrar más detalles sobre la especificación de la API de Selenium WebDriver?

    -Puedes encontrar más detalles sobre la especificación de la API de Selenium WebDriver en la documentación oficial de Selenium, donde se detallan las diferentes acciones y métodos disponibles, como encontrar elementos o realizar acciones en ellos.

  • ¿Cómo se configura el entorno de desarrollo para comenzar a escribir pruebas con Selenium?

    -Para configurar el entorno de desarrollo, es necesario descargar la librería cliente de Selenium correspondiente al lenguaje de programación elegido, descargar y configurar el controlador del navegador y, opcionalmente, ajustar la configuración de Selenium WebDriver según las necesidades específicas del proyecto.

  • ¿Qué tipo de preguntas sobre la arquitectura de Selenium se pueden esperar en una entrevista?

    -En una entrevista, se pueden esperar preguntas sobre cómo funciona la comunicación entre la librería cliente, el WebDriver y el navegador, el papel del protocolo JSON Wire, cómo se ejecutan y manejan los errores en los scripts de Selenium, y detalles sobre la configuración y uso de la API de Selenium WebDriver.

Outlines

00:00

😀 Introducción a la Arquitectura de Selenium

Este tutorial se centra en la arquitectura de Selenium, explicando su importancia para comprender cómo se desarrolla y ejecuta un script de automatización. Se menciona que Selenium soporta múltiples lenguajes de programación y se utiliza la librería cliente de Selenium para escribir y interpretar el código. Se describe el proceso de cómo el código se convierte en formato JSON y se envía a través del protocolo JSON Wire a los controladores del navegador. Se ilustra con un ejemplo práctico de cómo se ejecuta un script en el navegador Chrome, incluyendo la interacción bidireccional entre el código, el WebDriver y el navegador real.

05:01

🔧 Configuración y Detalles Técnicos de Selenium WebDriver

En este párrafo, se profundiza en la configuración de Selenium, incluyendo la necesidad de descargar y configurar controladores de navegador según el navegador en el que se deseen ejecutar las pruebas. Se mencionan los diferentes controladores disponibles para navegadores como Firefox, Safari y Chrome, y se destaca la responsabilidad de diferentes organizaciones en el soporte de estos. Además, se habla sobre la implementación de Selenium WebDriver como una API REST, donde los comandos de código se convierten en solicitudes HTTP y se envían en formato JSON. Se sugiere explorar la documentación para comprender mejor la especificación W3C de WebDriver y sus métodos de acción.

10:04

📚 Conclusión y Recursos para Aprendizaje Avanzado

El tutorial concluye con una breve mención de la especificación W3C para WebDriver, que detalla las acciones disponibles para los elementos y los métodos GET y POST utilizados en la implementación. Se alienta a los aprendices interesados en la implementación interna de WebDriver a estudiar la documentación para obtener más detalles. Para aquellos que buscan ser tester de automatización sin profundizar en los detalles técnicos, se recomienda enfocarse en la arquitectura de alto nivel, que es útil para respuestas en entrevistas. El presentador agradece la atención y ofrece un resumen de los conceptos clave tratados en el tutorial.

Mindmap

Keywords

💡Selenium

Selenium es un marco de herramientas para la automatización de pruebas web y un proyecto de automatización de navegador. En el guion, Selenium se menciona como la herramienta principal que se utiliza para la automatización de pruebas, y se discute su arquitectura para comprender cómo interactúa con los navegadores y cómo se configura para el desarrollo.

💡Arquitectura de Selenium

La arquitectura de Selenium es esencial para entender cómo funciona la herramienta y cómo interactúa con los navegadores web. En el video, se explica que comprender esta arquitectura ayuda a configurar el entorno de desarrollo y a escribir scripts de prueba más eficientemente.

💡Biblioteca de cliente de Selenium

La biblioteca de cliente de Selenium es un conjunto de herramientas que permite a los desarrolladores escribir código en varios lenguajes de programación compatibles con Selenium, como Java, Python, Ruby, C# y JavaScript. En el guion, se menciona que esta biblioteca es crucial para interpretar el código escrito por el usuario y para convertirlo en una forma que el WebDriver pueda entender.

💡JSON Wire Protocol

El JSON Wire Protocol es un protocolo de comunicación que permite que el código escrito en la biblioteca de cliente de Selenium se comunique con el WebDriver y, a su vez, con el navegador. En el guion, se describe cómo el código se convierte en formato JSON y se envía a través de este protocolo.

💡WebDriver

El WebDriver es una API que permite a los programas controlar el navegador web. En el video, se menciona que el código escrito por el usuario se envía al WebDriver, que a su vez interactúa con el navegador real para ejecutar las acciones definidas en el script.

💡Navegadores y controladores de navegador

Los controladores de navegador, como ChromeDriver, GeckoDriver, SafariDriver y EdgeDriver, son componentes necesarios para que Selenium interactúe con diferentes navegadores web. En el guion, se explica que dependiendo del navegador en el que se deseen ejecutar las pruebas, se debe descargar y configurar el controlador de navegador correspondiente.

💡IDE (Entorno de desarrollo integrado)

Un IDE es un software que proporciona servicios a los programadores para facilitar el desarrollo de software. En el guion, se menciona Eclipse como un ejemplo de IDE para Java, donde se escribe y ejecuta el código de Selenium.

💡REST API

Una API REST es una arquitectura de software que define una manera de intercambiar datos entre diferentes sistemas. En el video, se menciona que Selenium WebDriver es en realidad una API REST, y se describe cómo las solicitudes y respuestas se envían y reciben en formato JSON.

💡Elementos del navegador

Los elementos del navegador son componentes visuales de una página web, como botones, enlaces y campos de texto, con los que interactúa Selenium. En el guion, se describe cómo Selenium utiliza métodos como 'find element' para localizar y manipular estos elementos en la página web.

💡Errores en la automatización

Los errores en la automatización son situaciones en las que Selenium no puede encontrar o interactuar con un elemento como se esperaba. En el guion, se menciona cómo estos errores se devuelven al controlador de navegador y, a continuación, al IDE, donde se muestran al usuario.

Highlights

Tutorial sobre la arquitectura de Selenium WebDriver.

Importancia de comprender la arquitectura de Selenium para la configuración y escritura de scripts de automatización.

Selenium admite múltiples lenguajes de programación como Java, Python, Ruby, C# y JavaScript.

La librería cliente de Selenium ayuda a escribir código en diferentes lenguajes de programación.

El código escrito se convierte en formato JSON y se transfiere a través del protocolo JSON Wire.

El protocolo JSON Wire actúa como un puente entre el código y los controladores del navegador.

Los controladores del navegador, como ChromeDriver, interactúan con el navegador real para ejecutar las acciones definidas en el script.

Las acciones del navegador y los resultados se comunican de vuelta al IDE a través del protocolo JSON Wire.

Ejemplo de un script básico de Selenium para buscar texto en Google.

Si el navegador no encuentra un elemento definido en el script, se devuelve un error.

Los errores se comunican de vuelta al IDE en formato JSON.

Selenium WebDriver es en realidad una API REST.

La documentación proporciona detalles sobre la especificación W3 de WebDriver y sus componentes.

La arquitectura de Selenium es importante para respuestas en entrevistas y comprender cómo funciona la herramienta.

Se recomienda enfocarse en la arquitectura de alto nivel si no se está interesado en los detalles internos de la implementación.

Tutorial concluye con una revisión de la arquitectura de Selenium y agradece a los espectadores.

Transcripts

play00:00

hello guys welcome to selenium-webdriver

play00:02

tutorial in this tutorial we are going

play00:05

to understand about selenium

play00:07

architecture so the previous tutorial

play00:10

was all about the selenium introduction

play00:13

the basics of selenium and now let's

play00:17

understand the selenium architecture

play00:20

understanding selenium architecture is

play00:22

really important because it will help

play00:25

you to understand how you are going to

play00:28

set up the development in one meant and

play00:30

write the script so how your scripts

play00:35

interact with the browser so this

play00:37

understanding is really important in any

play00:40

automation framework or any automation

play00:43

tool so having a basic understanding of

play00:46

the architecture helps you a lot in you

play00:50

know like future in the advanced topics

play00:52

in learning the tool properly so let's

play00:57

go ahead and understand the selenium

play00:59

architecture so here on my screen I have

play01:03

prepared a diagram for selenium

play01:05

architecture so if you see in the left

play01:09

hand side we have the selenium client

play01:12

library section right so what this

play01:15

selenium client library is because we

play01:18

have seen that selenium supports

play01:20

multiple programming languages like Java

play01:22

Python Ruby c-sharp JavaScript right so

play01:27

this client library provided by selenium

play01:30

is basically helps you to write your

play01:33

code in any of these programs supported

play01:36

programming languages in the integrated

play01:38

development environment so for example

play01:41

for Java you will use Eclipse for Python

play01:44

you can use Python for Java you have

play01:48

other other IDs as well so once you

play01:52

write your script in any of these

play01:54

programming languages your selenium

play01:56

client library helps that code to be

play02:01

interpreted so basically what happens is

play02:03

once you write your test case and

play02:06

trigger your tests that complete

play02:09

selenium code that you have written in

play02:10

any programming supported programming

play02:12

language

play02:13

for example here let's take an example

play02:15

of Java that code gets translated or

play02:19

converted into the JSON format okay and

play02:25

transferred to the selenium webdriver

play02:29

through the JSON wire protocol so you if

play02:32

you see here the JSON wire protocol so

play02:35

your code whatever you have written gets

play02:39

converted into the JSON format

play02:41

through the JSON wire protocol over HTTP

play02:44

it gets transferred to any of these

play02:48

browser drivers so here you have the web

play02:50

driver and then supported you know like

play02:53

browser drives so for example you try

play02:56

you are trying to execute your script

play02:58

that you have written in the Chrome

play03:01

browser so you will have the

play03:02

corresponding Chrome browser chrome

play03:05

driver Chrome browser driver and then

play03:09

you have the real browser okay so here

play03:11

you will see these arrows are

play03:13

bi-directional so what this means is

play03:15

that the once you run the script it gets

play03:18

communicated to through the JSON wire

play03:21

protocol to the selenium webdriver and

play03:23

the corresponding and the browser driver

play03:26

which is in this case we are taking an

play03:28

example of the Chrome browser so chrome

play03:30

driver and that chrome driver in turn

play03:34

launches or sense the actions or the

play03:39

script actions that you have defined to

play03:41

the real browser okay so it will launch

play03:44

the real browser it will perform the

play03:47

action that you have defined in your

play03:49

script and then based on that action if

play03:52

the action is successful then it will

play03:55

respond back whether the action has been

play03:58

successful and thence to the chrome

play04:02

browser from the chrome browser again to

play04:04

the JSON wire protocol over HTTP to your

play04:08

ID in this case in our case it will be

play04:11

Eclipse because this is will be using

play04:13

Java and we'll be using Eclipse as an

play04:16

integrated development environment for

play04:17

Java so to give you a brief example say

play04:21

for example I want to search any text on

play04:26

Google

play04:26

komm right so this is the very basic

play04:28

script that I'll launch the browser I

play04:30

want to launch google.com in Chrome

play04:33

browser search a text and see whether

play04:37

the search has been successful so what

play04:39

I'll do in the automation steps is I'll

play04:43

first step will be to launch the browser

play04:46

and launch and open the URL google comm

play04:50

then I'll find the text box search text

play04:54

box I click on that text box and then

play04:58

I'll enter the text that I want to

play05:00

search and then click on the search

play05:02

button and it will give me the results

play05:05

now in the automation script I'll

play05:07

perform the same steps so with my

play05:10

selenium Java client library I'll write

play05:14

these steps in the programming in the

play05:17

code and once I'll run this code it this

play05:22

code will get converted into JSON wire

play05:24

into JSON format through JSON wire

play05:27

protocol it will go to the Chrome

play05:30

browser launch the browser to perform

play05:32

all these actions if it is not able to

play05:34

find say for example there is a web

play05:37

element search text box that you have

play05:40

defined in your script which is not

play05:42

which the the the Chrome browser is not

play05:46

able to the chrome driver is not able to

play05:49

find in the real browser so in that case

play05:52

there will be error returned so in that

play05:54

error scenario the return the error will

play05:57

be returned to the chrome driver right

play05:59

and then from chrome driver it will be

play06:01

returned from in the JSON format with

play06:07

Jason wire protocol over HTTP to your ID

play06:10

ok and it will it will be displayed on

play06:13

your ID as an error so this is briefly

play06:17

or very quickly to understand the

play06:20

overview or how the selenium

play06:22

architecture it is now if you want to

play06:26

get a lot more detail or want to dig

play06:29

deeper into you know what exactly how

play06:35

the selenium webdriver is implement

play06:37

implemented select selenium webdriver is

play06:39

actually

play06:40

rest api okay so if we let's go ahead

play06:44

and before before understanding that

play06:48

selenium-webdriver rest api i would like

play06:50

to show you the browser drivers that we

play06:52

need to download and configure in our

play06:55

environment setup right so let me go

play06:58

back to this website okay and here if

play07:02

you'll see we'll go to the doc downloads

play07:05

page right and here you have the

play07:08

selenium client right so selenium client

play07:11

every webdriver language bindings so

play07:13

this is what all the selenium client

play07:17

library is talking about right so these

play07:19

client libraries basically so if you

play07:22

want to write your code or test in Java

play07:24

you need this client library right you

play07:26

need to download this now if you want to

play07:33

run your test case in a different

play07:34

browser so go to browser section so

play07:36

gecko driver is implemented for support

play07:39

by Mozilla right so if you want to run

play07:42

your test case in the Firefox you need

play07:46

gecko driver if you need to run test

play07:50

case in I you need iDrive ER for safari

play07:53

it is Safari driver and all these are

play07:56

supported by different organizations who

play08:00

will see safari supported by Apple or

play08:02

prized by Oprah software chrome driver

play08:05

is by the chrome chromium project right

play08:07

and Edie is by Microsoft so depending on

play08:12

which browsers you want to run your test

play08:14

cases you have to download these browser

play08:17

drivers and configure these right so

play08:21

this is what we need to configure and

play08:24

then the selenium webdriver

play08:26

library so there are multiple

play08:29

configuration options that are available

play08:32

so I will show you exactly what all you

play08:36

need in order to setup your integral

play08:40

your development environment before you

play08:42

start writing your first test case in

play08:45

selenium all right so now when it comes

play08:50

to understanding what exactly selenium

play08:53

webdriver so selenium webdriver is

play08:55

nothing it's an API right it's a REST

play08:59

API and when you write your test case or

play09:04

any step in any IDE in language C for

play09:08

example Java you are writing the step or

play09:12

code to launch any webpage now what

play09:16

happens is there is a call behind the

play09:20

there is a call that happens so your

play09:22

that that particular line of code is

play09:24

converted into the JSON format and sent

play09:28

as a request or a rest get request or

play09:31

post request so depending on what

play09:33

operation you are performing so it will

play09:35

be sent as a post request or get request

play09:37

and that's what selenium webdriver is

play09:41

all about so it will be sending that

play09:44

request and getting the response back

play09:47

into the JSON format now if you want to

play09:50

get into the more details of you know

play09:54

the webdriver API so you can go to the

play09:57

documentation and in the documentation

play10:03

here you can you can see the selenium

play10:05

browser automation project and you can

play10:08

see w3 webdriver specification if you

play10:11

click on webdriver specification it will

play10:15

show you the w3 specification for all

play10:19

the components of the webdriver right so

play10:23

for example these are the actions that

play10:27

are available for the elements so you

play10:29

can find elements you can find element

play10:31

from element so all these so if you go

play10:34

to elements section and scroll down you

play10:39

will see some get post methods to use

play10:43

and you can see the find method right

play10:45

find element so when you say actually

play10:47

find element use you see actually

play10:50

internally what happens is it's a post

play10:53

method and it passes the session ID of

play10:58

the particular session and finds the

play11:01

element right the element that you pass

play11:04

or the locator or the

play11:07

collision of the element that you pass

play11:09

so this is more of you know like what

play11:12

exactly how the webdriver implementation

play11:15

is done to find elements or find element

play11:18

from element similarly under the actions

play11:21

you will see there are a lot of methods

play11:23

available so this is if you want if you

play11:26

are more interested into what exactly

play11:28

the webdriver is how it is implemented

play11:31

so you can go through this documentation

play11:34

to learn a lot more about the webdriver

play11:38

architecture but if you are just

play11:41

learning to be you know like automation

play11:45

tester and not worried into too much

play11:48

detail of the internal working so which

play11:50

I don't think you will require if you

play11:53

are just you know doing the automation

play11:55

script so just stick to the high level

play11:58

architecture because this architecture

play12:01

will be asked in many interview

play12:04

questions so it will help you a lot to

play12:05

explain how exactly it is implemented so

play12:11

that's pretty much all about the

play12:13

selenium architecture hope you liked the

play12:16

tutorial thank you very much for

play12:17

watching

Rate This

5.0 / 5 (0 votes)

Связанные теги
SeleniumArquitecturaAutomatizaciónPruebasNavegadoresDesarrolloProgramaciónWebDriverIDEJSON
Вам нужно краткое изложение на английском?