Sunteți pe pagina 1din 32

EXERCISE 1

STUDY OF SOFTWARE TESTING TOOLS

INTRODUCTION TO SELENIUM

1. History of Selenium

• In 2004 invented by Jason R. Huggins and team.

• Original name is JavaScript Functional Tester [JSFT]

• Open source browser based integration test framework built originally by


Thoughtworks.

• 100% JavaScript and HTML

• Web testing tool

• That supports testing Web 2.0 applications

• Supports for Cross-Browser Testing(ON Multiple Browsers)

• And multiple Operating Systems

• Cross browser – IE 6/7, Firefox .8+, Opera, Safari 2.0+

2. What is Selenium?

• Acceptance Testing tool for web-apps

• Tests run directly in browser

• Selenium can be deployed on Windows, Linux, and Macintosh.

• Implemented entirely using browser technologies -

JavaScript

DHTML

Frames

3. Selenium Components

– Selenium IDE

– Selenium Core

– Selenium RC

– Selenium Grid

3.1 Selenium IDE


• The Selenium-IDE (Integrated Development Environment) is the tool you use to develop
your Selenium test cases.

• It is Firefox plug-in
• Firefox extension which allows record/play testing paradigm
• Automates commands, but asserts must be entered by hand
• Creates the simplest possible Locator
• Based on Selenese
3.1.1 Overview of Selenium IDE: A.Test

Case Pane

B. Toolbar

C. Menu Bar

D.Log/Reference/UI-Element/Rollup Pane

A. Test Case Pane:

Your script is displayed in the test case pane. It has two

tabs.

one for displaying the command (source)

and their parameters in a readable “table” format.

B. Toolbar: The toolbar contains buttons for controlling the execution of your
test cases, including a step feature for
C. Menu Bar:

File Menu: The File menu allows you to create, open and save test case and test suite files.

Edit Menu: The Edit menu allows copy, paste, delete, undo and select all operations for
editing the commands in your test case.

Options Menu: The Options menu allows the changing of settings. You can set the timeout
value for certain commands, add user-defined user extensions to the base set of Selenium
commands, and specify the format (language) used when saving your test cases.

D. Help Menu:

Introducing Selenium Commands

The command set is often called selenese. Selenium commands come in three
“flavors”:
Actions, Accessory and Assertions.

a. Actions: user actions on application / Command the browser to do something.

Actions are commands that generally manipulate the state of the application.

1. Click link- click / Clickandwait

2. Selecting items

b. Accessors: Accessors examine the state of the application and store the results in
variables, e.g. "storeTitle".

c. Assertions: For validating the application we are using Assertions

1. For verifying the web pages

2. For verifying the text

3. For verifying alerts


Assertions can be used in 3 modes:

assert

verify

waitFor

Example: "assertText","verifyText" and "waitForText"

NOTE:

1. When an "assert" fails, the test is aborted.

2. When a "verify" fails, the test will continue execution

3. "waitFor" commands wait for some condition to become true

Commonly Used Selenium Commands

These are probably the most commonly used commands for building test. open - opens a

page using a URL.

click/clickAndWait - performs a click operation, and optionally waits for a new page to load.
verifyTitle/assertTitle - verifies an expected page title. verifyTextPresent- verifies expected text is

somewhere on the page. verifyElementPresent -verifies an expected UI element, as defined by its

HTML

tag, is present on the page.

verifyText - verifies expected text and it’s corresponding HTML tag are present on the page.

verifyTable - verifies a table’s expected contents.


waitForPageToLoad -pauses execution until an expected new page loads. Called automatically
when clickAndWait is used.

waitForElementPresent -pauses execution until an expected UI element, as defined by its HTML tag, is
present on the page.

3.1.2 Recording and Run settings

When Selenium-IDE is first opened, the record button is ON by default.


During recording, Selenium-IDE will automatically insert commands into your test case based on
your actions.
a. Remember Base URL MODE - Using Base URL to Run Test Cases in Different Domains
b. Record Absolute recording mode – Run Test Cases in Particular Domain.

3.1.3 Running Test Cases

Run a Test Case Click the Run button to run the currently displayed test case.
Run a Test Suite Click the Run All button to run all the test cases in the currently loaded test suite.
Stop and Start The Pause button can be used to stop the test case while it is running. The icon
of this button then changes to indicate the Resume button. To continue click Resume.
Stop in the Middle You can set a breakpoint in the test case to cause it to stop on a particular command.
This is useful for debugging your test case. To set a breakpoint, select a command, right-
click, and from the context menu select Toggle Breakpoint.
Start from the Middle You can tell the IDE to begin running from a specific command in the middle
of the test case. This also is used for debugging. To set a startpoint, select a command, right-click,
and from the context menu select Set/Clear Start Point.
Run Any Single Command Double-click any single command to run it by itself. This is useful when
writing a single command. It lets you immediately test a command you are constructing, when
you are not sure if it is correct. You can double-click it to see if it runs correctly. This is also
available from the context menu.
TestSuite:
A test suite is a collection of tests. Often one will run all the tests in a test suite as
one continuous batch-job.
When using Selenium-IDE, test suites also can be defined using a simple HTML
file. The syntax again is simple. An HTML table defines a list of tests where each
row defines the filesystem path to each test.

Installing the IDE

Using Firefox, first, download the IDE from the SeleniumHQ downloads page Firefox will protect
you from installing addons from unfamiliar locations, so
you will need to click ‘Allow’ to proceed with the installation, as shown in the following screenshot.

When downloading from Firefox, you’ll be presented with the following window.
Select Install Now. The Firefox Add-ons window pops up, first showing a
progress bar, and when the download is complete, displays the following.

Restart Firefox. After Firefox reboots you will find the Selenium-IDE listed
under the Firefox Tools menu.
Opening the IDE

To run the Selenium-IDE, simply select it from the Firefox Tools menu. It opens as follows with an
empty script-editing window and a menu for loading, or creating new test cases.
EXERCISE 2

USING SELENIUM IDE, WRITE A TEST SUITE CONTAINING MINIMUM 4 TEST CASES.

AIM:
To write a test suite for minimum of 4 test cases using selenium.

PROCEDURE:

TC’S #1: Manual Steps:

• Open (Example: Type www.google.com)


• Type “energy efficient” in the Google Search Input Box
• Click outside on an empty spot
• Click Search Button
• Verify the Text Present as “energy efficient”
• Assert the Title as “energy efficient - Google Search”
• Save the test case with .HTML Extension. TC’S #2:

• Open (Example: Type www.google.com)


• Type “Selenium RC” in the Google Search Input Box
• Click outside on an empty spot
• Click Search Button
• Verify the Text Present as “Selenium RC”
• Assert the Title as “Selenium RC - Google Search”
• Save the test case with .HTML Extension. Steps for
creating test suite:

1. Create more Tc’s save each Test Case with <.html> extension.

2. Open Firefox

3. Open Tools Selenium IDE

4. File Open new Test Suite

5. File Open Add Test cases

6. Add more test cases

7. Save Suite with <.Html> extensions.

8. Run the test suite

Conduct a test suite for nay two web sites. TC’S #1: Manual Steps:

• Open (Example : Type www.google.com)


• Type “energy efficient” in the Google Search Input Box
• Click outside on an empty spot
• Click Search Button
• Verify the Text Present as “energy efficient”
• Assert the Title as “energy efficient - Google Search”
• Save the test case with .HTML Extension.

TC#2:

1: Open Firefox Web Browser

2: In the address bar, Type http://www.yahoo.com

3: In the search input button, Type "energy efficient"

4: Click on the "Web Search" submit button

5: Wait for Search Results to come on "http:/search.yahoo.com"

6: Verify "energy efficient" text is present anywhere in the search results: (Select and

highlight anywhere in the search results page, "energy efficient" text is present.)

7: Verify the browsers title has the value "energy efficient - Yahoo! Search
Results"

8. Save the test case with .HTML Extension.


Steps for creating test suite:

1. Create more Tc’s save each Test Case with <.html> extension.

2. Open Firefox

3. Open Tools Selenium IDE

4. File Open new Test Suite

5. File Open Add Test cases

6. Add more test cases

7. Save Suite with <.Html> extensions.

8. Run the test suite

RESULT:

Test suite generated successfully

EXERCISE 3
GRADING SYSTEM USING TEST LINK
AIM:
To Write a Java Program for grading system and Write set of test cases to test the program.

PROCEDURE:

import java.util.Scanner;
public class JavaExample
{
public static void main(String args[])
{
/* This program assumes that the student has 6 subjects,
* thats why I have created the array of size 6. You can
* change this as per the requirement.
*/
int marks[] = new int[6];
int i;
float total=0, avg;
Scanner scanner = new Scanner(System.in);

for(i=0; i<6; i++) {


System.out.print("Enter Marks of Subject"+(i+1)+":");
marks[i] = scanner.nextInt();
total = total + marks[i];
}
scanner.close();
//Calculating average here
avg = total/6;
System.out.print("The student Grade is: ");
if(avg>=80)
{
System.out.print("A");
}
else if(avg>=60 && avg<80)
{
System.out.print("B");
}
else if(avg>=40 && avg<60)
{
System.out.print("C");
}
else
{
System.out.print("D");
}
}
}

Output:
Enter Marks of Subject1:40
Enter Marks of Subject2:80
Enter Marks of Subject3:80
Enter Marks of Subject4:40
Enter Marks of Subject5:60
Enter Marks of Subject6:60
The student Grade is: B

Following are the steps involved to add a project into TestLink −


Usually to create a project, an option is available at the Test Project Management menu as shown in the
following screenshot.
Step 1 − Enter the following details into Create a Project form −
Name − It should be a unique project name.
Prefix − It is used for test case ID to identify the test cases.
Project description − Details about the project.
Enhanced features − You can check the checkboxes based on the requirement of the project. It allows
to select which features you want such as Requirement, Automation, etc.
Issue tracker − If any issue tracker is linked with TestLink, it will be displayed here.
Step 2 − Select the Availability option and then click the Create button as shown in below.

Clicking the Create button adds the project along with Delete and Active/Inactive switch for Requirement
and Active features as shown in the following screenshot.

Step 3 − You can view the project by selecting a project name from the “Test Project” dropdown at the top
right corner of the screen as seen below.
Edit a Test Case

To edit a test case, you should have Edit Test Case permission.
Following are the steps to edit a test case −
Step 1 − Select the test case from the tree structure on the left panel of the screen and click the settings
known as actions to display all the available options.
Step 2 − Click the Edit button as shown below.

It opens the Test case details in the edit page.


Step 3 − You can edit the Name, Details or any other fields as shown below.
Step 4 − Click the Save button to update the test case.

Move/Copy a Test Case

To Move/Copy a test case, you should have Create/Edit Test Suite permission. This functionality allows
creating a duplicate test case or reordering of the structure.
Step 1 − To copy/move a test suite into another project, select the test cases that need to be copied/moved
and click the setting icon known as Actions.
Step 2 − Click the Move/Copy button as shown below.
Step 3 − It opens the Move/Copy page. You can select the test suite to move or copy a new test case
name and decide whether the keywords and requirements should be copied/moved to the target suite.
Step 4 − After selection, click the Copy or Move button according to requirement.
Step 5 − The Copy button will copy the test suite in both of the suites, while the move button will move the
test case from the current suite to the target suite.
Following screenshot shows how to copy/move the test case to another suite −

Delete a Test Case

To delete a Test Case, you should have Delete Test Case permission.
Step 1 − To delete a test case, select the test case from the suite that needs to be deleted and click the
setting icon known as Actions.
Step 2 − Once done, click the delete button as shown below.
A confirmation message will be displayed to delete. Click Yes to delete the test cases as shown in following
screenshot.

The page will be refreshed and the test case will be deleted from the tree structure on the left side panel
of the screen.
A successful deletion message will be displayed as shown below.
RESULT:

Thus the Java Program for grading system and test cases executed successfully.

EXERCISE 4
TRIANGLE PROGRAM BASED ON SIDES AND ANGLES USING TEST LINK

AIM:

To Write a C Program for triangle based on sides and angles and Write Set of Test Cases to Test
the Program

PROCEDURE:

Step 1: Input a, b & c i.e three integer values which represent three sides of the triangle.

