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 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 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). In the definition part, self in…

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 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 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 – Special Functions in Python

Python Programming – Special Functions in Python The Python language provides two special functions, which can be used while using inheritance. These functions and their description is given in Table 11.1. The programming example for these functions is also given in Code 11.7., the output of which apparently makes clear the use of these functions. Function Description issubclass(child, parent) Returns a boolean result; either true or false, true if the child is indeed a subclass of the superclass parent isinstance(obj, Class) Returns a boolean result; either true or false, true if obj is indeed an instance of Class or a subclass of Class   Code: 11.7. Illustration of ininstance( ) and issubclass( ) functions. #Illustration of ininstance( ) and issubclass( ) functions class student: #base class ‘A student class’ class marks(student): #derived class ‘A marks class’ class result(marks): # new derived class A result class’ r1=result() r2=student() print(issubclass(result, marks)) print(issubclass(student, marks)) print(isinstance(rl, result)) print(isinstance(r2, result)) Output True False True False Python Tutorial

Python Programming – Method Overriding in Python

Python Programming – Method Overriding in Python Method overriding is one of the important concepts to consider while using inheritance in Python. As we see in the previous programming Code 11.1. for single inheritance that the __init__() method was defined both in the base class as well as derived class. When an object of a derived class is created then the __init_() method of derived class overrides that of the base class. That means, the __init__( ) of the derived class rectangle takes preference over the __init__( ) method of shape class. In order to overcome this issue, the __init__() method of the derived class is extended further to make a call to the __init__( ) method of base class. This is done by using shape, __init__() as shown in code 11.1. By invoking this way, a call to the__init__() method of shape class is made from the __init__() method of the derived class rectangle. Method overriding can also be resolved by using a built-in Python function super(). The super() function invokes the parent constructor method by itself without referring to the class name as mentioned in the call shape.__init__(). The super() function is used as follows: super().__init__() The programming…

Python Programming – Python Multilevel Inheritance

Python Programming – Python Multilevel Inheritance In the concept of multilevel inheritance, we see that a derived class can be further inherited by a new derived class. In other words, the features of the base class and a derived class can be inherited by a new derived class. The programming illustration of multilevel inheritance is given in Code 11.3. It is almost similar to the program code given for multiple inheritances, where there were two base classes and one derived class. Herein, with multilevel inheritance, we create a base class student with similar data members and functions as mentioned in the previous example. Then, we derive marks class from the student class that means the marks class inherits the traits of the student class. Further, we create a new derived class result, which is inherited from the marks class. Eventually, we have three classes with two levels student->marks->result. Thus, the result class contains the traits of both the class’s student as well as marks. Alike, previous program the object of the result class is created, by which all the operations are performed like earlier, and the result is displayed. Code: 11.3. Illustration of multilevel inheritance, #illustration of multilevel inheritance class…

Python Programming – Python Multiple Inheritance

Python Programming – Python Multiple Inheritance Multiple inheritances refer to two or more base classes and one derived class. In this type of inheritance, the features of multiple classes can be inherited into the derived class. The programming example of multiple inheritances is given in Code 11.2. This program contains three classes, two base classes student and marks and one derived class result, which inherits the traits of both students and marks classes. The student class having two data members name and role of the student and a class function display, which displays the values of name and roll no. The other base class marks contain three data members ml, m2, and m3 representing marks of three subjects. It also contains a class function display_marks(), which displays the marks of all three subjects. Now, the third derived class result, which is derived from both the base classes student and marks contains two data members total_marks and perc representing percentage. It also contains a class function display_result() to display the total_marks and percentage of a student. In this program, the object of the derived class result is created as r1. It is to be noted here that by the creation of…