-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mid session app installations example
- Loading branch information
Showing
2 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
...src/test/java/com/examples/mid_session_app_installs/MidSessionAppInstallsAndroidTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.examples.mid_session_app_installs; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.helpers.SauceAppiumTestWatcher; | ||
import io.appium.java_client.android.AndroidDriver; | ||
import lombok.var; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestName; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.MutableCapabilities; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static com.helpers.Constants.*; | ||
|
||
/** | ||
* Android Native App Tests | ||
*/ | ||
public class MidSessionAppInstallsAndroidTest { | ||
|
||
By productsScreenLocator = By.xpath("//*[@content-desc=\"products screen\"]"); | ||
By sortButtonLocator = By.xpath("//*[@content-desc=\"sort button\"]"); | ||
By sortModalLocator = By.xpath("//*[@content-desc=\"active option\"]"); | ||
|
||
|
||
@Rule | ||
public TestName name = new TestName(); | ||
|
||
//This rule allows us to set test status with Junit | ||
@Rule | ||
public SauceAppiumTestWatcher resultReportingTestWatcher = new SauceAppiumTestWatcher(); | ||
|
||
private AndroidDriver driver; | ||
|
||
@Before | ||
public void setup() throws MalformedURLException { | ||
System.out.println("Sauce Android Native App - Before hook"); | ||
MutableCapabilities capabilities = new MutableCapabilities(); | ||
MutableCapabilities sauceOptions = new MutableCapabilities(); | ||
URL url; | ||
|
||
switch (region) { | ||
case "us": | ||
url = new URL(SAUCE_US_URL); | ||
System.out.println("Sauce REGION US"); | ||
break; | ||
case "eu": | ||
default: | ||
url = new URL(SAUCE_EU_URL); | ||
System.out.println("Sauce REGION EU"); | ||
break; | ||
} | ||
|
||
// For all capabilities please check | ||
// http://appium.io/docs/en/writing-running-appium/caps/#general-capabilities | ||
// Use the platform configuration https://saucelabs.com/platform/platform-configurator#/ | ||
// to find the emulators/real devices names, OS versions and appium versions you can use for your testings | ||
|
||
capabilities.setCapability("platformName", "Android"); | ||
capabilities.setCapability("appium:automationName", "UiAutomator2"); | ||
capabilities.setCapability("appium:deviceName", "Samsung.*"); | ||
sauceOptions.setCapability("resigningEnabled", true); | ||
sauceOptions.setCapability("sauceLabsNetworkCaptureEnabled", true); | ||
capabilities.setCapability("appium:platformVersion", "13"); | ||
String appName = "mda-1.0.14-17.apk"; | ||
capabilities.setCapability("appium:app", "storage:filename=" +appName); | ||
|
||
// Sauce capabilities | ||
sauceOptions.setCapability("name", name.getMethodName()); | ||
sauceOptions.setCapability("build", "myApp-job-1"); | ||
List<String> tags = Arrays.asList("sauceDemo", "Android", "Demo", "mid-session-app-installs"); | ||
sauceOptions.setCapability("tags", tags); | ||
sauceOptions.setCapability("username", System.getenv("SAUCE_USERNAME")); | ||
sauceOptions.setCapability("accessKey", System.getenv("SAUCE_ACCESS_KEY")); | ||
|
||
capabilities.setCapability("sauce:options", sauceOptions); | ||
|
||
try { | ||
driver = new AndroidDriver(url, capabilities); | ||
} catch (Exception e){ | ||
System.out.println("Error to create Android Driver: " + e.getMessage()); | ||
return; | ||
} | ||
//Setting the driver so that we can report results | ||
resultReportingTestWatcher.setDriver(driver); | ||
} | ||
|
||
@Test | ||
public void upgradeAppInMidSession() throws MalformedURLException { | ||
// Navigate to the "About" page | ||
navigateToAbout(); | ||
|
||
// Install a new version | ||
var results = driver.executeScript("mobile:installApp", ImmutableMap.of("appPath", "storage:filename=mda-1.0.17-20.apk")); | ||
System.out.println(results); | ||
|
||
// Launch the new app | ||
driver.executeScript("mobile: startActivity", ImmutableMap.of("intent", "com.saucelabs.mydemoapp.android/.view.activities.SplashActivity")); | ||
|
||
waiting(3); | ||
|
||
// Navigate to the "About" page | ||
navigateToAbout(); | ||
} | ||
|
||
private void navigateToAbout(){ | ||
driver.findElement(By.id("com.saucelabs.mydemoapp.android:id/menuIV")).click(); | ||
List<WebElement> menuItems = driver.findElements(By.id("com.saucelabs.mydemoapp.android:id/itemTV")); | ||
// About is the 6 item | ||
menuItems.get(5).click(); | ||
// For the Video... | ||
waiting(5); | ||
} | ||
private void waiting(int sec){ | ||
try | ||
{ | ||
Thread.sleep(sec*1000); | ||
} | ||
catch(InterruptedException ex) | ||
{ | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...pium-app-examples/src/test/java/com/examples/mid_session_app_installs/README.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Using Test App Upgrades/Mid-Session App Installations | ||
This folder contains example for using Test App Upgrades/Mid-Session App Installations on Android real devices. | ||
Please read the documents about this feature [here](https://docs.saucelabs.com/mobile-apps/automated-testing/appium/test-app-upgrades/) | ||
|
||
## Important information | ||
### Environment variables for Sauce Labs | ||
The examples in this repository use environment variables, make sure you've added the following | ||
|
||
# For Sauce Labs Emulators/Simulators/Real devices | ||
export SAUCE_USERNAME=******** | ||
export SAUCE_ACCESS_KEY=******* | ||
|
||
### Demo app(s) | ||
The demo app that has been used for all these tests can be found [here](https://github.com/saucelabs/my-demo-app-android/releases). | ||
You can find in the [apps folder](./apps) the two versions of the app that is used for this example | ||
|
||
### Upload apps to Sauce Storage | ||
You need to upload the apps to the Sauce Storage. Please check [here](https://docs.saucelabs.com/mobile-apps/app-storage/) how to do it. | ||
**If you don't do that then the scripts can't find the apps!** | ||
|
||
## Run tests on Sauce Labs Android real devices | ||
You can run the Android test on Sauce platform with: | ||
|
||
// If using the US DC | ||
mvn clean test -Dtest=MidSessionAppInstallsAndroidTest -Dregion=us | ||
|
||
// If using the EU DC | ||
mvn clean test -Dtest=MidSessionAppInstallsAndroidTest -Dregion=eu | ||
|
||
The tests will be executed on any available Samsung device, OS 13. | ||
|
||
> NOTE: Make sure you are in the folder `appium-app-examples` when you execute this command |