Selenium (Java)

December 16, 2016 | Author: Veera Karthik G | Category: N/A
Share Embed Donate


Short Description

Java...

Description

CONTENTS 1.Framework a.General Data Driven Framework b. Testing Web Driver Data Driven Framework 2.JAVA 3.Sample Programs on Java 4.Interview Questions on Java 5.Selenium RC 6.TestNG and JUnit 7.Web Driver. 8.Sample Programs on Selenium 9.Interview Question on Selenium

Page | 2 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Framework General Data Driven Framework & TestNG WebDriver Data Driven Framework Aim or Goals of Framework: ¾ Tests With Multiple Suite ¾ Run Selective Test Suite ¾ Run Selected Test Cases ¾ Generate Logs ¾ Repeat a test case – Parameterize ¾ Execute Test cases with multiple sets of data ¾ Run complete Project in Console or command line ¾ BAT file for execution through ANT ¾ Generate Html Reports using TestNG ¾ Generate XSLT Reports or Pie Graphs for Result

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 3 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

Prepare Test Suites - TestSuite.xlsx

 

Prepare Test Cases and Test data xls for Test Suites. One xls file per test suite Introduce Runmodes Make eclipse Java project make package- suiteA make package- suiteB make package- suiteC make package- logs make package- util make package- base, in base create initialize function and declare global variables like xls files with path. make package- config, create OR.properties and config.properties make package- xls Put xls files in xls Prepare config.properties and OR.properties

Make TestUtil.java in util package Prepare function to check Runmode of a Test Suite - isSuiteRunnable ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 4 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Prepare function to check Runmode of a Test Case in Test Suite isTestCaseRunnable Prepare function to return test data for a test case in two dim array getData Make TestBase.java Prepare initialize function to initialize the logs, Make TestSuiteBase.java class in each test Suite package Prepare all test classes in all suites Prepare testng.xml and individual suite xmls Batch run and check empty project Implement @BeforeSuite and @BeforeTest functions in Project to check Runmode of Suite and Test Batch run and check empty project Implement @dataprovider Functions in all test classes - PARAMETRIZING THE TEST CASES Implement build.xml and run project through command prompt Make a .bat file to run the frameworkDouble clicking on bat file your will or complete script will execute and generate the reports and logs.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 5 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Framework is Class Room Training OnlyPlease Contact Below Contact Number ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 6 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

             

JAVA

 

 

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 7 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

 

INDEX of JAVA  1. Introduction to Java 1.1. History 1.2. Java Virtual machine 1.3. Java Runtime Environment vs. Java Development Kit 1.4. Characteristics of Java 1.5. Development Process with Java 1.6. Classpath 2. Installation of Java 3. Your first Java program 3.1. Write source code 3.2. Compile and run your Java program 3.3. Using the classpath 4. Integrated Development Environment 5. Your first graphical user interface application (GUI) 6. Statements 6.1. Boolean Operations 6.2. Switch Statement 7. Working with Strings 8. Type Conversion 8.1. Conversion to String 8.2. Conversion from String to Number 8.3. Double to int 8.4. SQL Date conversions 9. Cheat Sheets 9.1. Working with classes 9.2. Working with local variable ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 8 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

10. Thank you  

 

11. Questions and Discussion 12. Links and Literature

1. Introduction to Java 1.1. History Java is a programming language created by James Gosling from Sun Microsystems in 1991. The first publicly available version of Java (Java 1.0) was released in 1995. Over time new enhanced versions of Java have been released. The current version of Java is Java 1.7 which is also known as Java 7. From the Java programming language the Java platform evolved. The Java platform allows that the program code is written in other languages than the Java programming language and still runs on the Java virtual machine.

1.2. Java Virtual machine The Java virtual machine (JVM) is a software implementation of a computer that executes programs like a real machine. The Java virtual machine is written specifically for a specific operating system, e.g. for Linux a special implementation is required as well as for Windows. Java programs are compiled by the Java compiler into so-called bytecode. The Java virtual machine interprets this bytecode and executes the Java program.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 9 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1.3. Java Runtime Environment vs. Java Development Kit Java comes in two flavors, the Java Runtime Environment (JRE) and the Java Development Kit (JDK). The Java runtime environment (JRE) consists of the JVM and the Java class libraries and contains the necessary functionality to start Java programs. The JDK contains in addition the development tools necessary to create Java programs. The JDK consists therefore of a Java compiler, the Java virtual machine, and the Java class libraries.

1.4. Characteristics of Java The target of Java is to write a program once and then run this program on multiple operating systems. Java has the following properties: •

Platform independent: Java programs use the Java virtual machine as abstraction and do not access the operating system directly. This makes Java programs highly portable. A Java program which is standard complaint and follows certain rules can run unmodified on all supported platforms, e.g. Windows or Linux.



Object-orientated programming language: Except the primitive data types, all elements in Java are objects.



Strongly-typed programming language: Java is strongly-typed, e.g. the types of the used variables must be pre-defined and conversion to other objects is relatively strict, e.g. must be done in most cases by the programmer.



________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 10 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

  • •

Interpreted and compiled language: Java source code is transferred into the bytecode format which does not depend on the target platform. These bytecode instructions will be interpreted by the Java Virtual machine (JVM).



The JVM contains a so called Hotspot-Compiler which translates performance critical bytecode instructions into native code instructions.



Automatic memory management: Java manages the memory allocation and deallocation for creating new objects. The program does not have direct access to the memory. The so-called garbage collector deletes automatically objects to which no active pointer exists.

The Java syntax is similar to C++. Java is case sensitive, e.g. the variables myValue and myvalue will be treated as different variables.

1.5. Development Process with Java The programmer writes Java source code in a text editor which supports plain text. Normally the programmer uses an Integrated Development Environment (IDE) for programming. An IDE supports the programmer in the task of writing code, e.g. it provides auto-formating of the source code, highlighting of the important keywords, etc. At some point the programmer (or the IDE) calls the Java compiler (javac). The Java compiler creates the bytecode instructions. . These instructions are stored in .class files and can be executed by the Java Virtual Machine.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 11 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1.6. Classpath The classpath defines where the Java compiler and Java runtime look for .class files to load. This instructions can be used in the Java program. For example if you want to use an external Java library you have to add this library to your classpath to use it in your program.

2. Installation of Java Java might already be installed on your machine. You can test this by opening a console (if you are using Windows: Win+R, enter cmd and press Enter) and by typing in the following command: java -version If Java is correctly installed, you should see some information about your Java installation. If the command line returns the information that the program could not be found, you have to install Java. The central website for installing Java is the following URL: http://java.com If you have problems installing Java on your system, search via Google for How to install JDK on YOUR_OS. This should result in helpful links. Replace YOUR_OS with your operating system, e.g. Windows, Mac OS X, etc.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 12 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

3. Your first Java program 3.1. Write source code The following Java program is developed under Microsoft Windows. The process on other operating system should be similar but is not covered in this description.

Select a new directory which will contain your Java code. I will use the c:\temp\java which will be called javadir in the following description. Open a text editor which supports plain text, e.g. Notepad under Windows and write the following source code. You can start Notepad via Start → Run → Notepad and by pressing enter. // A small Java program public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 13 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Save the source code in your javadir directory with the HelloWorld.java filename. The name of a Java source file must always equals the class name (within the source code) and end with the .java extension. In this example the filename must be HelloWorld.java because the class is called HelloWorld. 

3.2. Compile and run your Java program

Switch to the command line, e.g. under Windows Start-> Run -> cmd. Switch to the javadir directory with the command cd javadir, for example in my case cd c:\temp\java. Use the command dir to see that the source file is in the directory. javac testjava.java Check the content of the directory with the command "dir". The directory contains now a file "testjava.class". If you see this file you have successfully compiled your first Java source code into bytecode. By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with the -d compiler flag. ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 14 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

Run -> cmd. Switch to the directory jardir.

 

To run your program type in the command line: java testjava

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 15 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

The system should write "learning selenium" on the command line.

 

3.3. Using the classpath You can use the classpath to run the program from another place in your directory. Switch to the command line, e.g. under Windows Start-> Run -> cmd. Switch to any directory you want. Type: java learning selenium

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 16 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

If you are not in the directory in which the compiled class is stored then the system should result an error message Exception in thread "main" java.lang.NoClassDefFoundError: test/TestClass To use the class type the following command. Replace "mydirectory" with the directory which contains the test directory. You should again see the " learning selenium " output. java -classpath "mydirectory" learning selenium