Step 2: if (a < (b + c)) and (b < (a + c)) and (c < (a + b) then do step 3 else print not a triangle. do step 6.

Step 3: if (a=b) and (b=c) then Print triangle formed is equilateral. do step 6.

Step 4: if (a ≠ b) and (a ≠ c) and (b ≠ c) then Print triangle formed is scalene. do step 6.

Step 5: Print triangle formed is Isosceles.

PROGRAM CODE:

#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<process.h>
int main()
{
int a, b, c;
clrscr();

printf("Enter three sides of the triangle");


scanf("%d%d%d", &a, &b, &c);

if((a > 10) || (b > 10) || (c > 10))


{
printf("Out of range");
getch();
exit(0);
}
if((a<b+c)&&(b<a+c)&&(c<a+b))
{
if((a==b)&&(b==c))
{
printf("Equilateral triangle");
}
else if((a!=b)&&(a!=c)&&(b!=c))
{
printf("Scalene triangle");
}
else
printf("Isosceles triangle");
}
else { printf("triangle cannot be formed");
}
getch();
return 0;

Test cases:

Test Case Input Values Expected Results

1. 3, 3, 3 Equilateral Triangle

2. 3, 3, 2 Isosceles Triangle

3. 3, 4, 5 Scalene Triangle

4. 3, 3, ? Invalid Input

Executing A Test Case In Test Link Tool:


TestLink tool allows executing a test case with which we can change the status of a test
case. TestLink tool has the available status as “blocked” “Passed”, or “failed”. The
default status of a test case is “not run” status and once this status has changed and
updated to “blocked” “Passed”, or “failed”, it cannot be changed back to “not run” status
again. The following are the steps to execute a test case in TestLink tool.

Step 1: From the top navigation bar present on the page, click on the “Test Execution”
link (highlighted and shown below). It will open a new “Execute Tests” panel.

Step 2: Shown below is “Execute Tests” panel where you can pick a test case which
you want to run from the left side panel.
Step 3: Your test case is required to have stepped into it for execution. If you haven’t
added any step to your test case, then take a step back and add at least one step to
your test case which you want to execute. This step will be required in order to execute
your test case. In the example below, we have added step “execute” to the test case
“TL-1: Test Case 1”. When you are preparing to execute the test case then you need to
enter the execution note to one or more steps associate with the current test case and
you have to select an appropriate status (here we have selected “Passed” as shown
below).

At the bottom of the same page, you need to enter Notes or description about the
attached requirement and once it is completed you need to click on the execution icons
present on the right-hand side of “Notes / Description” field as shown below.
Using the icons below, you can quickly execute the test case and assign it the status as
“blocked” “Passed”, or “failed”.

Since we have clicked on the “Passed” execution link. Our current test case has
executed successfully and it has been assigned status as “Passed” as shown below.
RESULT:

Thus a C Program for triangle based on sides and angles and Test Cases executed successfully.

EXERCISE : 5

PRIME NUMBER
GENERATION USING TESTLINK

AIM:

To Write a C Program for prime number generation using test link and Write set of test cases to test the
program

PROCEDURE:

#include<stdio.h>

main()

int n, c = 2;
printf("Enter a number to check if it is prime\n");

scanf("%d",&n);

for ( c = 2 ; c <= n - 1 ; c++ )

if ( n%c == 0 )

printf("%d isn't prime.\n", n);

break;

if ( c == n )

printf("%d is prime.\n", n);

return 0;

TEST CASES:

WRITE A TEST CASE TO CHECK IT(TEST BOX) ACCEPTS ONLY NUMBERS.- VALID TEST CASE.

1. ENTER DECIMAL NUMBERS-----NEGATIVE TEST CASE

2. ENTER NUMBER IN P/Q FORM----NEGATIVE TEST CASE

3. TEST CASE TO CHECK ALPHA, SPECIAL CHARS - SHOULD NOT ACCEPT.

4. NOT PRIME NUMBER(BOUNDRY VALUES MIN TO MAX) - MESSAGE SHOULD BE DISPLAYED.

5. PRIME NUMBER - CORRECT OUTPUT.

6. CHECK THE LENGTH OF CHARCTERS.

7. CHECK HOW MANY(MAX.) NUMBER OF DIGITS ENTERED BY USER


8. CHECK MINIMUM.NUMBER OF DIGITS ENTERED BY USER

Output of program:

TESTLINK :

Step 1: Bring up the Testlink application

Open the XAMPP console and click on Start buttons for Apache Web Server and MySQL. After Apache
Web server and MySQL database are started, you can see their status on XAMPP control panel. Apache
and MySQL elements on XAMPP control Panel has turned green which demonstrate the port number.

Note: When you want to stop or restart the Apache Web Server and MySQL database then you can
simply click on the Stop button to complete the required action.
Step 2: Login into the TestLink application with admin or appropriate role

Make sure that the role with which you are going to login into Testlink tool should have appropriate
access to write requirements. Once Apache Web server and MySQL database are up and running, you
can access the TestLink application at the below URL on your local machine.

http://localhost/testlink-1.9.16/login.php

Shown below is the login page for TestLink tool. Enter username and password as admin and admin
respectively in order to log into the application.

[Click image to enlarge]

After successful login, it will take you to the home page of the Test Link tool as shown below.

[Click image to enlarge]


Step 3: At the top left corner of the home page, you will notice a “Test Report” icon on the header as
shown below (highlighted icon). Click on this “test report” icon.
Step 4: It will open “Reports and Metrics” panel where on the left-hand side of the panel has links to
generate various reports and on the right-hand side panel you will find the description of those reports as
shown below.

[Click image to enlarge]


Step 5: Click on the “Test Report” link present on the left-hand side of the panel (highlighted and shown
below).

Step 6: It will open up “Test Report” panel on the right-hand side of the panel where you can observe
Test report – Document options along with a number of checkboxes which are present opposite to these
options as shown below. You just simply need to check that checkbox which you want to include in the
Test report. The available options are as follows.

1. Table of Contents: When you enable this option by checking the checkbox, then it will display a
table of contents in the Test report.
2. Header Numbering: When you enable this option by checking the checkbox, then it will display
header numbering in the Test report.
3. Test Suite description: When you enable this option by checking the checkbox, then it will
display test suite description in the Test report.
4. Test Case Summary: When you enable this option by checking the checkbox, then it will display
test case summary in the Test report.
5. Test Case Scenario: When you enable this option by checking the checkbox, then it will display
test case scenario in the Test report.
6. Test Case Author: When you enable this option by checking the checkbox, then it will display
test case author in the Test report.
7. Test Case Keywords: When you enable this option by checking the checkbox, then it will display
test case summary in the Test report.
8. Test Case Custom Fields: When you enable this option by checking the checkbox, then it will
display test case custom fields in the Test report.
9. Test Case Related Requirements: When you enable this option by checking the checkbox, then
it will display test case related requirements in the Test report.
10. Execution Notes: When you enable this option by checking the checkbox, then it will display
execution notes in the Test report.
11. Step Execution Notes: When you enable this option by checking the checkbox, then it will
display step execution notes in the Test report.
12. Test results: When you enable this option by checking the checkbox, then it will display test
results in the Test report.
13. Step Execution Results: When you enable this option by checking the checkbox, then it will
display step execution results in the Test report.
14. Build Custom Fields: When you enable this option by checking the checkbox, then it will display
build custom fields in the Test report.
15. Metrics: When you enable this option by checking the checkbox, then it will display metrics in the
Test report.

Step 6: Select as many checkboxes for the options which you want to display in your test report. Anytime,
you can use the option “check/uncheck all” which is present at the bottom in order to check and uncheck
all the checkboxes respectively when clicked. As an example, we have just checked four checkboxes.
They are a table of contents, test case summary, test results, and step execution results. Next, click on
the tree root in order to generate full doc or a specific folder for branch doc which is present at the bottom.
Here, we have clicked on “Testlink suite 1” to generate the test report.
Step 7: The report has generated successfully and it can be seen on the right-hand side of the panel as
shown below page by page.
]

This report will grow as long as you enable more option by checking the checkboxes as discussed earlier
in this chapter. Depending on the organization need, we can customize our test report by simply playing
around with the checkboxes for the available options.

RESULT :

Thus a C Program for prime number generation using test link and set of test cases executed
successfully.

Exercise: 6

SELENIUM FOR AUTOMATED WEBSITE TESTING

AI M:

To generate automated website testing using selenium.


PROCEDURE
The Seven Basic Steps of Selenium Tests
There are seven basic steps in creating a Selenium test script, which apply to any test case and any
application under test (AUT).
1. Create a WebDriver instance.
2. Navigate to a Web page.
3. Locate an HTML element on the Web page.
4. Perform an action on an HTML element.
5. Anticipate the browser response to the action.
6. Run tests and record test results using a test framework.
7. Conclude the test.
The Login Use Case
Imagine that you want to test a very basic use case for any website or Web application, in which a user
logs in and, upon successful authentication, receives a message. There are two basic processes in this
use case, each of which we want to test:

● The login process, which involves the user entering a username and password in a form, and then
clicking a Submit button.
● The login response process, in which the website displays the login response message.

Login FOR REGISTRATION

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import org.junit.Assert;

public class Example {


public static void main(String[] args) {

// Create an instance of the driver


WebDriver driver = new FirefoxDriver();

// Navigate to a web page


driver.get("http://www.foo.com");

// Perform actions on HTML elements, entering text and submitting the form
WebElement usernameElement = driver.findElement(By.name("username"));
WebElement passwordElement = driver.findElement(By.name("password"));
WebElement formElement = driver.findElement(By.id("loginForm"));

usernameElement.sendKeys("Alan Smithee");
passwordElement.sendKeys("twilightZone");

//passwordElement.submit(); // submit by text input element


formElement.submit(); // submit by form element

// Anticipate web browser response, with an explicit wait


WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement messageElement = wait.until(
ExpectedConditions.presenceOfElementLocated(By.id("loginResponse"))
);

// Run a test
String message = messageElement.getText();
String successMsg = "Welcome to foo. You logged in successfully.";
Assert.assertEquals (message, successMsg);

// Conclude a test
driver.quit();

}
}

RESULT:

Thus the program for generated automated website testing using selenium

S-ar putea să vă placă și