Created
August 19, 2015 10:56
-
-
Save saikrishna321/f9e79c30859441541d54 to your computer and use it in GitHub Desktop.
GalenTestBase -- Load AndroidDriver
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 com.galenframework.java.sample.components; | |
import static java.util.Arrays.asList; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.List; | |
import org.openqa.selenium.Dimension; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.testng.annotations.DataProvider; | |
import com.galenframework.testng.GalenTestNgTestBase; | |
import io.appium.java_client.AppiumDriver; | |
import io.appium.java_client.android.AndroidDriver; | |
public abstract class GalenTestBase extends GalenTestNgTestBase { | |
private static final String ENV_URL = "http://testapp.galenframework.com"; | |
@Override | |
public WebDriver createDriver(Object[] args) { | |
TestDevice device = (TestDevice) args[0]; | |
if (device.name == "mobile") { | |
AppiumDriver<WebElement> driver = null; | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("deviceName", "10.4.21.140:5555"); | |
capabilities.setCapability("platformVersion", "5.0.1"); | |
capabilities.setCapability("browserName", "browser"); | |
try { | |
driver=new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); | |
} catch (MalformedURLException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return driver; | |
} else { | |
WebDriver driver = new FirefoxDriver(); | |
if (args.length > 0) { | |
if (args[0] != null && args[0] instanceof TestDevice) { | |
if (device.getScreenSize() != null) { | |
driver.manage().window().setSize(device.getScreenSize()); | |
} | |
} | |
} | |
return driver; | |
} | |
} | |
public void load(String uri) { | |
getDriver().get(ENV_URL + uri); | |
} | |
@DataProvider(name = "devices") | |
public Object[][] devices() { | |
return new Object[][] { { new TestDevice("mobile", new Dimension(450, 800), asList("mobile")) }, | |
{ new TestDevice("tablet", new Dimension(750, 800), asList("tablet")) }, | |
{ new TestDevice("desktop", new Dimension(1024, 800), asList("desktop")) } }; | |
} | |
public static class TestDevice { | |
private final String name; | |
private final Dimension screenSize; | |
private final List<String> tags; | |
public TestDevice(String name, Dimension screenSize, List<String> tags) { | |
this.name = name; | |
this.screenSize = screenSize; | |
this.tags = tags; | |
} | |
public String getName() { | |
return name; | |
} | |
public Dimension getScreenSize() { | |
return screenSize; | |
} | |
public List<String> getTags() { | |
return tags; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment