Python Programming - Introduction to Selenium

Python Programming – Introduction to Selenium

Python Programming – 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 defects, 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…

Python Programming - Python Operator Overloading

Python Programming – Python Operator Overloading

Python Programming – Python Operator Overloading In the previous chapter, we learn the fundamentals of OOPS, i.e., the creation of user-defined data type classes and objects in Python. In this chapter, we will learn one of the significant features of object-oriented. programming structures (OOPS) that is operator overloading. As implied from the name, operator overloading means assigning special meaning to the existing operator to perform some intended task. In other words, the same operator exhibiting different meanings as per the situation is called operator overloading. For example, the “+’ operator is used to add two numbers, the same can be used for merging two lists and concatenating two strings. It indicates that the same ‘+’ operator can be used to perform different tasks based on the context in which it is being used. Similarly, two-class objects can also be added by using the concept of operator overloading by using the similar syntax that is used for adding two integer numbers. In the following sections, the concept of operator overloading is discussed in detail. Python Programming – Overloading Operator in Python Alike, the ‘+’ operator overloading, the subtraction operator can also be overloaded. The programming code for the same is given…

Python Programming - Overloading Relational Operators

Python Programming – Overloading Relational Operators

Python Programming – Overloading Relational Operators The relational operators can also be overloaded as arithmetic and bitwise operators. The Python language provides a list of built-in functions for overloading relational operators. As we know that relational operators are less than (<), less than equal to (<=), greater than (>), greater than equal to (>=), equal to (=), and not equal to (!=). Here in this section, we will demonstrate, how to overload greater than (>) relational operator. The programming illustration for the same is given in Code 12.4. In this program, we create a class distance with two data members a and b. Another built-in function __gt__() is defined in the class with two arguments self and obj. The__gt__()function is used to overload greater than the operator in Python. We create two objects dl and d2 of the class distance. The values of data members have been initialized through constructor __init__() while creating these two objects. Then, the two objects dl and d2 are compared by using the greater than operator (>), in the same manner in which two simple variables are compared, i.e., dl>d2. Basically, the call dl>d2 expands as dl. gt (d2). Quick Tip: Using Python’s Comparison Operators…

Python Programming - Overloading Bitwise Operators

Python Programming – Overloading Bitwise Operators

Python Programming – Overloading Bitwise Operators As we know that Python contains a rich set of operators. The bitwise operators can also be overloaded like arithmetic operators. Here in this section, we learn to overload bitwise and operator (‘&’)- The programming illustration to overload bitwise and (&) operator is given in Code 12.3. As we know that the bitwise and (&) works at the bit level and return true (1) only if both the bits are true (1), otherwise it returns false (0). In this program, we see that a Number class is created, which contains only one data member num. the__init__() method initialize the value of this variable for two objects n1 and n2. In order to overload, the bitwise and (&) operator the invocation is made as nl&n2, where n1 and n2 are the objects of class Number and the result is assigned to the third object n3. The invocation nl&n2 expands as n1. and (n2), where and Q is the built-in Python function for overloading bitwise and operator. In the definition part of this function, n1 represents the calling object that is self and n2 represents the object as argument i.e., obj. The computation is performed by…

Python Programming - Overloading '+’ Operator in Python

Python Programming – Overloading ‘+’ Operator in Python

Python Programming – Overloading ‘+’ Operator in Python Overloading the *+’ operator is quite simpler in Python than in C++. The overloaded + operator can add the values contained in two objects by following the same syntax that is used for adding two simple variables. The programming example to overload the arithmetic ‘+’ operator is given in Code 12.1. In this program, we see that a class complex is created with two member variables real and imag, which are initialized by using the __init__( ) constructor function. Then for overloading the plus “+’ operator the built-in Python function __add_( ) is used. This function is specifically meant for adding two objects, which signifies the concept of operator overloading. The user-defined function display(), displays the values of object variables. In this program, we create two objects cl and c2 of the class complex with initializing values of data members. Then, the values of class data members are displayed associated with these two objects cl and c2. Subsequently, the addition of two objects cl+c2 is performed by using the same syntax that is used for adding two simple variables. The result of cl+c2 is assigned to a third object c3. Then, the…

Python Programming - Inheritance

Python Programming – Inheritance

