[go: up one dir, main page]

0% found this document useful (0 votes)
90 views15 pages

Selenium Task 6

The document introduces Selenium and its installation process. It then provides code examples to test Google.com, Gmail.com, and a mortgage calculator site using Selenium.

Uploaded by

Afreen Syed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views15 pages

Selenium Task 6

The document introduces Selenium and its installation process. It then provides code examples to test Google.com, Gmail.com, and a mortgage calculator site using Selenium.

Uploaded by

Afreen Syed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Task-6

AIM: a)Introduction to Selenium tool and Installation procedure


b) Testing for www.google.com, www.gmail.com and
www.mortigagecalculator.com

A) Selenium is a set of different software tools each with a different approach to supporting
test automation. Most Selenium QA Engineers focus on the one or two tools that most meet
the needs of their project, however learning all the tools will give you many different options
for approaching different test automation problems. The entire suite of tools results in a rich
set of testing functions specifically geared to the needs of testing of web applications of all
types. These operations are highly flexible, allowing many options for locating UI elements and
comparing expected test results against actual application behavior. One of Selenium’s key
features is the support for executing one’s tests on multiple browser platforms.

Installation steps:

Step 1 - Install Java on your computer

Step 2 - Install Eclipse IDE

Step 3 - Download the Selenium Java Client Driver

Step 4 - Configure Eclipse IDE with WebDriver

1. Launch the "eclipse.exe" file inside the "eclipse" folder that we extracted in step 2. If you
followed step 2 correctly, the executable should be located on C:\eclipse\eclipse.exe.
2. When asked to select for a workspace, just accept the default location.
3. Create a new project through File > New > Java Project. Name the project as "newproject".

A new pop-up window will open enter details as follow

1. Project Name
2. Location to save project
3. Select an execution JRE
4. Select layout project option
5. Click on Finish button
4. In this step,

1. Right-click on the newly created project and


2. Select New > Package, and name that package as "newpackage".
A pop-up window will open to name the package,

1. Enter the name of the package


2. Click on Finish button

5. Create a new Java class under newpackage by right-clicking on it and then selecting- New >
Class, and then name it as "MyClass". Your Eclipse IDE should look like the image below.
When you click on Class, a pop-up window will open, enter details as

1. Name of the class


2. Click on Finish button
This is how it looks like after creating class.
Now selenium WebDriver's into Java Build Path

In this step,

1. Right-click on "newproject" and select Properties.


2. On the Properties dialog, click on "Java Build Path".
3. Click on the Libraries tab, and then
4. Click on "Add External JARs.."

When you click on "Add External JARs.." It will open a pop-up window. Select the JAR files
you want to add.
After selecting jar files, click on OK button.

Select all files inside the lib folder.


Select files outside lib folder
Once done, click "Apply and Close" button
6. Add all the JAR files inside and outside the "libs" folder. Your Properties dialog should now
look similar to the image below.
6. Finally, click OK and we are done importing Selenium libraries into our project.

B) Google.com

1)Install the chrome driver

mport org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.Test;

public class Openchrome {

@Test

public void test12() throws Exception{

// Initialize browser

WebDriver driver=new ChromeDriver();


// Open Google

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

// Close browser

driver.close();

Output:

b) gmail

package login;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login1 {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
// Wait For Page To Load
// Put a Implicit wait, this means that any search for elements on the page
could take the time the implicit wait is set for before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Navigate to URL
driver.get("https://mail.google.com/");
// Maximize the window.
driver.manage().window().maximize();
// Enter UserName
driver.findElement(By.id("Email")).sendKeys(" YOUR USER NAME");
// Enter Password
driver.findElement(By.id("Passwd")).sendKeys("YOUR PASSWORD");
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Click on 'Sign In' button
driver.findElement(By.id("signIn")).click();
//Click on Compose Mail.
driver.findElement(By.xpath("//div[@class='z0']/div")).click();
// Click on the image icon present in the top right navigational Bar
driver.findElement(By.xpath("//div[@class='gb_1 gb_3a gb_nc
gb_e']/div/a")).click();
//Click on 'Logout' Button
driver.findElement(By.xpath("//*[@id='gb_71']")).click();
//Close the browser.
driver.close();
}
}

c)mortgage calculator

package chrome;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class chromedriver {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
// Wait For Page To Load
// Put a Implicit wait, this means that any search for elements on the page
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Navigate to URL
driver.get("https://mail.google.com/");
// Maximize the window.
driver.manage().window().maximize();
// Enter UserName
driver.findElement(By.id("Email")).sendKeys(" YOUR USER NAME");
// Enter Password
driver.findElement(By.id("Passwd")).sendKeys("YOUR PASSWORD");
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Click on 'Sign In' button
driver.findElement(By.id("signIn")).click();
//Click on Compose Mail.
driver.findElement(By.xpath("//div[@class='z0']/div")).click();
// Click on the image icon present in the top right navigational Bar
driver.findElement(By.xpath("//div[@class='gb_1 gb_3a gb_nc gb_e']/div/a")).click();
//Click on 'Logout' Button
driver.findElement(By.xpath("//*[@id='gb_71']")).click();
//Close the browser.
driver.close();
}
}

You might also like