0% found this document useful (0 votes)
2K views5 pages

Launch Browser With TestNG Handson

Selenium WebDriver Hands-on Solutions | TCS Fresco Play
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)
2K views5 pages

Launch Browser With TestNG Handson

Selenium WebDriver Hands-on Solutions | TCS Fresco Play
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/ 5

2.

Hands-On
Welcome to Launch Browser with TestNG

File Name - LaunchBrowser_TestNG

package launchBrowserTestNG;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

public class LaunchBrowser_TestNG {

@Test
public void LaunchBrowser() throws InterruptedException{

DesiredCapabilities caps = new DesiredCapabilities();


caps.setJavascriptEnabled(true);

caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPER
TY, "/projects/challenge/phantomjs-2.1.1-linux-x86_64/bin/phantomjs");
WebDriver driver = new PhantomJSDriver(caps);
System.out.println("PhantomJS Headless Driver launched");

// Write your script here


driver.get("https:/google.com");
Thread.sleep(5000);
System.out.println("Launch Browser is successful");
System.out.println("Page Title : " + driver.getTitle());

//Searching for "Fresco Play" in Google search

driver.findElement(By.xpath("//input[@name='q']")).sendKeys("Fresco
Play");

driver.findElement(By.xpath("//input[@name='q']")).sendKeys(Keys.ENTER)
;
Thread.sleep(5000);
System.out.println("Page Title : " + driver.getTitle());

}
}

File Name - pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com</groupId>
<artifactId>launchBrowserTestNG</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>launchBrowserTestNG</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<suiteXmlFile>launchBrowserTestNG/testng.xml</suiteXmlFile>
</properties>

<dependencies>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.11.0</version>
</dependency>

<!-- Add you Testng dependency here...!! -->

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.0.1</version>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>

</build>
</project>

File Name - testng.xml

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="launchBrowserTestNG.LaunchBrowser_TestNG"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

You might also like