Skip to content

Instantly share code, notes, and snippets.

@ckzgraphics
Created March 7, 2019 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckzgraphics/ea2ca74ee94aca81dc077457c9ea696e to your computer and use it in GitHub Desktop.
Save ckzgraphics/ea2ca74ee94aca81dc077457c9ea696e to your computer and use it in GitHub Desktop.
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.io.File;
import java.net.MalformedURLException;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
public class CustomMediaFile_iOS {
public static String userName = "<BROWSERSTACK_USERNAME>";
public static String accessKey = "<BROWSERSTACK_ACCESS_KEY>";
public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesiredCapabilities caps = null;
AppiumDriver driver = null;
WebElement wele = null;
MobileElement ele = null;
TouchAction touch = null;
JavascriptExecutor js = null;
try {
caps = new DesiredCapabilities();
caps.setCapability("project", "Test Run");
caps.setCapability("build", "Build v1");
caps.setCapability("name", "Test: Media File iOS");
caps.setCapability("device", "iPhone 8 Plus");
caps.setCapability("os_version", "11.0");
caps.setCapability("app", "bs://<app-hashed-id>"); // IMAGE FOOD
List<String> ls = new ArrayList<String>();
ls.add("media://<media-hashed-id>");
caps.setCapability("browserstack.uploadMedia", ls);
driver = new IOSDriver<IOSElement>(new URL("http://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps);
touch = new TouchAction(driver);
js = (JavascriptExecutor) driver;
Thread.sleep(2000);
take_screenshot(driver);
driver.findElement(MobileBy.AccessibilityId("Add")).click();
Thread.sleep(2000);
take_screenshot(driver);
ele = (MobileElement) driver.findElement(MobileBy.xpath(".//XCUIElementTypeImage[@name='defaultPhoto']"));
HashMap<String, Object> gesture = new HashMap<String, Object>();
gesture.put("x", "25");
gesture.put("y", "25");
gesture.put("element", ele);
js.executeScript("mobile: tap", gesture);
Thread.sleep(2000);
take_screenshot(driver);
touch.tap(156, 108).perform();
Thread.sleep(2000);
take_screenshot(driver);
touch.tap(46, 164).perform();
Thread.sleep(2000);
take_screenshot(driver);
} catch (Exception e) {
e.printStackTrace();
} finally {
if(driver != null){
driver.quit();
}
}
} // MAIN END
public static void take_screenshot(WebDriver webDriver){
try {
TakesScreenshot scrShot =((TakesScreenshot)webDriver);
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
// File DestFile=new File("/Users/test.png");
// FileUtils.copyFile(SrcFile, DestFile);
} catch (Exception e) {
e.printStackTrace();
}
} // FUNC END
} // CLASS END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment