[go: up one dir, main page]

0% found this document useful (0 votes)
18 views5 pages

Exp 4 SY

The document outlines an experiment for installing Selenium server and automating a test scenario using Java/PHP to validate Google Search functionality. It includes detailed steps for setting up the environment, writing the test script, and verifying the results through assertions. The test script demonstrates launching the Chrome browser, entering a search term, and checking the title of the resulting page against an expected value.

Uploaded by

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

Exp 4 SY

The document outlines an experiment for installing Selenium server and automating a test scenario using Java/PHP to validate Google Search functionality. It includes detailed steps for setting up the environment, writing the test script, and verifying the results through assertions. The test script demonstrates launching the Chrome browser, entering a search term, and checking the title of the resulting page against an expected value.

Uploaded by

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

SOFTWATE TESTING LAB - 15CS64P 2020-21

Experiment 4: Install Selenium server and demonstrate it using a


script in Java/PHP.

Test Scenario
Here, We will automate the testing for the following scenario in Google Chrome Browser by
developing Test script using Selenium Web Driver:
Driver

• Launch Chrome Browser


• Maximize the browser
• Open URL: https://www.google.
www.google.com
• Checks whether Search text box accepts value or not and "Google
Google Search"
Search button
functionality. Title of the search results web page is validated.
• Finally, Concludes test result by comparing expected result with the actual result.

Locating required Web Elements

We need unique id or name for required web elements (Search textbox and "Google Search" button)
to automate them through your test script. It can be done as follows:

• www.google.com. Right click on the Search text box and select


Open URL: https://www.google.
inspect element.. It will show source code of web page. Note down the id or name of search
code Here, Unique name of Search textbox is "q".
textbox from the source code.

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

• Repeat the same for "Google Search" button. Here, unique name of "Google Search" button
is "btnK".

Code Explaination

1. Open Eclipse application,, click File -> New -> Java Project and create Java project as "ST
Lab" (Note: Eclipse IDE and JDK 8 or above must be downloaded and installed earlier.
Refer Experment 3 to know
now how to download and install).
install
2. Right click on the "src" folder and create a new class file from the New -> Class.
3. Give Class name as "Exp4"
"Exp4 and click the "Finish" buton.
4. Right click on the "src" folder and click "Build Path" ->
> "Configure Build Path".

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

5. Under Libraries tab select "Classpath" and click "Add External JARs". Then, add all the
required JAR files ("client
client-combined-3.141.59.jar", " client-combined--3.141.59-sources.jar",
all jar files from "libs" folder and "junit4.jar" file) and finally, click "Apply and Close".
(Note: Downloading required JAR files explained in Experiment 3. Refer Experiment 3 for
more information)

6. Import the required packages and set the system property "webdriver.chrome.driver" to
the path of your ChromeDriver.exe file (Note: Chrome Driver must be downloaded earlier.
Refer Experment 3 to know how to download chrome driver).
driver)
System.setProperty("webdriver.chrome.driver",
("webdriver.chrome.driver", "D:\\STLab\\chromedriver.exe");
chromedriver.exe");
7. Create a instance of Web driver class, launch
unch the browser and navigate it to the required
google.com. Maximize the browser if required.
URL: https://www.google
WebDriver driver=new ChromeDriver();
driver.navigate().to("https://www.
driver.navigate().to("https://www.google.com");
driver.manage().window().maximize();
8. Next, you need to locate the search textbox and "Google Search" button element. Send
value to search text box and perform click action on button element as below:
driver.findElement(By.
.findElement(By.name("q")).sendKeys("Software
q")).sendKeys("Software Testing");
Testing
driver.findElement(By.
.findElement(By.name("btnK")).submit();
9. To validate results, assertions are needed. Asserts compares expected result with actual
result. Here, Expected Title of search results web page is "Software Testing - Google
Search" on search operation.
operation It is compared with current tilte of the web page as below:
String ExpTitle = "Software
" Testing - Google Search";
Assert.assertEquals(ExpTitle driver.getTitle());
Assert.assertEquals(ExpTitle,
10. close the browser.
driver.close();
Computer Science & Engineering
SOFTWATE TESTING LAB - 15CS64P 2020-21

11. Click on the "Run" and click "Run As" to run


un the application. Test results will be
generated.

Test Script

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Exp4 {
@Test
public void testGoogle()()
{
//Set system property
System.setProperty chromedriver.exe");
setProperty("webdriver.chrome.driver","D:\\STLab\\chromedriver.exe"
//Creates instance of webDtiver class
WebDriver driver=new
driver ChromeDriver();
//Launch the browser and navigate to "https://www.linkedin.com/login"
driver.navigate().to(
.navigate().to("https://www.google.com");
//Maximize the Browser
driver.manage().window().maximize();
.manage().window().maximize();
// Locate the search textbox and send value
driver.findElement(By.
.findElement(By.name("q")).sendKeys("Software
"Software Testing");
Testing"
// Locate the button and click
driver.findElement(By.
.findElement(By.name("btnK")).submit();
//Expected URL on successful login is: https://www.linkedin.com/feed/
String ExpTitle = "Software Testing - Google Search";
//Compares expected result with actual result.
Assert.assertEquals
assertEquals(ExpTitle, driver.getTitle());
System.out.println(
.println("Test Passed\nGoogle
nGoogle Search is Successful: ");
"
//Close the browser
driver.close();
}
}

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

Test Result:

REFERENCES

[1] https://www.selenium.dev/
[2] https://www.javatpoint.com/selenium-webdriver
https://www.javatpoint.com/selenium
[3] https://www.tutorialspoint.com/selenium/selenium_webdriver.htm
[4] https://www.google.com

Computer Science & Engineering

You might also like