4. Integrated Development Environment The previous chapter explained how to create and compile a Java program on the command line. A Java Integrated Development Environment (IDE) provides lots of ease of use functionality for creating java programs. There are other very powerful IDE's available, for example the Eclipse IDE. . In the following I will say "Create a Java project SomeName". This will refer to creating an Eclipse Java project. If you are using a different IDE please follow the required steps in this IDE.

4.1. To Install Java:  1. Go to google and type “download JDK” 2. Now select your OS compatibility (32bit or 64bit) 3. Install in your system.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 17 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

     

4.2. To Configure Eclipse IDE:  1. Go to google and type “download Eclipse”   2. Now select your OS compatibility (32bit or 64bit)  3. Save in your system and open folder and send shortcut to desktop  ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 18 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

         

 

             ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 19 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

             

Click on short cut it displays like below: Now click on workbench link.

   

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 20 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

5. Your first graphical user interface application (GUI) Introduction of Eclipse and eclipse GUI. Now open eclipse short cut from the desktop as above explained. It’ll displays like below screenshot.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 21 QEdg ge TECHNO OLOGIES: # 204, 2 Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491. nd

 

c a new Javva proje ect : Using Eclipse create Step 1: 1. Go to o file menu ÆNewÆsselect Java a Project _______ __________ __________ _________ __________ __________ __________ __________ ____

QEdg ge TECHNO OLOGIES: # 204, 2nd Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491.  

Page | 22 QEdg ge TECHNO OLOGIES: # 204, 2 Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491. nd

 

Step 2: Type Pro oject Name e and click on finish button. b

_______ __________ __________ _________ __________ __________ __________ __________ ____

QEdg ge TECHNO OLOGIES: # 204, 2nd Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491.  

Page | 23 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Create Package: ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 24 QEdg ge TECHNO OLOGIES: # 204, 2 Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491. nd

 

Step 3: • •

Now click on prroject folde er and selecct src folde er Go to o file menu u or click bu utton and select s pack kage

_______ __________ __________ _________ __________ __________ __________ __________ ____

QEdg ge TECHNO OLOGIES: # 204, 2nd Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491.  

Page | 25 QEdg ge TECHNO OLOGIES: # 204, 2 Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491. nd

 

Step 4: •

Type e package name n and click c on finish button.

_______ __________ __________ _________ __________ __________ __________ __________ ____

QEdg ge TECHNO OLOGIES: # 204, 2nd Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491.  

Page | 26 QEdg ge TECHNO OLOGIES: # 204, 2 Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491. nd

 

Creatte Classs: Step 5: Select package p fold der and go to file men nu and click on menu button and d select cla ass

_______ __________ __________ _________ __________ __________ __________ __________ ____

QEdg ge TECHNO OLOGIES: # 204, 2nd Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491.  

Page | 27 QEdg ge TECHNO OLOGIES: # 204, 2 Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491. nd

 

Step 6: 1. Type e class Nam me, Ex: BasicPrograms,, spaces it won’t allow w. 2. Selecct public sttatic void main m check box 3. Click k on finish button. b

_______ __________ __________ _________ __________ __________ __________ __________ ____

QEdg ge TECHNO OLOGIES: # 204, 2nd Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491.  

Page | 28 QEdg ge TECHNO OLOGIES: # 204, 2 Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491. nd

 

It disp plays like belo ow.

_______ __________ __________ _________ __________ __________ __________ __________ ____

QEdg ge TECHNO OLOGIES: # 204, 2nd Floor, Nagassuri Plaza, Ameerpet, Hyderabad d. Email: info@qedge etech.com,, ph:040-64 4644491/92 2, 77029444 491.  

Page | 29 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

6. Statements The following describes certain aspects of the software.

6.1. Boolean Operations Use == to compare two primitives or to see if two references refers to the same object. Use the equals() method to see if two different objects are equal. && and || are both Short Circuit Methods which means that they terminate once the result of an evaluation is already clear. Example (true || ....) is always true while (false && ...) always false is. Usage: (var !=null && var.method1()..) ensures that var is not null before doing the real check. Table 1. Boolean Operations ==

Description Is equal, in case of objects the system checks if the reference variable point to the same object, is will not compare the

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 30 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Operations

Description content of the objects!

&&

And

!=

is not equal, similar to the "=="

a.equals(b)

Checks if string a equals b

a.equalsIgnoreCase(b) Checks if string a equals b while ignoring lower cases If (value ? false : true) {}

Return true if value is not true. Negotiation

6.2. Switch Statement The switch statement can be used to handle several alternatives if they are based on the same constant value. switch (expression) { case constant1: command; break; // Will prevent that the other cases or also executed case constant2: command; break; ... default: } Example: switch (cat.getLevel()) { ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 31 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

case 0: return true; case 1: if (cat.getLevel() == 1) {

if (cat.getName().equalsIgnoreCase(req.getCategory())) { return true; } } case 2: if (cat.getName().equalsIgnoreCase(req.getSubCategory())) { return true; } }

7. Working with Strings The following lists the most common string operations Table 2. . Command

Description

text1.equals("Testing");

return true if text1 is equal to "Testing". The test is case sensitive.

text1.equalsIgnoreCase("Testing");

return true if text1 is equal to "Testing". The test is not case sensitive. For example it would also be true for "testing"

StringBuffer str1 = new StringBuffer(); Define a new String with a variable length. str.charat(1);

Return the character at position 1. (Strings starting with 0)

str.substring(1);

Removes the first characters.

str.substring(1, 5);

Gets the substring from the second to the fifths character.

str.indexOf(String)

Find / Search for String Returns the index of the first occurrence of the specified string.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 32 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Command

Description

str.lastIndexOf(String)

Returns the index of the last occurrence of the specified string. StringBuffer does not support this method. Hence first convert the StringBuffer to String via method toString.

str.endsWith(String)

Returns true if str ends with String

str.startsWith(String)

Returns true if str starts with String

str.trim()

Removes spaces

str.replace(str1,str2)

Replaces all occurrences of str1 by str2

str.concat(str1);

Concatenates str1 at the end of str.

str.toLowerCase() str.toUpperCase()

Converts string to lower- or uppercase

str1 + str2

Concatenate str1 and str2

String[] zeug = myString.split("-"); String[] zeug = myString.split("\\.");

Spits myString at / into Strings. Attention: the split string is a regular expression, so if you using special characters which have a meaning in regular expressions you need to quote them. In the second example the . is used and must be quoted by two backslashes.

8. Type Conversion If you use variables of different types Java requires for certain types an explicit conversion. The following gives examples for this conversion.

8.1. Conversion to String Use the following to convert from other types to Strings // Convert from int to String String s1 = String.valueOf (10); // "10" String s2 = // Convert from double to String String.valueOf (Math.PI); // "3.141592653589793" ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 33 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

// Convert from boolean to String

 

String s3 = String.valueOf (1 < 2); // "true" // Convert from date to String String s4 = String.valueOf (new Date()); // "Tue Jun 03 14:40:38 CEST 2003"

8.2. Conversion from String to Number // Conversion from String to int int i = Integer.parseInt(String); // Conversion from float to int float f = Float.parseFloat(String); // Conversion from double to int double d = Double.parseDouble(String); The conversion from string to number is independent from the Locale settings, e.g. it is always using the English notification for number. In this notification a correct number format is "8.20". The German number "8,20" would result in an error. To convert from a German number you have to use the NumberFormat class. The challenges is that if the value is for example 98.00 then the NumberFormat class would create a Long which cannot be casted to Double. Hence the following complex conversion class. private Double convertStringToDouble(String s) { Locale l = new Locale("de", "DE"); Locale.setDefault(l); NumberFormat nf = NumberFormat.getInstance(); Double result = 0.0; try { if (Class.forName("java.lang.Long").isInstance(nf.parse(s))) { ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 34 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

result = Double.parseDouble(String.valueOf(nf.parse(s))); } else { result = (Double) nf.parse(new String(s)); } } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (ParseException e1) { e1.printStackTrace(); } return result; }

8.3. Double to int int i = (int) double;

9. Cheat Sheets The following can be used as a reference for certain task which you have to do.

9.1. Working with classes While programming Java you have to create several classes, methods, instance variables. The following uses the package test.

Table 3. What to do

How to do it package test;

Create a new class called MyNewClass.

public class MyNewClass {

Create a new attribute (instance variable) "var1" in MyNewClass with type String

} package test;

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 35 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

What to do

How to do it public class MyNewClass { private String var1; } package test;

