Skip to content

Instantly share code, notes, and snippets.

@freynaud
Created October 23, 2012 07:15
Show Gist options
  • Save freynaud/3937405 to your computer and use it in GitHub Desktop.
Save freynaud/3937405 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.ebayopensource.twin.Application;
import org.ebayopensource.twin.Screenshot;
import org.ebayopensource.twin.element.Window;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Reporter;
import org.testng.annotations.Test;
import org.uiautomation.ios.IOSCapabilities;
import org.uiautomation.ios.UIAModels.UIAButton;
import org.uiautomation.ios.UIAModels.UIADriver;
import org.uiautomation.ios.UIAModels.UIAWindow;
import org.uiautomation.ios.UIAModels.predicate.NameCriteria;
import org.uiautomation.ios.client.uiamodels.impl.RemoteUIADriver;
public class Demo {
private final String hub = "http://localhost:4444/wd/hub";
@Test(invocationCount=30,threadPoolSize=3)
public void testIOSApp() {
UIADriver driver = new RemoteUIADriver(hub, IOSCapabilities.iphone("eBay"));
try {
UIAWindow win = driver.getLocalTarget().getFrontMostApp().getMainWindow();
UIAButton button = win.findElement(UIAButton.class, new NameCriteria("Agree"));
button.tap();
// screenshot
File f = new File("IOS.png");
driver.getLocalTarget().takeScreenshot(f.getAbsolutePath());
Reporter.log("<img src='" + f.getAbsolutePath() + "'>");
} finally {
driver.quit();
}
}
@Test(invocationCount=30)
public void testWindowsApp() throws IOException {
Application session = new Application(new URL(hub));
try {
session.open("notepad", null);
// Wait for the main window to appear and grab it
Window window = session.getWindow();
// Enter some dramatic text
window.type("Hello world!\n");
// Take screenshots
Screenshot screenshot = window.getScreenshot();
File f = new File("notepad.pnj");
screenshot.save(f);
Reporter.log("<img src='" + f.getAbsolutePath() + "' />");
} finally {
// kill the app
session.close();
}
}
@Test(invocationCount=60,threadPoolSize=2)
public void testWeb() throws MalformedURLException {
WebDriver driver = new RemoteWebDriver(new URL(hub), DesiredCapabilities.firefox());
try {
driver.get("http://ebay.co.uk");
//screenshot
File web = new File("webshot.pnj");
Augmenter a = new Augmenter();
File tmp = ((TakesScreenshot) a.augment(driver)).getScreenshotAs(OutputType.FILE);
tmp.renameTo(web);
Reporter.log("<img src='" + web.getAbsolutePath() + "' />");
} finally {
driver.quit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment