You are on page 1of 2

Step1)click on terminal & type -> sudo apt-get install tree

then press enter


Step2)copy paste below code in GoogleSearch.java
package googleSearch;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class GoogleSearch {

WebDriver driver;
Logger logger;
@BeforeTest
public void launch() {

logger =Logger.getLogger("GoogleSearch");
PropertyConfigurator.configure("Log4j.properties");

// PhantomJS Headless Driver

DesiredCapabilities caps = new DesiredCapabilities();


caps.setJavascriptEnabled(true);

caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,"/
projects/challenge/phantomjs-2.1.1-linux-x86_64/bin/phantomjs");
driver = new PhantomJSDriver(caps);
logger.info("PhantomJS Headless Driver launched");

// Write the Parameter tag and drive the values from testng.xml file and pass the
value inside the methods

@Test
@Parameters({"URL","searchKey"})
public void googleSearch (String URL,String searchKey) throws
InterruptedException {
driver.get(URL);
Thread.sleep(5000);
logger.info("URL have been hitted");

// Write the script for google search


driver.findElement(By.name("q")).sendKeys(searchKey);

logger.info("Google Search has been done");


}
@AfterTest
public void teardown(){
driver.quit();
}
}

#Step 3) Copy paste below code in testing.xml file


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">

<!-- Create Parameter tag and link the class file here -->
<parameter name="URL" value="https://google.com" />
<parameter name="searchKey" value="Fresco Play" />
<test name="testGuru">
<classes>
<class name="googleSearch.GoogleSearch">
</class>
</classes>
</test>
</suite>

#step4)click on run>install and check "Build Success" and submit

You might also like