Create a Constructor for "MyNewClass which has a String parameter and assigns the value of it to the "var1" instance variable.

public class MyNewClass { private String var1; public MyNewClass(String para1) { var1 = para1; // or this.var1= para1; } } package test; public class MyNewClass { private String var1;

Create a new method "doSomeThing" in class which do not return a value and has no parameters

public MyNewClass(String para1) { var1 = para1; // or this.var1= para1; } public void doSomeThing() { } } package test;

Create a new method "doSomeThing2" in class which do not return a value and has two parameters, a int and a Person

public class MyNewClass { private String var1; public MyNewClass(String para1) { var1 = para1; // or this.var1= para1; }

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 36 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

What to do

How to do it public void doSomeThing() { } public void doSomeThing2(int a, Person person) { } } package test; public class MyNewClass { private String var1; public MyNewClass(String para1) { var1 = para1; // or this.var1= para1; } public void doSomeThing() {

Create a new method "doSomeThing2" in class which do return an int value and has three parameters, two Strings and a Person

} public void doSomeThing2(int a, Person person) { } public int doSomeThing3(String a, String b, Person person) { return 5; // Any value will do for this example } } package test;

Create a class "MyOtherClass" with two instance variables. One will store a String, the other will store a Dog. Create getter and setter for these variables. public class MyOtherClass { ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 37 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

What to do

How to do it String myvalue; Dog dog; public String getMyvalue() { return myvalue; } public void setMyvalue(String myvalue) { this.myvalue = myvalue; } public Dog getDog() { return dog; }

}

public void setDog(Dog dog) { this.dog = dog; }

9.2. Working with local variable A local variable must always be declared in a method.

Table 4. What to do

How to do it

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 38 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

What to do

How to do it

Declare a (local) variable of type string.

String variable1;

Declare a (local) variable of type string and assign "Test" to it. Declare a (local) variable of type Person

String variable2 = "Test"; Person person;

Declare a (local) variable of type Person, create a new Object and assign the variable to this object. Declare a array of type String

Person person = new Person(); String array[];

Declare a array of type Person and create an array for this variable which can hold 5 Persons. Assign 5 to the int variable var1 (which was already declared); Assign the existing variable pers2 to the exiting variable pers1; Declare a ArrayList variable which can hold

Person array[]= new Person[5];

var1 = 5;

pers1 = pers2;

ArrayList persons;

objects of type Person Create a new ArrayList with objects of type Person and assign it to the existing variable

persons = new ArrayList();

persons Declare a ArrayList variable which can hold objects of type Person and create a new Object for it.

ArrayList persons = new ArrayList();

Java Interview Programs: ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 39 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Java basic program- Program-1: package Pack1;    public class JavaBasic_Commands {        public static void main(String[]args){        System.out.println("learning selenium");        int a=10;   //32bit   it can store the numeric values        int b=11,c=12;    long l=67;     //64 bit it can store the numeric values          double d=45.6;   //it can any decimal values        double d1=35;     System.out.println(a+d);        char c1='j';   //it can strore a single char        String str="selenium";          System.out.println(str);        }  }     

Out put: learning selenium  ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 40 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

55.6  selenium

Program-2: package Pack1;    public class String_functions {        public static void main (String[]args){  String str="learning";  //it can store no.of chars  or group of words,       String str1="the rain have been started";            System.out.println(str+"===="+str1);              int length=str1.length();        System.out.println(length);                    //String[] test=str1.split(" ");              }  }

Out put: learning====the rain have been started  26 

For loops Program-3: package Pack1;    public class For_Loops {    public static void main(String[] args) {  ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 41 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

  //int i=5;      for(int i=5;i>=0;i‐‐){        //initialization,  condition, incremental or decremental      System.out.print(i);        }    }  }  Out put:  5  4  3  2  1  0   

If conditions programs-4: package Pack1;  public class If_Conditions {      public static void main (String[]args){      /*int a=120, b=25;      if(a>b){        System.out.println("a is the greatest value=  "+a);      }else{        System.out.println("b is the greatest value=  "+b);  //type syso+contl+spacebar      }      */      // + ‐ / % &             int a=14, b=13, c=45;            if(a>b && a>c){      System.out.println("a is the greatest value= "+a);        }else if(b>c){  ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 42 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

    "+b);              "+c);        }  }   

Output:

 

System.out.println("b is the greatest value= 

    }else{    System.out.println("c is the greatest value=  } 

c is the greatest value= 45 

While loop - programs-5: package Pack1;  public class While_Loop {    public static void main(String[] args) {    int i=1;  //initializtion    while(i TestNG can do more than bundle class testing, it can bundle method testing as well. With TestNG unique “Grouping” concept, every method is tie to a group, it can categorize tests according to features. For example, ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 110 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Here is a class with four methods, three groups (method1, method2 and method3) @Test(groups="method1") public void testingMethod1() { System.out.println("Method - testingMethod1()"); } @Test(groups="method2") public void testingMethod2() { System.out.println("Method - testingMethod2()"); } @Test(groups="method1") public void testingMethod1_1() { System.out.println("Method - testingMethod1_1()"); } @Test(groups="method4") public void testingMethod4() { System.out.println("Method - testingMethod4()"); } With the following XML file, we can execute the unit test with group “method1” only. ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 111 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd



 

With “Grouping” test concept, the integration test possibility is unlimited. For example, we can only test the “DatabaseFuntion” group from all of the unit test classes.

6. Parameterized Test The “Parameterized Test” means vary parameter value for unit test. This feature is implemented in both JUnit 4 and TestNG. However both are using very different method to implement it. JUnit 4 The “@RunWith” and “@Parameter” is use to provide parameter value for unit test, @Parameters have to return List[], and the parameter will pass into class constructor as argument. @RunWith(value = Parameterized.class) public class JunitTest6 { private int number; public JunitTest6(int number) { this.number = number; } ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 112 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

@Parameters public static Collection data() { Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } }; return Arrays.asList(data); } @Test public void pushTest() { System.out.println("Parameterized Number is : " + number); } } It has many limitations here; we have to follow the “JUnit” way to declare the parameter, and the parameter has to pass into constructor in order to initialize the class member as parameter value for testing. The return type of parameter class is “List []”, data has been limited to String or a primitive value for testing. TestNG XML file or “@DataProvider” is use to provide vary parameter for testing. XML file for parameterized test. Only “@Parameters” declares in method which needs parameter for testing, the parametric data will provide in TestNG’s XML configuration files. By doing this, we can reuse a single test case with different data sets and even get different results. In addition, even end user, QA or QE can provide their own data in XML file for testing. Unit Test public class TestNGTest6_1_0 { ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 113 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

@Test @Parameters(value="number") public void parameterIntTest(int number) { System.out.println("Parameterized Number is : " + number); } } XML File @DataProvider for parameterized test. While pulling data values into an XML file can be quite handy, tests occasionally require complex types, which can’t be represented as a String or a primitive value. TestNG handles this scenario with its @DataProvider annotation, which facilitates the mapping of complex parameter types to a test method. @DataProvider for Vector, String or Integer as parameter ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 114 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

@DataProvider   

public Object[][] login(){ 

 

 

Object[][] data=new Object[2][2]; 

 

 

 

 

 

data[0][0]="uname"; 

 

 

data[0][1]=343453; 

 

 

 

 

 

data[1][0]="uname1"; 

 

 

data[1][1]=345645; 

 

 

 

 

 

return data; 

 

 

 

 



  @DataProvider for object as parameter P.S “TestNGTest6_3_0” is an simple object with just get set method for demo. @Test(dataProvider = "Data-Provider-Function") public void parameterIntTest(TestNGTest6_3_0 clzz) { System.out.println("Parameterized Number is : " + clzz.getMsg()); System.out.println("Parameterized Number is : " + clzz.getNumber()); } //This function will provide the patameter data @DataProvider(name = "Data-Provider-Function") public Object[][] parameterIntTestProvider() {

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 115 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

TestNGTest6_3_0 obj = new TestNGTest6_3_0(); obj.setMsg("Hello"); obj.setNumber(123); return new Object[][]{ {obj} }; } TestNG’s parameterized test is very user friendly and flexible (either in XML file or inside the class). It can support many complex data type as parameter value and the possibility is unlimited. As example above, we even can pass in our own object (TestNGTest6_3_0) for parameterized test

7. Dependency Test The “Parameterized Test” means methods are test base on dependency, which will execute before a desired method. If the dependent method fails, then all subsequent tests will be skipped, not marked as failed. JUnit 4 JUnit framework is focus on test isolation; it did not support this feature at the moment. TestNG It use “dependOnMethods “ to implement the dependency testing as following @Test public void method1() { System.out.println("This is method 1"); } ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 116 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

@Test(dependsOnMethods={"method1"}) public void method2() { System.out.println("This is method 2"); } The “method2()” will execute only if “method1()” is run successfully, else “method2()” will skip the test.

WebDriver ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 117 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1. What is WebDriver? WebDriver uses a different underlying framework from Selenium’s javascript Selenium-Core. It also provides an alternative API with functionality not supported in Selenium-RC. WebDriver does not depend on a javascript core embedded within the browser, therefore it is able to avoid some long-running Selenium limitations. WebDriver’s goal is to provide an API that establishes ¾ A well-designed standard programming interface for web-app testing. ¾ Improved consistency between browsers. ¾ Additional functionality addressing testing problems not well-supported in Selenium 1.0. The Selenium developers strive to continuously improve Selenium. Integrating WebDriver is another step in that process. The developers of Selenium and of WebDriver felt they could make significant gains for the Open Source test automation

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 118 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

community be combining forces and merging their ideas and technologies. Integrating WebDriver into Selenium is the current result of those efforts.

2. When to Use WebDriver? One should use WebDriver when requiring improved support for ¾ Mult-browser testing including improved functionality for browsers not wellsupported by ¾ Selenium-1.0. ¾ Handling multiple frames, multiple browser windows, popups, and alerts. ¾ Page navigation. ¾ Drag-and-drop. ¾ AJAX-based UI elements.

3. About WebDriver: WebDriver is a tool for automating testing web applications, and in particular to verify that they work as expected. It aims to provide a friendly API that’s easy to explore and understand, which will help make your tests easier to read and maintain. It’s not tied to any particular test framework, so it can be used equally well with JUnit, TestNG or from a plain old “main” method. This “Getting Started” guide introduces you to WebDriver’s Java API and helps get you started becoming familiar with it. Start by Downloading the latest binaries and unpack them into a directory. From now on, we’ll refer to that as $WEBDRIVER_HOME. Now, open your favourite IDE and: ¾ Start a new Java project in your favourite IDE ¾ Add all the JAR files under $WEBDRIVER_HOME to the CLASSPATH

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 119 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

You can see that WebDriver acts just as a normal Java library does: it’s entirely selfcontained, and you don’t need to remember to start any additional processes or run any installers before using it. You’re now ready to write some code. An easy way to get started is this example, which searches for the term “Cheese” on Google and then outputs the result page’s title to the console. You’ll start by using the HtmlUnit Driver. This is a pure Java driver that runs entirely in-memory. Because of this, you won’t see a new browser window open.

4.Which Implementation of WebDriver Should I Use? WebDriver is the name of the key interface against which tests should be written, but there are several implementations. These are: Name of driver

Operating

Class to instantiate

System HtmlUnit Driver

All

org.openqa.selenium.htmlunit.Ht

Firefox Driver

All

mlUnitDriver

Internet Explorer Driver Windows

Windows

org.openqa.selenium.firefox.Firef

Chrome Driver All

All

oxDriver org.openqa.selenium.ie.InternetEx plorerDriver org.openqa.selenium.chrome.Chro meDriver

You can find out more information about each of these by following the links in the table. Which you use depends on what you want to do. For sheer speed, the HtmlUnit Driver is great, but it’s not graphical, which means that you can’t watch what’s happening. As a developer you may be comfortable with this, but sometimes it’s good to be able to test using a real browser, especially when you’re showing a demo of ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 120 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

your application (or running the tests) for an audience. Often, this idea is referred to as “safety”, and it falls into two parts. Firstly, there’s “actual safety”, which refers to whether or not the tests works as they should. This can be measured and quantified. Secondly, there’s “perceived safety”, which refers to whether or not an observer believes the tests work as they should. This varies from person to person, and will depend on their familiarity with the application under test, WebDriver, and your testing framework. To support higher “perceived safety”, you may wish to choose a driver such as the Firefox Driver. This has the added advantage that this driver actually renders content to a screen, and so can be used to detect information such as the position of an element on a page, or the CSS properties that apply to it. However, this additional flexibility comes at the cost of slower overall speed. By writing your tests against the WebDriver interface, it is possible to pick the most appropriate driver for a given test. To keep things simple, let’s start with the

4.1 HtmlUnit Driver: WebDriver driver = new HtmlUnitDriver();

4.2 Navigating The first thing you’ll want to do with WebDriver is navigate to a page. The normal way to do this is bycalling “get”: driver.get( "http://www.google.com" ); WebDriver will wait until the page has fully loaded (that is, the “onload” event has fired) before returning control to your test or script. It’s worth noting that if your ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 121 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded. If you need to ensure such pages are fully loaded then you can use “waits”.

4.3 Interacting With the Page Just being able to go to places isn’t terribly useful. What we’d really like to do is to interact with the pages, or, more specifically, the HTML elements within a page. First of all, we need to find one. WebDriver offers a number of ways of finding elements. For example, given an element defined as: you could find it using any of: WebElement element; element = driver.findElement(By.id( "passwd-id" )); element = driver.findElement(By.name( "passwd" )); element = driver.findElement(By.xpath( "//input[@id=’passwd-id’]" )); You can also look for a link by its text, but be careful! The text must be an exact match! You should also be careful when using XPATH in WebDriver. If there’s more than one element that matches the query, then only the first will be returned. If nothing can be found, a NoSuchElementException will be thrown. WebDriver has an “Object-based” API; we represent all types of elements using the same interface: Web Element. This means that although you may see a lot of possible methods you could invoke when you hit your IDE’s auto-complete key combination, not all of them will make sense or be valid. Don’t worry! WebDriver will attempt to do the Right Thing, and if you call a method that makes no sense (“setSelected()” on a “meta” tag, for example) an exception will be thrown. ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 122 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

So, you’ve got an element. What can you do with it? First of all, you may want to enter some text into a text field: element.sendKeys( "some text" ); You can simulate pressing the arrow keys by using the “Keys” class: element.sendKeys( " and some" , Keys.ARROW_DOWN); It is possible to call sendKeys on any element, which makes it possible to test keyboard shortcuts such as those used on GMail. A side-effect of this is that typing something into a text field won’t automatically clear it. Instead, what you type will be appended to what’s already there. You can easily clear the contents of a text field or textarea: element.clear(); Filling In Forms -~~~~~~~~~~~~~~~ We’ve already seen how to enter text into a textarea or text field, but what about the other elements? You can “toggle” the state of checkboxes, and you can use “setSelected” to set something like an OPTION tag selected. Dealing with SELECT tags isn’t too bad: WebElement select = driver.findElement(By.xpath( "//select" )); List allOptions = select.findElements(By.tagName( "option" )); for (WebElement option : allOptions) { System.out.println(String.format( "Value is: %s" , option.getValue())); ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 123 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

option.setSelected();

 

}

This will find the first “SELECT” element on the page, and cycle through each of it’s OPTIONs in turn, printing out their values, and selecting each in turn. As you can see, this isn’t the most efficient way of dealing with SELECT elements. WebDriver’s support classes include one called “Select”, which provides useful methods for interacting with these. Select select = new Select(driver.findElement(By.xpath( "//select" ))); select.deselectAll(); select.selectByVisibleText( "Edam" ); This will deselect all OPTIONs from the first SELECT on the page, and then select the OPTION with the displayed text of “Edam”. Once you’ve finished filling out the form, you probably want to submit it. One way to do this would be to find the “submit” button and click it: driver.findElement(By.id( "submit" )).click(); // Assume the button has the ID "submit" :) Alternatively, WebDriver has the convenience method “submit” on every element. If you call this on an element within a form, WebDriver will walk up the DOM until it finds the enclosing form and then calls submit on that. If the element isn’t in a form, then the NoSuchElementException will be thrown: element.submit();

4.4 Getting Visual Information And Drag And Drop ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 124 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Sometimes you want to extract some visual information out of an element, perhaps to see if it’s visible or where it is on screen. You can find out this information by casting the element to a RenderedWebElement: WebElement plain = driver.findElement(By.name( "q" )); RenderedWebElement element = (RenderedWebElement) element; Not all drivers render their content to the screen (such as the HtmlUnit Driver), so it’s not safe to assume that the cast will work, but if it does you can gather additional information such as the size and location

4.5 Moving Between Windows and Frames It’s rare for a modern web application not to have any frames or to be constrained to a single window. WebDriver supports moving between named windows using the “switchTo” method: driver.switchTo().window( "windowName" ); All calls to driver will now be interpreted as being directed to the particular window. But how do you know the window’s name? Take a look at the javascript or link that opened it: Click here to open a new window Alternatively, you can pass a “window handle” to the “switchTo().window()” method. Knowing this, it’s possible to iterate over every open window like so: ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 125 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

for (String handle : driver.getWindowHandles()) { driver.switchTo().window(handle); } You can also swing from frame to frame (or into iframes): driver.switchTo().frame( "frameName" ); It’s possible to access subframes by separating the path with a dot, and you can specify the frame by its index too. That is: driver.switchTo().frame( "frameName.0.child" ); would go to the frame named “child” of the first subframe of the frame called “frameName”. All frames are evaluated as if from *top*.

4.6 Navigation: History and Location Earlier, we covered navigating to a page using the “get” command (driver.get("http://www.example.com")) As you’ve seen, WebDriver has a number of smaller, task-focused interfaces, and navigation is a useful task. Because loading a page is such a fundamental requirement, the method to do this lives on the main WebDriver interface, but it’s simply a synonym to: driver.navigate().to( "http://www.example.com" );

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 126 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

To reiterate: “navigate().to()” and “get()” do exactly the same thing. One’s just a lot easier to type than the other! The “navigate” interface also exposes the ability to move backwards and forwards in your browser’s history: driver.navigate().forward(); driver.navigate().back(); Please be aware that this functionality depends entirely on the underlying browser. It’s just possible that something unexpected may happen when you call these methods if you’re used to the behaviour of one browser over another.

4.7 Cookies Before we leave these next steps, you may be interested in understanding how to use cookies. First of all, you need to be on the domain that the cookie will be valid for: // Go to the correct domain driver.get( "http://www.example.com" ); // Now set the cookie. This one’s valid for the entire domain Cookie cookie = new Cookie( "key" , "value" ); driver.manage().addCookie(cookie);

// And now output all the available cookies for the current URL Set allCookies = driver.manage().getCookies(); for (Cookie loadedCookie : allCookies) { System.out.println(String.format( "%s -> %s" , loadedCookie.getName(), loadedCookie.getValue())); ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 127 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

}

6. WebDriver Implementations 5.1 HtmlUnit Driver This is currently the fastest and most lightweight implementation of WebDriver. As the name suggests, this is based on HtmlUnit. ¾ Fastest implementation of WebDriver ¾ A pure Java solution and so it is platform independent. ¾ Supports JavaScript ¾ Emulates other browser’s JavaScript behavior

JavaScript in the HtmlUnit Driver None of the popular browsers uses the JavaScript engine used by HtmlUnit (Rhino). If you test JavaScript using HtmlUnit the results may differ significantly from those browsers. When we say “JavaScript” we actually mean “JavaScript and the DOM”. Although the DOM is defined by the W3C each browser out there has its own quirks and differences in their implementation of the DOM and in how JavaScript interacts with it. HtmlUnit has an impressively complete implementation of the DOM and has good support for using JavaScript, but it is no different from any other browser: it has its own quirks and differences from both the W3C standard and the DOM implementations of the major browsers, despite its ability to mimic other browsers. With WebDriver, we had to make a choice; do we enable HtmlUnit’s JavaScript capabilities and run the risk of teams running into problems that only manifest themselves there, or do we leave JavaScript disabled, knowing that there are more ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 128 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

and more sites that rely on JavaScript? We took the conservative approach, and by default have disabled support when we use HtmlUnit. With each release of both WebDriver and HtmlUnit, we reassess this decision: we hope to enable JavaScript by default on the HtmlUnit at some point.

5.2 Declaring Browsers in WebDriver WebDriver Run with Firefox Browser: WebDriver driver = new FirefoxDriver(); WebDriver Run with InternetExplorer Browser: WebDriver driver = new InternetExplorerDriver(); Convert Selenium-RC code to WebDriver code:

//First Declare WebDriver: WebDriver driver = new FirefoxDriver();

// Create the Selenium implementation Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl); // Perform actions with selenium selenium.open( "http://www.google.com" ); selenium.type( "name=q" , "cheese" ); selenium.click( "name=btnG" ); //Now you can Execute

5.3 Firefox profile Handling in WebDriver

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 129 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Suppose that you wanted to modify the user agent string (as above), but you’ve got a tricked out Firefox profile that contains dozens of useful extensions. There are two ways to obtain this profile. Assuming that the profile has been created using Firefox’s profile manager (firefox -ProfileManager): ProfileIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile( "WebDriver" ); profile.setPreferences( "foo.bar" , 23); WebDriver driver = new FirefoxDriver(profile); Alternatively, if the profile isn’t already registered with Firefox: File profileDir = new File( "path/to/top/level/of/profile" ); FirefoxProfile profile = new FirefoxProfile(profileDir); profile.addAdditionalPreferences(extraPrefs); WebDriver driver = new FirefoxDriver(profile); Enabling features that might not be wise to use in Firefox As we develop features in the Firefox Driver, we expose the ability to use them. For example, until we feel native events are stable on Firefox for Linux, they are disabled by default. To enable them: FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(true); WebDriver driver = new FirefoxDriver(profile);

7. Locators or Properties ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 130 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1.

Id

2.

Name

3.

Class or classname

4.

Linktext

5.

Partial link text

6.

Normal xpath

7.

Absolute xpath

Other methods: we can create our own xpath 1. 2. 3. 4. 5. 6.

//input[@id=’give id’] //button[@class=’give class name’ ] //a[@href=’give the link’ ] //div[starts-with(@id, ‘give id starts’) ] //div[ends-with(@class, ‘give id give ends of class’) ] //div[contains(@id, ‘give id starts’) ]

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 131 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Important Interview Questions for Selenium RC & WebDriver

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 132 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1. What are the few Challenges that you faced with Selenium Automation in your company? ¾ Very difficult to find good documentation. Hardcore programming. ¾ Less inbuilt features for reporting/test case management. ¾ Finding locators/xpaths. ¾ Sometimes selenium is not able to recognize elements. We have to use JavaScript. in that case - especially in Selenium RC. ¾ We can’t run scripts from step as we can do in QTP. SO script generation takes a lot of time. ¾ Difficult to generate reports. ¾ Password encryption is not possible. ¾ Bitmap comparison is not supported by Selenium. ¾ You need to learn any one of the native language like (.Net, Java, Perl, Python, PHP, Ruby) to work efficiently with the scripting side of selenium. ¾ Sometimes stopping the selenium server it shows error, selenium server is running but actually it won’t run. ¾ Since Selenium is a freeware tool, there is no direct support if one is in trouble with the support of applications. ¾ There is no object repository concept in Selenium, so maintainability of the objects is very high.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 133 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

¾ There are many challenges if one have to interact with Win 32 windows even when. ¾ you are working with Web based applications. ¾ Bitmap comparison is not supported by Selenium. ¾ Any reporting related capabilities, you need to depend on third party tools.

3. Advantages of Selenium? ¾ Selenium is a open source tool ¾ It can Automate any Web Application ¾ It is a perfect tool for Browser Automation ¾ In the market very demand Automation Tool ¾ It can support no.of languages ¾ Once we prepare the code in the windows platform we can run in any OS, platform independent. ¾ We can integrate with No. of tools

4. Disadvantages of Selenium? ¾ Selenium Can’t record the Desktop application ¾ Selenium IDE can’t Record on IE Browser ¾ Bitmap comparison is not possible in selenium ¾ Handle dynamic Objects little bit tricky ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 134 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

¾ Less inbuilt features

 

¾ Generating reports bit difficult.

5. What do you know about Selenium? 6. Selenium is a suite of tools for web automation testing. Selenium first came to life in 2004 when Jason Huggins was testing an internal application at ThoughtWorks. Selenium was a tremendous tool, it wasn’t without it’s drawbacks. Because of its Javascript based automation engine and the security limitations browsers apply to Javascript, different things became impossible to do. Selenium Suite of projects include: Selenium IDE Selenium Core Selenium 1 (known as. Selenium RC or Remote Control) Selenium 2 (known as. Selenium Webdriver) Selenium-Grid

7. What are the technical challenges with selenium? As you know Selenium is a free ware open source testing tool. There are many challenges with Selenium. 1. Selenium Supports only web based applications 2. It doesn’t support any non web based (Like Win 32, Java Applet, Java Swing, .Net Client Server etc) applications 3. When you compare selenium with QTP, Silk Test, Test Partner and RFT, there ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 135 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

are many challenges in terms of maintainability of the test cases 4. Since Selenium is a freeware tool, there is no direct support if one is in trouble with the support of applications 5. There is no object repository concept in Selenium, so maintainability of the objects is very high 6. There are many challenges if one have to interact with Win 32 windows even when you are working with Web based applications 7. Bitmap comparison is not supported by Selenium 8. Any reporting related capabilities, you need to depend on third party tools 9. You need to learn any one of the native language like (.Net, Java, Perl, Python, PHP, Ruby) to work efficiently with the scripting side of selenium

8. What are the capabilities of Selenium IDE? Selenium IDE (Integrated Development Environment) works similar to commercial tools like QTP, Silk Test and Test Partner etc. The below mentioned points describes well about Selenium IDE. 1. Selenium IDE is a Firefox add-on. 2. Selenium IDE can support recording the clicks, typing, and other actions to make a test cases. 3. Using Selenium IDE A Tester can play back the test cases in the Firefox browser 4. Selenium IDE supports exporting the test cases and suites to Selenium RC. 5. Debugging of the test cases with step-by-step can be done 6. breakpoint insertion is possible 7. Page abstraction functionality is supported by Selenium IDE 8. Selenium IDE can supports an extensibility capability allowing the use of addons or user extensions that expand the functionality of Selenium IDE

9. What are the challenges with Selenium IDE? ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 136 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

Selenium-IDE does not directly support: 1. condition statements 2. iteration or looping 3. logging and reporting of test results 4. error handling, particularly unexpected errors 5. database testing 6. test case grouping 7. re-execution of failed tests 8. test case dependency 9. capture screenshots on test failures 10. Results Report generations

10. Which are the browsers supported by Selenium IDE? 1. Selenium can record only on firefox and It can support or run only on firefox

11. How to execute a single line command from Selenium IDE? Single line command from Selenium IDE can be executed in two ways 1.Right click on the command in Selenium IDE and select "Execute This Command" 2.Select the command in Selenium IDE and press "X" key on the keyboard

12. How to insert a start point in Selenium IDE? Start point Selenium IDE can be set in two ways 1. Right click on the command in Selenium IDE and select "Set / Clear Start Point" 2. Select the command in Selenium IDE and press "S" key on the keyboard ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 137 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

3. You can have only one start point

 

4. If you have already set one start point and you selected other command as start point. Then the first start point will be removed and the new start point will be set

13. How to insert a break point in Selenium IDE? Break point can be set in two ways in Selenium IDE 1. Right click on the command in Selenium IDE and select "Toggle Break Point" 2. Select the command in Selenium IDE and press "B" key on the keyboard 3. If you want to clear the break point once again Spress "B" key on the keyboard 4. You can set multiple break points in Selenium IDE

14. How to debug the tests in Selenium IDE? To debug or execute the test cases line by line. Follow the below mentioned steps 1. Insert a break point (see the question to know more How to insert a break point in Selenium IDE? )from the location where you want to execute step by step 2. Run the test case 3. execution will be paused at the given break point 4. Click on the step (Blue) button to continue with the next statement 5. Click on Run button, to continue executing all the commands at a time

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 138 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

15. How to export the tests from Selenium IDE to Selenium RC in different languages? From selenium IDE the test cases can be exported into the languages 1. .Net, 2. Java, 3. Perl, 4. Python, 5. PHP, 6. Ruby The below mentioned steps can explain how to export the test cases 1. Open the test case from Selenium IDE 2. Select File -> Export Test Case As

16. Which is the command used for displaying the values of a variable into the output console or log? 1. The command used for displaying the values of a variable into the output console or log - echo 2. If you want to display a constant string. The below mentioned command can be used echo ex: echo "The sample message" 3. If you want to display the value of a variable it can be written like below echo ${> 4. ex: echo ${var1} 5. Note: Here var1 is the variable

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 139 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

17. Which are the browsers supported by Selenium RC? 1. Supported browsers for Selenium RC include: 2. 1. *firefox 2. *mock 3. *firefoxproxy 4. *pifirefox 5. *chrome 6. *iexploreproxy 7. *iexplore 8. *firefox3 9. *safariproxy 10. *googlechrome 11. *konqueror 12. *firefox2 13. *safari 14. *piiexplore 15. *firefoxchrome 16. *opera 17. *iehta 18. *custom 3. Note: Any third party browser is supported with *custom followed by the complete path of the browser with executable

18. Which are the Operating Systems supported by Selenium?

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 140 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

1. Selenium IDE

 

Works in Firefox 2+ Start browser, run tests Run tests Operating Systems Supported: 2. 1. Windows, 2. OS X 3. Linux 4. Solaris 5. Others whichever supports Firefox 2+ 3. Selenium Remote Control Used for starting browser and run tests Operating Systems Supported: 4. 1. Windows, 2. OS X 3. Linux 4. Solaris 5. Others 5. Selenium Core Used for running tests Operating Systems Supported: 6. 1. Windows, 2. OS X 3. Linux 4. Solaris 5. Others

19. What is Selenium RC?

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 141 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1. Selenium-RC is the solution for tests that need a little more than just simple browser actions and a linear execution. Selenium-RC leverages the full power of programming languages, creating tests that can do things like read and write external files, make queries to a database, send emails with test reports, and practically anything else a user can do with a normal application. 2. You will want to use Selenium-RC whenever your test requires logic not supported by running a script from Selenium-IDE

20. Why Selenium RC is used?

1. Selenium-IDE does not directly support: 2. 1. condition statements 2. iteration 3. logging and reporting of test results 4. error handling, particularly unexpected errors 5. database testing 6. test case grouping 7. re-execution of failed tests 8. test case dependency 9. capture screenshots on test failures 3. The reason behind why Selenium-IDE does not support the above mentioned requirements is IDE supports only HTML language. Using HTML language we cannot achieve the above mentioned requirements. Because HTML does not support conditional, looping and external source connectives. 4. To overcome the above mentioned problems Selenium RC is used. 5. Since Selenium RC supports the languages .Net, Java, Perl, Python, PHP, and Ruby. In these languages we can write the programme to achieve the IDE issues ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 142 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

21. Which are the languages supported by Selenium RC? The languages supported by Selenium RC 1. .Net, 2. Java (Junt 3, Junt 4, TestNG, Groovy) 3. Perl, 4. Python, 5. PHP, 6. Ruby

22. What is Selenium Grid? Selenium Grid is part of Selenium suite of projects. Selenium Grid transparently distribute your tests on multiple machines so that you can run your tests in parallel, cutting down the time required for running in-browser test suites. This will dramatically speeds up in-browser web testing, giving you quick and accurate feedback you can rely on to improve your web application.

23. What is Selenium WebDriver or Google WebDriver or Selenium 2.0? ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 143 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1. WebDriver uses a different underlying framework from Selenium’s javascript Selenium-Core. It also provides an alternative API with functionality not supported in Selenium-RC. WebDriver does not depend on a javascript core embedded within the browser, therefore it is able to avoid some long-running Selenium limitations. 2. WebDriver’s goal is to provide an API that establishes • A well-designed standard programming interface for web-app testing. • Improved consistency between browsers. • Additional functionality addressing testing problems not well-supported in Selenium 1.0. 3. The Selenium developers strive to continuously improve Selenium. Integrating WebDriver is another step in that process. The developers of Selenium and of WebDriver felt they could make significant gains for the Open Source test automation community be combining forces and merging their ideas and technologies. Integrating WebDriver into Selenium is the current result of those efforts.

24. What are the capabilities of Selenium WebDriver or Google WebDriver or Selenium 2.0? One should use WebDriver when requiring improved support for Mult-browser testing including improved functionality for browsers not wellsupported by Selenium-1.0. • Handling multiple frames, multiple browser windows, popups, and alerts. • Page navigation. • Drag-and-drop. • AJAX-based UI elements. ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 144 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

25. What is the architecture of Selenium RC?

1. The Selenium Server which launches and kills browsers, and acts as an HTTP proxy for browser requests. 2. Client libraries for various programming languages, each of which instructs the Selenium Server in how to test the AUT by passing it your test script’s Selenium commands. 3. The diagram shows the client libraries communicate with the Server passing each Selenium command for execution. Then the server passes the Selenium command to the browser using Selenium-Core JavaScript commands. The browser, using its JavaScript interpreter, executes the Selenium command, which effectively, runs the check you specified in your Selenese test script.

26. What is the architecture of Selenium Grid? The below mentioned theory explains about the setup of Selenium Grid with architecture and how it works. 1. Selenium Grid builds on the traditional Selenium setup, taking advantage of the following properties: 2. * The Selenium test, the application under test, and the remote control/browser pair do not have to be co-located. They communicate through HTTP, so they can all live on different machines. * The Selenium tests and the web application under test are obviously specific to a ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 145 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

particular project. Nevertheless, neither the Selenium remote control nor the browser is tied to a specific application. As a matter of fact, they provide a capacity that can easily be shared by multiple applications and multiple projects. 3. Consequently, if only we could build a distributed grid of Selenium Remote Controls, we could easily share it across builds, applications, projects - even potentially across organizations. Of course we would also need to address the scalability issues as described earlier when covering the traditional Selenium setup. This is why we need a component in charge of: 4. * Allocating a Selenium Remote Control to a specific test (transparently) * Limiting the number of concurrent test runs on each Remote Control * Shielding the tests from the actual grid infrastructure 5. Selenium Grid calls this component the Selenium Hub. 6. * The Hub exposes an external interface that is exactly the same as the one of a traditional Remote Control. This means that a test suite can transparently target a regular Remote Control or a Selenium Hub with no code change. It just needs to target a different IP address. This is important as it shields the tests from the grid infrastructure (which you can scale transparently). This also makes the developer’s life easier. The same test can be run locally on a developer machine, or run on a heavy duty distributed grid as part of a build – without ever changing a line of code. * The Hub allocates Selenium Remote Controls to each test. The Hub is also in charge of routing the Selenese requests from the tests to the appropriate Remote Control as well as keeping track of testing sessions. * When a new test starts, the Hub puts its first request on hold if there is no available Remote Control in the grid providing the appropriate capabilities. As soon as a suitable Remote Control becomes available, the Hub will serve the request. For the whole time, the tests do not have to be aware of what is happening within the grid; it is just waiting for an HTTP response to come back.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 146 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

27. Does Selenium support mobile internet testing? Selenium supports Opera. And opera is used in most of the Smart phones. So whichever Smart phone supports opera, selenium can be used to test. So, one can use Selenium RC to run the tests on mobiles.

28. Does Selenium support Google Android Operating System? Yes, Selenium Web Driver or Google Web Driver or Selenium 2.0 supports Android Operating System. There are several libraries written to support Android Operating System.

29. What are the types of text patterns available in Selenium? There are three types of patterns available in Selenium 1. globbing 2. regular expressions 3. Exact

30. How to use regular expressions in Selenium? ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 147 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1. Regular expressions in Selenium IDE can be used with the keyword - regexp: as a prefix to the value and patterns needs to be included for the expected values. 2. For example if you want to use the regular expression for a command Command: verifyText Target: //font/font/b/font[1] Value: Flight Confirmation # 2011-05-02451 3. in the above example Flight Confirmation is continuously changing each time you run the test case. So this can be written with a regular expression as mentioned below 4. Command: verifyText Target: //font/font/b/font[1] Value: regexp:Flight Confirmation # [0-9]{4}-[0-9]{2}-[0-9]{5,10}

31. What are the regular expression patterns available in Selenium? 1. Selenium regular expression patterns offer the same wide array of special characters that exist in JavaScript. Below are a subset of those special characters

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 148 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

2. PATTERN 4. .

3. MATCH 5. any single character 7. character class: any single character that appears

6. [ ]

inside the brackets 9. quantifier: 0 or more of the preceding character

8. *

(or group) 11.quantifier: 1 or more of the preceding character

10. +

(or group) 13.quantifier: 0 or 1 of the preceding character (or

12. ?

group) 15.quantifier: 1 through 5 of the preceding character

14. {1,5}

(or group) 17.alternation: the character/group on the left or

16. |

the character/group on the right 19.grouping: often used with alternation and/or

18. ( )

quantifier

32. What is Selenese?

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 149 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1. Selenium set of commands which are used for running the test are called as Selenese. 2. There are three types of Selenese, those are: 1. Actions - used for performing the operations and interactions with the target elements 2. Assertions - used as check points 3. Accessors - used for storing the values in a variable

33. How do you add check points or verification points in Selenium? 1. check points or verification points are known as Assertions in Selenium. The keywords with below mentioned prefix will be used for adding check points or verification points. 2. 1. verify 2. assert 3. waitFor

34. What is Assertion in Selenium? 1. Assertion is nothing but a check or verification point.

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 150 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

2. Assertion verifies the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this checkbox is checked.

35. What are the types of Assertions there in Selenium? 1. Selenium Assertions can be used in 3 modes: 2. 1) assert - When an “assert” fails, the test will be aborted. If you are executing test suite, the next state case will start 3. 2) verify - When a “verify” fails, the test will continue execution, logging the failure. 4. 3) waitFor - “waitFor” commands wait for some condition to become true (which can be useful for testing Ajax applications). They will succeed immediately if the condition is already true. However, they will fail and halt the test if the condition does not become true within the current timeout setting

36. When to use Assert, Verify and WaitFor in Selenium? ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 151 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

1. 1) assert - If the expected value is mandatory to continue with the next set of steps we will use Assert. As Assert aborts the test, if the expected value doesn't match. It is good to use for any mandatory checks. 2. 2) verify - If the expected value is optional to continue with the next set of steps we will use Verify. As Verify continues executing with the next set of steps, if the expected value doesn't match. It is good to use for any optional checks. 3. 3) waitFor - If your test needs to wait, if the expected value is not matching we use waitFor. We normally use waitFor for AJAX kind of controls loading within a page

37. What is an Accessor in Selenium? 1. Accessor is one of the type of Selenese. 2. I. Accessors are used for storing the value of a target in a variable. 3. Ex: 1) storeTitle - Stores the title of a window in a variable 4. 2) storeText - Stores the target element text in a variable 5. II. Accessors are also used for evaluating the result and storing the result in a variable 6. Ex: storeTextPresent - Evaluates whether the text is present in the current window. If the text is present stores true in the variable else stores false 7. Ex: storeEementPresent - Evaluates whether the element is present in the current window. If the element is present stores true in the variable else stores false

________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 152 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

38. When to use Accessors in Selenium? 1. Accessors are mostly used for storing the value in a variable. 2. The variable can be used for following reasons: 3. 1) To get the value from an element and comparing with some dynamic value 4. 2) To take a logical decision to execute the test steps ex: if the value of the variable true execute step1 and step2 else step3 and step4 5. 3) To execute some statements in a loop based on the value returned by the element

39. How to capture bitmaps in Selenium? 1. Bitmaps are captured using the Selenium set of commands. There are two modes of capturing the bitmaps 2. 1) Capture the bitmap for the entire page - it captures the browser main page area of AUT 2) Capture the bitmap for the screen shots - it captures the entire screen shot like the print scree that you give from your keyboard 3. Selenium doesn't support bitmap capturing for an element on AUT.

40. Which are the commands used for capturing the bitmaps? 1. captureEntirePageScreenshot Saves the entire contents of the current window canvas to a PNG file. Contrast this with the captureScreenshot command, which captures the contents of the OS viewport (i.e. whatever is currently being displayed on the monitor), and is implemented in the RC only. Currently this only works in Firefox when running in chrome mode, and in IE non-HTA using the ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 153 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

EXPERIMENTAL "Snapsie" utility. The Firefox implementation is mostly borrowed from the Screengrab! Firefox extension. Please see captureEntirePageScreenshot for more details 2. captureEntirePageScreenshotAndWait Saves the entire contents of the current window canvas to a PNG file. Contrast this with the captureScreenshot command, which captures the contents of the OS viewport (i.e. whatever is currently being displayed on the monitor), and is implemented in the RC only. Currently this only works in Firefox when running in chrome mode, and in IE non-HTA using the EXPERIMENTAL "Snapsie" utility. The Firefox implementation is mostly borrowed from the Screengrab! Firefox extension. Please see captureEntirePageScreenshotAndWait for details. 3. Note: This command runs with only mozilla firefox when you run the tests from RC. Other browsers it will not support

41. What is the difference between captureEntirePageScreenshot and CaptureScreenShot? 1. captureEntirePageScreenshot 1. This captures the AUT web page only 2. This supports only mozilla firefox 3. Accepts two arguments. one is the file name to be saved and other argument is back ground color 2. CaptureScreenShot 3. 1. This captures the System screen shot 2. This supports all the browsers when you run from Selenium RC 3. Accepts one argument. That is the file name to be saved. ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 154 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

42. How do you set user extensions in Selenium IDE? 1. 1. Open user-extensions.js with an editor (Notepad, etc.); it's found in the selenium\core\scripts folder. If it doesn't exist, just create it. 2. If you need to, commit the user-extensions.js file (like if you use subversion). 3. Open Selenium IDE and choose the Options menu and then Options... from that menu. 4. Make sure the path to your user-extensions.js file is entered in the Selenium Core extensions field (like \selenium\core\scripts\userextensions.js) 5. Press OK button on options 6. Restart the IDE to reflect your extensions. 2. Note: After reopen, Selenium IDE may show compilations errors if the userextensions.js file has any syntax errors.

43. What are the limitations of Selenium IDE 1. The limitations of Selenium IDE are: 2. 1) Selenium IDE uses only HTML language 2) Conditional or branching statements execution like using of if, select statements is not possible 3) Looping statements using is not possible directly in Selenium HTML language in ide 4) Reading from external files like .txt, .xls is not possible 5) Reading from the external databases is not possible with ide ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 155 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

