Selenium with Python - A Beginner’s Guide (Pallavi R Sharma) (Z-Library)

Author: Pallavi R Sharma

Python

Step by step directions to get started with Selenium using Python as a programming language DESCRIPTION Selenium is the most popular open source test automation tool available in the market. In the last decade, its usage has dramatically increased in the IT sector across all types of organizations. The reason for its popularity is mainly because it supports multiple programming languages, test executions on multiple browsers and operating systems. In this book, we will learn about the different components of Selenium. We will discuss the concepts of WebDriver and learn how to apply test automation concepts with it to automate the testing of our application. We will learn the process of recognizing the test objects on the screen and writing Selenium commands using Python as a programming language We will also discuss how to use design patterns like the page object mode and data-driven testing to ensure building a robust test framework, which is modular and scalable in nature. KEY FEATURES Get introduced to the world of Selenium Understand the concept of locators in Selenium Learn how to write scripts using Selenium WebDriver in Python Learn the concepts of synchronization Learn how to handle different HTML elements like form, table, alert, frame, and dropdown Learn about design patterns like the page object model, data-driven tests, and adding assertions WHAT WILL YOU LEARN The objective is to introduce the world of Selenium to a manual tester who knows Python as a programming language. You will learn to demystify the concept of identifying test objects and writing Selenium commands to create robust test scripts. This book will help learn to automate different HTML elements, which we come across in the web applications we need to test. You will understand how to build a good test suite by learning the concept of design patterns like the page object model and data-driven tests to ensure maintainability of code. WHO THIS BOOK IS FOR This book is for people who have exp

📄 File Format: PDF
💾 File Size: 3.4 MB
82
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
(This page has no text content)
📄 Page 2
Selenium with Python A Beginner’s Guide by Pallavi R Sharma FIRST EDITION 2019 Copyright © BPB Publications, India ISBN: 978-93-89328-813 All Rights Reserved. No part of this publication may be reproduced or distributed in any form or by any means or stored in a database or retrieval system, without the prior written permission of the publisher with the exception to the program listings which may be entered, stored and executed in a computer system, but they can not be reproduced by the means of publication. LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY The information contained in this book is true to correct and the best of author’s & publisher’s knowledge. The author has made every effort to ensure the accuracy of these publications, but cannot be held responsible for any loss or damage arising from any information in this book. All trademarks referred to in the book are acknowledged as properties of their respective owners. Distributors: BPB PUBLICATIONS 20, Ansari Road, Darya Ganj New Delhi-110002 Ph: 23254990/23254991 MICRO MEDIA Shop No. 5, Mahendra Chambers, 150 DN Rd. Next to Capital Cinema, V.T. (C.S.T.) Station, MUMBAI-400 001 Ph: 22078296/22078297 DECCAN AGENCIES 4-3-329, Bank Street, Hyderabad-500195 Ph: 24756967/24756400 BPB BOOK CENTRE 376 Old Lajpat Rai Market, Delhi-110006 Ph: 23861747 Published by Manish Jain for BPB Publications, 20 Ansari Road, Darya Ganj, New Delhi-110002 and Printed by him at Repro India Ltd, Mumbai
📄 Page 3
Dedicated to My Parents Dr. Neelaksh Sharma & Dr. Manju Sharma and My Kids Neeal & Maisha About the Author Pallavi has an overall professional experience of 14 years. She has worked in varied roles as a product/project manager in the presales team and marketing team for solutions on test automation tools. She holds two provisional patents along with other contributors for her work on building tool agnostic test automation framework solutions. Currently, she is acting as a test automation coach, writer, speaker and she works as a solopreneur. She collaborates and works with test automation enthusiasts across the globe. As an avid learner, she likes to keep herself updated to the latest trends and technologies. She is a firm believer in larger good and likes to live by example. She volunteers her time for the organization eVidyaloka where she acts as a centre administrator. She is a lifetime member for the Jabarkhet forest reserve and People for Animals. Reviewer Afsana Atar is an expert software test professional, an Agile evangelist. She has over a decade’s experience in the IT industry working with companies like Google, IBM, Principal Financial Group and Children’s Hospital of Philadelphia. She is currently working with a financial trading and brokerage firm, Susquehanna International Group. She has managed several projects and ensured the delivery of critical projects which enabled customer success. She is also an international author with several books and publications on testing, test management and the tech industry in general. She extends her thought leadership to teams in a variety of domains from digital advertising, education & healthcare to the financial sector in banking, insurance & trading. She is a Certified Scrum Master (CSM), an Agile scrum practitioner and part of the scrum alliance community. She is also an international speaker and has been invited to an international conference in Brazil and the USA after great success of her book “Hands-On Test Management with JIRA”. Acknowledgement First and foremost, I would like to thank Mr Manish Jain from BPB Publications for giving me this opportunity to write the book. I would also like to thank Nrip, Priyanka and all the people associated with this book. The entire team was very helpful and forthcoming in solving queries and making a first-time writer feel comfortable. I would like to thank Mr. Pankaj Goel, CEO at CresTech, to introduce me to the world of Software Test Automation, to hold my hand and help me walk the path. I would also like to thank Dr. Naren Ramakrishnan, Director at Discovery Analytics at Virginia Tech, who helped me hone my skills in open source programming languages and made me realize that a BTech degree is equivalent to having a driving license. I would like to express my heartfelt gratitude to my beautiful sister, Mahak and my handsome husband Ravi, for their care, humour, support, love and belief in my abilities. You both could see me when I could not see myself. Thanks a lot, guys. A special thanks to all the people who took my courses at Udemy, joined my batches or one-to-one sessions, or met me through some corporate programs. Thank you so much for giving me this opportunity to coach you and learn this wonderful tool Selenium along with you. Finally, I would like to express my heartfelt gratitude to the entire Selenium community from its creators to people who maintain the tool to everyone involved. Cheers to each one of you! It’s a wonderful creation! – Pallavi R Sharma Preface Selenium is a test automation tool for web application functional testing that has gained significant popularity in the last decade or so. The reason for its popularity is that it is open source, it supports scripting in different programming languages like Java, C#, Python, Ruby, Perl, and JavaScript. It automates different browsers on different operating systems. No other tool in the market comes with this rich feature set with zero license cost. Many organizations big or small have moved towards Selenium. Also due to adaptation of Agile practices, CI/CD pipeline automation is no longer an option but a necessity. Selenium implementation using Java as a programming language is widely used. In recent years, a significant rise is seen in the implementation of Selenium with Python, as this language has gained popularity. In this book, we will learn about the concepts of test automation using the tool Selenium, and implement them using the programming language Python. Chapter 1 – In this chapter, introduces Selenium, the different components of Selenium, discusses why we should use Selenium and the Selenium
📄 Page 4
architecture. Chapter 2 – In this chapter, discusses the Selenium IDE, its installation, how to create the first test for record and playback. It covers Selenium commands. Chapter 3 – In this chapter, talks about the concepts of the locators. Locators of Selenium allow us to identify the objects uniquely on the page so that we can perform actions on it. Chapter 4 – In this chapter, covers the setting system for writing our very first test using selenium webdriver on the eclipse IDE, using the PyDev plugin. It runsa test on Chrome, Firefox and the Internet Explorer browser. Chapter 5 – In this chapter, discusses the WebDriver, WebElements, and By classes of the selenium webdriver module of Python. It covers the different methods associated with these classes. Chapter 6 – In this chapter, discusses the unittest module. It is the unit test framework of the Python programming language. It also discusses its assertion module to help us assert our scripts. Chapter 7 – In this chapter, discuss the concept of synchronization. It covers static wait and dynamic wait. Chapter 8 – In this chapter, explains how we can parameterize our test using an external dataset like a csv file. Chapter 9 – In this chapter, discusses how Selenium automates different HTML elements. Form elements, tables, drop down. Chapter 10 – In this chapter, looks at some other HTML elements like frame, alerts and action class of Selenium Chapter 11 – In this chapter, discusses the concept of the page object model, which is a famous design pattern for Selenium test suite creations, which help manage object information. Chapter 12 – In this chapter, discusses how to implement the Selenium grid by invoking the Selenium server in the hub mode and node mode. It also covers how to make some changes in scripts to point it to the hub for execution. Downloading the code bundle and coloured images: Please follow the link to download the Code Bundle and the Coloured Images of the book: http://rebrand.ly/09afb Errata We take immense pride in our work at BPB Publications and follow best practices to ensure the accuracy of our content to provide with an indulging reading experience to our subscribers. Our readers are our mirrors, and we use their inputs to reflect and improve upon human errors if any, occurred during the publishing processes involved. To let us maintain the quality and help us reach out to any readers who might be having difficulties due to any unforeseen errors, please write to us at : errata@bpbonline.com Your support, suggestions and feedbacks are highly appreciated by the BPB Publications’ Family. Table of Contents 1. Introduction to Selenium Structure Objective History of Selenium Benefits of Selenium Components of Selenium Architecture of Selenium Conclusion Questions
📄 Page 5
1. Selenium IDE Structure Objective Installation of Selenium IDE Introduction to demo web application Record and playback in Selenium IDE Structure of Selenium IDE Test Conclusion Questions 1. Locators in Selenium Introduction Structure Objective What is a locator? Conclusion Questions 1. Installation and setup Structure Objective Installation and setting up Installing Selenium Python module Creating Python project in Eclipse Automating Chrome browser Writing the first script Automating Firefox browser Automating Internet Explorer Conclusion Questions 1. Understanding WebDriver, WebElement and By Structure Objective Introduction to Selenium module WebDriver WebElement By Conclusion Questions
📄 Page 6
1. Unittest in Python Structure Objective The unitest and its structure Assertions Conclusion Questions 1. Synchronizing Test Structure Objective Synchronization Implicit wait Explicit wait Conclusion Questions 1. Concept of Parameterization Structure Objective Test data file Parameterization and login logout scenario Conclusion Questions 1. Working with Different WebElements Structure Objective Working with form elements Working with HTML tables Working with dropdown list Conclusion Questions 1. Frames, Alerts, and Action Class Structure Objective Working with frame Working with alerts Action class
📄 Page 7
Conclusion Questions 1. Page Object Model Structure Objective Page Object Model (POM) Implementing the POM Conclusion Questions 1. Selenium-Grid Structure Objective Selenium-Grid Setting up the hub Setting a Chrome node on Windows machine Setting a Firefox node on Windows machine Executing tests in parallel Desired capabilities Conclusion Questions CHAPTER 1 Introduction to Selenium Software testing refers to a set of processes and procedures which help us identify whether the product at hand is getting built as per expectation or not. If we find any deviations we log them as defect, and in the subsequent releases we perform regression testing, retest the bugs, and eventually we are able to release a build to the market with an acceptable bug list. These regression tests, which we have to perform with every release cycle, are mandatory as well as monotonous in nature, which makes them an ideal candidate for test automation. There are many tools available in the market which allows us to automate our web applications, both commercial and open source. We have tools like UFT, RFT, Silk, Watir, Selenium, and others. Of these, Selenium, which is an open source functional testing tool for web applications, is the most popular. In this chapter we will introduce it. Structure History of Selenium Benefits of Selenium Components of Selenium Architecture of Selenium Objective In this chapter, we are going to learn about Selenium as a test automation tool--the reason for its popularity. We are also going to learn about the architecture of Selenium to understand how it executes tests on browsers. History of Selenium Selenium was created by Jason Huggins , while he was working at Thoughtworks in 2004. It was then called JavaScriptTestRunner . It was used to test an internal time and expense application . It was later released to the open source community as Selenium. It was named Selenium because it
📄 Page 8
overcame the shortcomings of another competitor that was made by an organization Mercury. Selenium as a chemical is used to treat Mercury poisoning. The main website of Selenium is http://seleniumhq.org/ , which is shown in the following screenshot. Here, you will find all the information related to the Selenium tool: Figure 1.1 There are different tabs on this web page, let’s have a look at what each represents: Projects: This tab basically lists the four projects, which make the Selenium tool. The Selenium IDE, Selenium RC, Selenium WebDriver, and Selenium Grid. We will talk in detail about these components in the coming chapters. Download: This tab, lists the various downloadthat are required while setting up our system for using the tool. Documentation: It provides detailed help that may be required to learn Selenium. It also provides code examples, in different programming languages, which Selenium supports. It is very well written, and should be a one-stop solution for all Selenium-related queries. Support: The support page provides information on chat, user groups, and the organization that is providing commercial support for the Selenium tool. About: The about section talks about news, events, history of Selenium and how one can get involved in the Selenium activities. Benefits of Selenium Selenium is one of the most popular open-source functional test automation tools for web applications. The reason for its popularity is due to the following: It supports multiple programming languages. You can code in Java, C#, Python, Ruby, and Perl. It supports automation of multiple browsers like IE, Firefox, Chrome, and Safari. It supports multiple operating systems like Windows, Mac, and Linux. It is available free of cost, It has a strong and active user community, which is very helpful.
📄 Page 9
Figure 1.2 Components of Selenium Selenium is not a one-test automation tool, but a group of four different tools, which are listed as follows, along with their usage: Selenium IDE: It is a tool used for recording and playing back scripts. It currently supports both Firefox and Chrome browsers. You can procure the tool from this link: https://www.seleniumhq.org/selenium-ide/ Selenium RC: It was also known as Selenium 1.0. Although no longer supported, it was a combination of aSelenium server and a client, which allowed automation of any browser on any operating system. SeleniumWebDriver: Also known as Selenium 2.0, whose 3.0 version is now available. It uses the technology of WebDriver API, where every browser has the capability through its API to automate itself. Currently the Selenium versions are released through the WebDriver technique of browser automation. Selenium Grid: It uses server component from the Selenium RC, and executes it in two different modes as hub and node. This allows executions of multiple tests simultaneously, which saves time and cost. Architecture of Selenium The main component of Selenium which is used in projects for automation is the Selenium WebDriver. We are going to discuss its architecture, which has four main components, as follows: The client libraries available in different programming languages JSON wire protocol over HTTP for communication to send commands from client to server WebDriver for every browser Browsers: Chrome, Firefox, IE, Opera, and more The following diagram shows the client libraries that are available in different programming languages. We create our scripts using them. These then send commands to the WebDriver server using the JSON wire protocol over HTTP. The WebDriver for each individual browser receives these commands and automates the browser, performing the action on them, thus achieving the task at hand:
📄 Page 10
Figure 1.3 Conclusion As we conclude this chapter, we understand the background of the test automation tool Selenium, its importance, and the reason behind its popularity in the test automation world. In our next chapter, we will be discussing a component of Selenium - the Selenium IDE. Questions Who created Selenium? Which Selenium component is used for record and playback? Why is Selenium popular? Which protocol does Selenium WebDriver use for communication? Is Selenium 1.0 still in use? CHAPTER 2 Selenium IDE In this chapter, we will discussthe Selenium IDE component. This component allows us to record and playback our tests. It is an integral component of the Selenium project, and has been recently upgraded and brought back into function with the help of the organization Applitools . Selenium IDE, also known as SIDE stands for Selenium Integrated Development Environment. It is one of the four projects of the Selenium ecosystem. The earlier version of Selenium IDE worked only on the Firefox browser. But the changes in the Firefox browser from version 55 didn’t allow Selenium IDE integration. At this juncture, Applitools helped Selenium community with a group of dedicated engineers ( https://github.com/seleniumHQ/selenium-ide/graphs/contributors ) and brought back Selenium IDE. The current version supports both Firefox and Chrome browsers. Structure Installing Selenium IDE
📄 Page 11
Walk through of the demo application Creating our first test Selenium IDE commands Objective The Selenium IDE component is used to record and play back tests. The current version, which supports both Firefox and Chrome browsers, has a rich feature list. It now allows running tests in parallel, supports JavaScript execution, allows usage of if conditions and many such cool things. To know more about it, read the article available here: https://applitools.com/blog/why-Selenium-ide-2019?utm_referrer=https://www.google.com/ Installation of Selenium IDE To install Selenium IDE, we have to follow the below-mentioned instructions: Open the Chrome browser and follow this link: https://www.seleniumhq.org/selenium-ide/ Here, we need to select the choice, Chrome or Firefox download. It will open a new browser window, with the option asking Add to Chrome as shown in the following screenshot: Figure 2.1 You need to select it. It will launch a popup, asking permission. Select Add extension as shown in the following screenshot: Figure 2.2 You will now be able to see Selenium IDE icon in your browser menu bar. After installing the Selenium IDE, we need to have a look at a demo web application. We will need this application to understand a few concepts of test automation using Selenium. So let us get introduced to it. Introduction to demo web application We will consider a demo web application, which is an ecommerce website. As we learn the concepts of test automation with Selenium using Python as a programming language, we will use functional flows from the web application. We will also look at a few other web applications as we learn to handle some specific html elements and deal with some specific scenarios. The URL of the demo application is: http://practice.bpbonline.com/catalog/index.php As you follow the URL, you will see the following screen:
📄 Page 12
Figure 2.3 Following are some of the specific functional flows in the application: Register the user Login and logout of user Change profile of user Change password of user Buy product Search product From the previous list of application business scenarios, we will take the login-logout business scenario as a sample one for our first record and playback script in Selenium IDE. Record script basically means with the help of Selenium IDE, we will capture the user actions as we perform the steps to login and then logout from the application. These will be captured by the Selenium IDE, as commands. It will then be played back, where Selenium IDE will launch the browser and will be able to perform the exact steps to login and logout of the application without any user intervention. Let's perform the following steps for login–logout: Open the application using the URL: http://practice.bpbonline.com/catalog/index.php Click on the My Account link. Fill in the user details; you can use the following user credentials: Username: bpb@bpb.com Password: bpb@123 Or you can also create your own account, by registering yourself and then using those credentials. Click on the Sign in button Click on the Log Off link Click on the Continue link Please note the above scenario is not a test case, as we have added no steps for the validation. There are only test steps. Record and playback in Selenium IDE
📄 Page 13
The following are the steps we need to perform for recording and playing back in Selenium IDE: Open Chrome browser. On it, click on the Selenium IDE icon. It will popup Selenium IDE window as shown in the following screenshot: Figure 2.4 Here, we will select Record a new test in a new project . Provide a project name in the next screen. Then in the next screen, provide the base URL for recording: Figure 2.5 Click here on START RECORDING . This will launch the browser with the application URL, and a message Selenium IDE is recording… . Now, whatever steps we perform on the browser, they will all be captured by the IDE. Check the following screenshot:
📄 Page 14
Figure 2.6 After performing all the steps, close the browser, and on the Selenium IDE, click the (stop button). Provide a name to the test, and save the project at a location in your system. After the login logout steps are captured, your test should look as follows: Figure 2.7 It could be possible that Selenium IDE may capture some other locator value for the same object which you see in the target field, which is absolutely fine, as long as you are able to replay the test successfully. There could be some other extra steps captured as Selenium IDE captures every mouse action, we need to delete those extra steps and only have those steps that match our manual action. Structure of Selenium IDE Test If we look at the above image, there are three columns which form a Selenium IDE test: Command , which provides information of the action being performed. Target , which talks about the object on which the action is to be performed.
📄 Page 15
Value , which talks about the data which will be used in the test. The commands of Selenium IDE fall under three categories, as follows: Action : Those commands, which change the state of the application. Assertion : Those commands which verify the state of the application after it is performed. There are two types of assertion commands that are as follows: Verify: These commands, if they fail, still allow execution of the next step in the test case. Assert: These commands, if they fail, don’t allow the execution of the next step in the test case. Accessor: Those commands which allow storage of value, or creation of variables to be used in the test. Let us write the login-logout scenario, this time with the validation steps: Open the application. Click My Account link. Type the E-mail address and Password . Click the Sign In button. Verify My Account Information text on the screen. Click on the Log Off link. Click on the Continue link. Verify Welcome to BPB Online text on the screen. To record the above scenario, we will perform the same steps as we did for the login-logout one, except for steps 5 and 8, where we will performthe following. Add the Command verify text during the recording, after you have logged in. Refer to the following screenshot: Figure 2.8 Now we will select the Target for that we click on the icon , and highlight and click the element, whose text we need to capture for verification. Refer to the following screenshot: Figure 2.9 We copy the text from here and put it in the Value field. So finally, our command would look like the following:
📄 Page 16
Figure 2.10 We will perform a similar action for step 8. Complete the steps of recording, and save the test for playback. As you playback the test, you will see all the steps in green. Now let us try to see the action of failure by changing the text of My Account Information to Junk . We will find out that although the test gets executed, but reports failure on the verification step. The following screenshot shows the behavior: Figure 2.11 Now, for the same test, if we change the Command from verify text , to assert text we will see that the execution will get halted at the step of failure. This is shown as follows:
📄 Page 17
Figure 2.12 So there are three states of execution here: Green: All pass Red: Fail White: Not executed Conclusion In thischapter, we discussed about the Selenium IDE component. We saw how we could use it for recording and playing back tests. We could use Selenium IDE for proofing concepts, to see if our application supports Selenium or not. Sometimes we struggle to find a locator for an object, in such cases recording the scenario in Selenium IDE is also helpful. In our next chapter we will discuss the concept of locators, what techniques Selenium uses to recognize objects on web application. Questions What browsers Selenium IDE supports? What does SIDE stands for? Explain the difference between verify and assert command? CHAPTER 3 Locators in Selenium Introduction When we try to automate a web application, there are two important steps to consider. One is to identify the object uniquely on which we would want to perform the action. The second is to perform the action on the identified object. To identify the object uniquely on the web page, Selenium provides us with some locator strategies. In this chapter we will discuss and explore them. Structure What is a locator?
📄 Page 18
Different types of locators Where are locators used? Objective When working with open source technology like Selenium, it is crucial for us to understand that as end user what strategy Selenium uses to identify an object on a page. As we are going to write scripts to automate applications at hand, we will have to provide object information using one of the locator strategies which Selenium will use to identify the object on the page so that the required action can be performed on it. What is a locator? Locator is a technique to identify the object on a page uniquely by using different identification methods. Once the object is identified, the action can be performed on it. Selenium provides us with the following locator techniques to identify the object on the page: ID NAME XPATH CSS DOM LINKTEXT PARTIALLINKTEXT To understand the different strategies of the locators, which Selenium uses to identify the object on the page, we will take the example of an HTML code snippet from our web application: http://practice.bpbonline.com/catalog/index.php my account page, which we see, when we click the My Account link of the home page. The idea is to explore the HTML code associated with E-mail Address field, Password field, and the Sign In button. So let us have a look at it: Figure 3.1 If we right click the HTML page, and select View page source . Refer to the following screenshot: Figure 3.2
📄 Page 19
We can see the HTML content associated with the web page. It is displayed as follows: Figure 3.3 As we have seen, the above HTML content is associated with three objects – username and password fields, and sign in button, let us try to understand the different locator strategies Selenium can use to identify them so that an action can be performed on them as our automation script executes. So, the following is explained below: ID: The ID locator is fetched from the ID attribute of an HTML element. If the HTML element of interest has an ID attribute, we use it to identify the object uniquely. The example of this is the Sign In button, which has the id = tdb1: Sign In NAME: This attribute is fetched from the NAME attribute of the HTML element. The data associated with this property of the HTML element is used to identify the object uniquely on the web page. Examples of this property areusername, and password fields: XPATH: The path traversed to reach the node of interest in an XML document is known as XPATH . To create the XPATH locator for an element, we look at an HTML document as if it is an XML document, and then traverse the path to reach it. The XPATH can either be a relative or an absolute one: A relative XPATH will be in relation to a landmark node. A node which has a strong identifier like an ID or NAME. It uses // in its path creation. Example: //input[@name="email_address"] An absolute XPATH starts from the root node HTML. It uses a single slash /. It is more prone to changes if the document structure undergoes changes during the development of the application, so it is generally avoided. Example: /HTML/body/div[2]/form[0]/table/tbody/tr[2]/input CSS: It stands for Cascading Style Sheets. We can use this as well to identify the objects uniquely on the web page. The syntax is as follows: If the HTML of the object has an ID attribute then, css=#ID , for example, css=#tdb1 Else, css=HTMLtag[prop=value], for example, css=input[name=’email_address’] DOM: It stands for Document Object Model. It allows object identification by using the HTML tag name associated with the object. LINKTEXT: Generally, whenever we encounter a link in the application we can use it to identify the object on the page. For example the My Account link can be identified using the same link text as seen in the web page PARTIAL LINK TEXT: We can also use a sub part of a complete text of the link to identify it on the web page and then perform actions on it. It is important to use an appropriate locator to identify the object on the page, which is unique, helps in quick identification of object and is robust to application changes during the development process. Generally, if the object HTML has IDor NAME we use it to identify the object on the page. Then we use XPATH, followed by CSS and the last option is DOM. If it is a link, we always use LINKTEXT or PARTIAL LINK TEXT to identify the element on the page. So ideally, this should be the approach we need to take. Conclusion In this chapter we discussed the concept of locators; we understood its various types. We also saw where and how they would be needed. These locator strategies are standard in Selenium. They are not going to get modified in any version, and have been consistent from old versions as well. Lastly, we need to keep in mind that the locator strategy we are choosing to identify the object has to be robust, and help to locate the object quickly on the page. In the next chapter we will learn the steps to setup Selenium and Eclipse IDE on Windows OS. Questions
📄 Page 20
What are the different locator strategies used in Selenium? Where can we find ID and NAME locators? What is the difference between relative and absolute XPATH locator? Create CSS locator for an object which has ID property available. How will you recognize a link in Selenium? CHAPTER 4 Installation and Setup In this chapter we will learn how to prepare our system with the required software so that we are able to write our test automation scripts and execute them. We will need to have Python, Java Runtime Engine (JRE), Eclipse IDE, PyDev. After setting upthesesoftware for creating scripts, we will need to set up Selenium in the system, and download the browser drivers for execution on the individual drivers. Structure Installation and setting up Installing Selenium Pythonmodule Installing JRE Installing Eclipse IDE Setting up PyDev Installing different drivers for Chrome, Firefox, and IE browser Running the very first program on three browsers Objective This chapter will help us to understand the steps to setup Selenium and Eclipse IDE on Windows system Installation and setting up Before we start to learn writing scripts to automate browser using Selenium WebDriver, we have to prepare our system with a few software. We will require the following: Python setup: https://www.python.org/downloads/ [download the latest version] [3.7] Java JRE: https://www.oracle.com/technetwork/Java/Javase/downloads/jre8-downloads-2133155.html , and install it on the system. Eclipse IDE: https://www.eclipse.org/downloads/ After we have installed and setup the above software in our system, we need to install PyDev in the Eclipse environment. To setup PyDev in the Eclipse environment, we have to perform the following actions: Open Eclipse. Click on Help | Install New Software . Provide in there, URL: http://pydev.org/updates The following screenshot shows the same:
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now
Back to List