Python Programming – Inheritance In the previous chapter, we have learned the designing of classes and objects in Python. Reusability or inheritance is one of the most significant features of OOPS. It is a good practice to reuse something which already exists rather than creating the new one all over again. It would not save only time and energy but also increases reliability, as the already build code is previously tested and debugged. Alike, C++ and Java, Python classes also use the concept of inheritance. Inheritance enables us to define a class that takes all the functionality and features of the base class. The base class is known as the parent class or superclass and the derived class is also known as the child class or subclass. Here in this section, we will learn the concept of using inheritance in detail. The general syntax of using inheritance is given as follows: class DerivedClass(BaseClass): Body of Derived Class The above syntax is quite simpler than that is used in C++ and Java for inheriting classes. The derived class represents the new class and the BaseClass represents the old class followed by a colon. The body of the class begins with indentation.…

Python Programming - Exception Handling

Python Programming – Exception Handling

Python Programming – Exception Handling When an exception occurs, the current process stops and passes it to the calling process until it is handled to obtain the result. If not handled properly, the program crashes and the intended output is not obtained and the program comes to a halt. Try, Except, and Finally In Java, try and catch blocks are used to handle exceptions, in Python, exceptions can be handled using a try and except statements. A critical operation that can raise an exception is included in the try clause and the code for handling the exception is included in except clause. Consider a programming example in Code: 8.3. In this program, we see that the user is asked to input an integer number and then its reciprocal will be computed. In the output, we see that if the user enters a character or float (real) value then the ValueError exception occurs, which is caught by the except clause, and the appropriate error message “please try again” along with the exception is displayed to the user. The while loop executes until the user supplies a valid integer value as an input for the computation of valid reciprocal. The critical portion…

Python Programming - Python Packages

Python Programming – Python Packages

Python Programming – Python Packages As we see in Windows, all the files are stored in a hierarchical fashion. This feature is provided to organize the files to access them later on efficiently rather than searching them here and there. Similar kinds of files are placed in the same directory. For example, pictures are stored in the directory called photos or pictures. Music files can be stored in directory names songs or music. Similarly, video files are stored in a video directory. Analogous to the above, when a program becomes larger, we can divide it into different modules as described in the above sections. Python provides packages for managing directories and modules for files. Similar modules can be placed in one package, which makes maintenance of the project or program under development easier. As a directory can contain subdirectories, similarly a package can contain sub-packages. The directory containing the package must contain a file named init _ py. This is required as Python identifies it as a package due to the init.py file. This file can be empty or we place the initialization code for the package to execute. Python Programming – Python Modules Python Programming – Functions Python Programming…

Python Programming - Python Strings

Python Programming – Python Strings

Python Programming – Python Strings The collection or sequence of characters is called a string. As Python list contain a sequence of heterogeneous data elements, the string contains a contiguous sequence of characters, which can be alphabets or special characters. We know that computer understands only binary data either 0 or 1. All the data that we type and use in the computer is first converted into binary form. Therefore, the strings that are alphabetical or character data is also converted into equivalent binary code using some encoding technique such as ASCII or Unicode encoding. In Python, Unicode encoding is used for strings. The Unicode encoding is used to bring uniformity as it includes all the characters of all the languages. The string is a useful data element of Python as it is used to store character values such as name, city, class, etc. Creating a String in Python The creation of string is rather simple in Python. The programmer does not need to specify the string size as in C, C++, and Java. The programmer can create a string of any size. The programming illustration of creating a string is given in Code 5.44. In this program, three strings…

Python Programming - Python Dictionary

Python Programming – Python Dictionary

Python Programming – Python Dictionary In the previous sections, we learned sequence data types such as Python lists, tuples, and sets. Herein, in this section, we learn Python dictionary. Python dictionary is a compound data type, which contains a pair comprising of a key-value corresponding to the value of an element. Or in other words, every data element of a dictionary is associated with a key value. The data element of a dictionary can be retrieved or accessed through its key value. Creating a Dictionary The Python dictionary is a collection of unordered pairs of key values and their associated data elements. Dictionary contains heterogeneous kind of data, where key must be unique and of an immutable type. In Python, a dictionary can be created as shown in Code 5.38. In this program, Python dictionary is created in four ways. The elements of a dictionary must be enclosed in curly braces {}. Initially data_dictl is created containing two keys ‘Name’ and ‘Rollnp’ with corresponding values. Then, a dictionary data_dict2 is created, which contains list as one its elements. Subsequently, data_dict3 is created using a Python built-in method dict( ), which encloses the values of dictionary keys and their values. At…