6) Exceptional handling is not there 7) A neat formatted Reporting is not possible with ide 3. To eliminate the above issues we use Selenium RC

44. What are the pre-requisites to run Selenium RC tests with Junit? 1. The pre-requisites to run Selenium RC tests with Junit: 2. 1) Jre 1.5 or better version needs to be installed 2) /jre/bin folder must be added in environment variable "path" 3) Junit folder path must be added to path or build path in eclipse 4) Selenium Java Client drivers needs to be added to the path for execution

45. How to configure Selenium RC with eclipse to run Junit Tests? 1. 1) Download eclipse. click here to download the software 2) Open eclipse -> Workspace Launcher window will open 3) Create a workspace by giving meaningful name 3) Click on Workbench 4) Create a project of type java 5) Create a package under src folder of the package 6) Add Junit to the build path 7) Add selenium rc java client driver to the build path 8) Now drag and drop your test script (.which is exported from Selenium IDE) to the package created

46. Which is the command used for running the Selenium RC Server? The procedure followed to run the Selenium RC Server is: 1. Open the command prompt. ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 156 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

2. Change the folder path to Selenium RC Server 3. Issue the command "java -jar selenium-server.jar" 4. For more options on how to start selenium server. Please have a look at Selenium RC Server startup Options

47.

How do you run selenium commands in slow motion in Selenium

