Last active
September 15, 2022 09:37
-
-
Save SarahElson/e8c0e6944497f9b4633cd8ac688b2be0 to your computer and use it in GitHub Desktop.
How To Test React Native Apps On iOS And Android
This file contains hidden or 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
@Builder | |
public class DriverManager { | |
private static final ThreadLocal<AppiumDriver<MobileElement>> DRIVER = new ThreadLocal<> (); | |
private String buildName; | |
private String testName; | |
private Platform platform; | |
private String platformVersion; | |
private String deviceName; | |
private String app; | |
private static final String LT_USERNAME = System.getenv ("username"); | |
private static final String LT_ACCESS_TOKEN = System.getenv ("token"); | |
private static final String GRID_URL = "@mobile-hub.LambdaTest.com/wd/hub"; | |
private static final String URL = "http://localhost:4723/wd/hub"; | |
@SneakyThrows | |
public DriverManager createRemoteDriver () { | |
DRIVER.set (new AppiumDriver<> (new URL (format ("https://{0}:{1}{2}", LT_USERNAME, LT_ACCESS_TOKEN, GRID_URL)), | |
setCapabilities())); | |
setupDriverTimeouts (); | |
return this; | |
} | |
@SuppressWarnings ("unchecked") | |
public <D extends AppiumDriver<MobileElement>> D getDriver () { | |
if (null == DRIVER.get ()) { | |
createRemoteDriver (); | |
} | |
return (D) DRIVER.get (); | |
} | |
public void quitDriver () { | |
if (null != DRIVER.get ()) { | |
getDriver ().quit (); | |
DRIVER.remove (); | |
} | |
} | |
private void setupDriverTimeouts () { | |
getDriver ().manage () | |
.timeouts () | |
.implicitlyWait (30, TimeUnit.SECONDS); | |
} | |
private DesiredCapabilities setCapabilities() { | |
DesiredCapabilities capabilities = new DesiredCapabilities (); | |
capabilities.setCapability ("build", buildName); | |
capabilities.setCapability ("name", testName); | |
capabilities.setCapability (MobileCapabilityType.PLATFORM_NAME, platform); | |
capabilities.setCapability (MobileCapabilityType.PLATFORM_VERSION, platformVersion); | |
capabilities.setCapability (MobileCapabilityType.DEVICE_NAME, deviceName); | |
capabilities.setCapability (MobileCapabilityType.APP, app); | |
capabilities.setCapability ("isRealMobile", true); | |
capabilities.setCapability ("network", true); | |
capabilities.setCapability ("visual", true); | |
capabilities.setCapability ("console", true); | |
capabilities.setCapability ("devicelog", true); | |
return capabilities; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment