Created
October 16, 2012 14:35
-
-
Save freynaud/3899645 to your computer and use it in GitHub Desktop.
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
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.Criteria; | |
import org.ebayopensource.twin.MouseButton; | |
import org.ebayopensource.twin.Screenshot; | |
import org.ebayopensource.twin.element.Menu; | |
import org.ebayopensource.twin.element.MenuItem; | |
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.predicate.NameCriteria; | |
import org.uiautomation.ios.client.uiamodels.impl.RemoteUIADriver; | |
public class Demo { | |
@Test | |
public void testIOSApp() { | |
UIADriver driver = | |
new RemoteUIADriver("http://localhost:4444/wd/hub", IOSCapabilities.iphone("eBay")); | |
try { | |
UIAButton button = | |
driver.getLocalTarget().getFrontMostApp().getMainWindow() | |
.findElement(UIAButton.class, new NameCriteria("Agree")); | |
button.tap(); | |
File f = new File("IOS.png"); | |
driver.getLocalTarget().takeScreenshot(f.getAbsolutePath()); | |
Reporter.log("<img src='" + f.getAbsolutePath() + "'>"); | |
} finally { | |
driver.quit(); | |
} | |
} | |
@Test | |
public void testWindowsApp() throws IOException { | |
Application session = new Application(new URL("http://localhost:4444/wd/hub")); | |
try { | |
session.open("notepad", null); | |
Reporter.log("pplication name: " + session.getApplicationName()); | |
Reporter.log("Application version: " + session.getApplicationVersion()); | |
// Wait for the main window to appear and grab it | |
Window window = session.getWindow(); | |
// Enter some dramatic text | |
window.type("Hello world!\n"); | |
window.type("This window will self-destruct in 3..."); | |
// Take screenshots | |
Screenshot screenshot = window.getScreenshot(); | |
File f = new File("notepad.pnj"); | |
screenshot.save(f); | |
Reporter.log("<img src='" + f.getAbsolutePath() + "' />"); | |
window.menu("File").openMenu().item("Exit").click(); | |
} finally { | |
// kill the app | |
session.close(); | |
} | |
} | |
@Test | |
public void testWeb() throws MalformedURLException { | |
WebDriver driver = | |
new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox()); | |
try { | |
driver.get("http://ebay.co.uk"); | |
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