RC? You can run the selenium commands in RC slow motion by two ways: selenium.setSpeed thread.sleep

48. What is the difference between Thread.Sleep() and Selenium.setSpeed()? selenium.setSpeed 1. takes a single argument in string format ex: selenium.setSpeed("2000") - will wait for 2 seconds 2. Runs each command in after setSpeed delay by the number of milliseconds mentioned in setSpeed. 1. thread.sleep 1. takes a single argument in integer format ex: thread.sleep(2000) - will wait for 2 seconds 2. Waits for only once at the command given at sleep.

49. Why do you use assert and verify statements in Selenium RC without referring to selenium? 1. SeleneseTestCase is the class which is having ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 157 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

2. 1. assertTrue

 

2. verifyTrue 3. assertEquals 4. verifyEquals 3. We use SeleneseTestCase class to extend the selenium test class file. 4. For Ex: the test class is declared as follows public class BookFlightSel1 extends SeleneseTestCase 5. In the above example SeleneseTestCase is the base class and BookFlightSel1 is the derived class. So, we can directly call and use the parent class methods verify and assert without instantiating the class in BookFlightSel1 class.

50. Which are the annotations generated with JUnit 4 tests in Selenium IDE? 1. The annotations generated with JUnit 4 tests in Selenium are: 2. 1. @Before public void method() - Will perform the method() before each test. This method can prepare the test 2. @Test public void method() - Annotation @Test identifies that this method is a test method.environment, e.g. read input data, initialize the class) 3. @After public void method() - Annotation @After is executed after the test is been executed and this method consists of post test operations such as closure of the application.

