Created
March 17, 2016 21:08
-
-
Save hidepin/93049154f92586d42367 to your computer and use it in GitHub Desktop.
selenium_addon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.func.sample.selnium; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.URL; | |
import java.util.concurrent.TimeUnit; | |
import org.apache.commons.io.FileUtils; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.OutputType; | |
import org.openqa.selenium.TakesScreenshot; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.firefox.FirefoxProfile; | |
import org.openqa.selenium.remote.Augmenter; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
public class Selenium { | |
public static void main(String[] args) { | |
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); | |
FirefoxProfile profile = new FirefoxProfile(); | |
RemoteWebDriver remoteWD = null; | |
int sleeptime = 2000; | |
try { | |
profile.addExtension(new File("C:/work/firebug-2.0.14.xpi")); | |
capabilities.setCapability(FirefoxDriver.PROFILE, profile); | |
remoteWD = new RemoteWebDriver(new URL("http://192.168.137.225:4444/wd/hub"), capabilities); | |
// remoteWD.get("file://C:/selenium/Chapter 3/HTML/Frames.html"); | |
remoteWD.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); | |
remoteWD.navigate().to("https://www.google.co.jp"); | |
WebElement searchBox = remoteWD.findElement(By.name("q")); | |
searchBox.sendKeys("Selenium WebDriver"); | |
WebElement searchButton = remoteWD.findElement(By.name("btnK")); | |
searchButton.click(); | |
Thread.sleep(sleeptime); | |
searchBox.clear(); | |
Thread.sleep(sleeptime); | |
searchBox.sendKeys("Packt Publishing"); | |
searchButton = remoteWD.findElement(By.name("btnG")); | |
searchButton.click(); | |
Thread.sleep(sleeptime); | |
remoteWD.navigate().back(); | |
Thread.sleep(sleeptime); | |
remoteWD.navigate().forward(); | |
Thread.sleep(sleeptime); | |
remoteWD.navigate().refresh(); | |
WebDriver augmentedDriver = new Augmenter().augment(remoteWD); | |
File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); | |
FileUtils.copyFile(screenshot, new File("C:/work/test.png")); | |
Thread.sleep(sleeptime); | |
remoteWD.quit(); | |
} catch (InterruptedException | IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PLEASE WILL YOU HELP ME DO THIS FOR ME? AM A 100LEVEL STUDENT IN THE UNIVERSITY
Assignment 5