51. What are the challenges with Selenium RC test suites when running in JUnit? 1. The challenges with Selenium RC test suites when running in JUnit 1. Each test case of Selenium RC test will invoke the browser and closes ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 158 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

after playing back

 

2. All the Test cases cannot run on a single browser session 3. If there is any dependency between the test cases, it is very difficult to execute 4. Running the test suites in junit will be helpful for only independent test cases. 2. Note: The dependent test case related issues can be addressed by using TestNG with junit

52. What are the advantages of using TestNG over Junit? The advantages of using TestNG over Junit: 1. The challenges of junit can be addressed using TestNG read What are the challenges with Selenium RC test suites when running in JUnit? for more details 2. You can execute the test cases dependent with each other read Runnning Selenium RC Tests Sequentially using TestNG for more details 3. You can execute test cases in a group read Use Group in TestNG framework for more details 4. You can generate the reports using TestNg

53. What are the basic annotations used to run TestNG tests in Selenium? 1. The basic annotations used to run TestNG tests in Selenium RC: 2. @BeforeClass: The annotated method with @BeforeClass will be run before the first test method in the current class is invoked. ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 159 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

2. @AfterClass: The annotated method with @AfterClass will be run after all the test methods in the current class have been run. 3. @BeforeMethod: The annotated method with @BeforeMethod will be run before each test method. 4. @AfterMethod: The annotated method with @AfterMethod will be run after each test method. 5. @Test: Marks a class or a method @Test with as part of the test.

54. How to run test cases with dependent in Selenium using TestNG? 1. The @Test should be followed by (dependsOnMethods = "testLogin") Note:- The test case will be executed after the testLogin case 2. Ex: @Test(dependsOnMethods = "testLogin")

55.

How to run Selenium IDE test suite with user

extensions using Selenium Remote Control? 1. Read this forum topic for How to run Selenium IDE TestSuite with Selenium Remote Control 2. to run Selenium IDE test suite with user extensions using Selenium Remote Control we need to use the below command. 3. java -jar selenium-server.jar -userExtensions user-extensions.js -htmlSuite "*" "" "" "" timeout

56. How to start selenium rc server with user extensions? 1. The command used is java -jar selenium-server.jar -userExtensions user-extensions.js ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 160 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

2. Note: In this case, the java script file user-extensions.js file name should always fixed. If the name or extension is changed the selenium rc server will not start.

57. What are the limitations of selenium RC 1. The limitations of selenium RC are: 1) Switching between the multiple instances of the same browser is not possible 2) Switching between the multiple instances of the different browsers is not possible 3) Browser navigation, like back and forward button emulations is not possible 4) Limited features in terms of drag and drop of objects 5) To work with Ajax based UI elements there are very limited features are there with Selenium RC

58. What is selenium webdriver? WebDriver is a Advanced version of RC, in this no need to start the server manually. It has Bigger API.

WebDriver Programs: ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 161 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

WebDriver Basic – Programs-1: package WebDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Webdriver_basic { public static void main(String[] args) throws Exception { WebDriver driver=new FirefoxDriver(); driver.manage().window().maximize(); //maximize window driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.MINUTES); //aplicable for all line or entire class for page to load driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //entire class it'll wait until elments to load Thread.sleep(2000); driver.get("http://google.com"); driver.findElement(By.linkText("Gmail")).click(); Thread.sleep(2000); ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 162 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

driver.findElement(By.id("Email")).sendKeys("selenium"); driver.findElement(By.id("Passwd")).sendKeys("testing"); driver.findElement(By.id("signIn")).click(); } }

WebDriver checkboxes – Programs-2: package WebDriver; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class checkboxes { @Test public void main() throws Exception { WebDriver driver=new FirefoxDriver(); driver.get("http://www.tizag.com/htmlT/htmlcheckboxes.php"); driver.manage().window().maximize(); //driver.findElement(By.linkText("Gmail")).click(); Thread.sleep(2000); boolean exits=driver.findElement(By.xpath("//html/body/table[3]/tbody/tr[1]/td[2]/t" + ________________________________________________________________________

QEdge TECHNOLOGIES: # 204, 2nd Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491.  

Page | 163 QEdge TECHNOLOGIES: # 204, 2 Floor, Nagasuri Plaza, Ameerpet, Hyderabad. Email: [email protected], ph:040-64644491/92, 7702944491. nd

 

"able/tbody/tr/td/div[4]/input[1]")).isEnabled(); for(int i=1;i
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF