-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lindsay Walker
committed
Dec 28, 2020
1 parent
cf4301b
commit f64cbd5
Showing
18 changed files
with
895 additions
and
8 deletions.
There are no files selected for viewing
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
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
3 changes: 1 addition & 2 deletions
3
Final/src/test/resources/config/mobile_android_EMU_parallel_test.xml
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
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,105 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>SauceAppiumSample</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<testngXmlDir>src/test/resources/config</testngXmlDir> | ||
<testngXmlFile>mobile_android_EMU_parallel_test.xml</testngXmlFile> | ||
<testng.version>6.14.3</testng.version> | ||
<commons-logging.version>1.2</commons-logging.version> | ||
<selenium.version>3.141.59</selenium.version> | ||
<maven-failsafe-plugin.version>2.19.1</maven-failsafe-plugin.version> | ||
<sauce.version>1.0.44</sauce.version> | ||
<appium.version>7.2.0</appium.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<version>${testng.version}</version> | ||
</dependency> | ||
|
||
<!-- Selenium --> | ||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-api</artifactId> | ||
<version>${selenium.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-java</artifactId> | ||
<version>${selenium.version}</version> | ||
</dependency> | ||
|
||
<!-- Apache Commons Logging --> | ||
<dependency> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
<version>${commons-logging.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</artifactId> | ||
<version>1.3</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<version>1.2.17</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>3.10.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.saucelabs</groupId> | ||
<artifactId>saucerest</artifactId> | ||
<version>${sauce.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.appium</groupId> | ||
<artifactId>java-client</artifactId> | ||
<version>${appium.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.0.0-M4</version> | ||
<configuration> | ||
<suiteXmlFiles> | ||
<suiteXmlFile>${testngXmlDir}/${testngXmlFile}</suiteXmlFile> | ||
</suiteXmlFiles> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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,104 @@ | ||
package tests; | ||
|
||
import io.appium.java_client.MobileBy; | ||
import io.appium.java_client.android.AndroidDriver; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.TimeoutException; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.net.URL; | ||
|
||
|
||
public class BasicTest { | ||
|
||
private static final String APP = "/Users/lindsaywalker/Documents/Example_Tests/Android.SauceLabs.Mobile.Sample.app.2.7.0.apk"; | ||
private static final String APPIUM = "http://localhost:4723/wd/hub"; | ||
|
||
private AndroidDriver driver; | ||
|
||
String usernameID = "test-Username"; | ||
String passwordID = "test-Password"; | ||
String submitButtonID = "test-LOGIN"; | ||
By ProductTitle = By.xpath("//android.widget.TextView[@text='PRODUCTS']"); | ||
|
||
@BeforeMethod | ||
public void setUp() throws Exception { | ||
DesiredCapabilities capabilities = new DesiredCapabilities(); | ||
capabilities.setCapability("deviceName", "Android Emulator"); //This will change to type of device e.g. Pixel 4 on Saucelabs | ||
capabilities.setCapability("platformName", "Android"); | ||
capabilities.setCapability("platformVersion","9.0" ); //add platformVersion | ||
capabilities.setCapability("automationName", "UiAutomator2"); | ||
capabilities.setCapability("appWaitActivity", "com.swaglabsmobileapp.MainActivity"); | ||
capabilities.setCapability("app", APP); | ||
|
||
|
||
driver = new AndroidDriver(new URL(APPIUM), capabilities); | ||
|
||
} | ||
|
||
@AfterMethod | ||
public void tearDown() { | ||
if (driver != null) { | ||
driver.quit(); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void loginToSwagLabsTestValid() { | ||
System.out.println("Sauce - Start loginToSwagLabsTestValid test"); | ||
|
||
login("standard_user", "secret_sauce"); | ||
|
||
// Verification | ||
Assert.assertTrue(isOnProductsPage()); | ||
} | ||
|
||
@Test | ||
public void loginTestValidProblem() { | ||
System.out.println("Sauce - Start loginTestValidProblem test"); | ||
|
||
login("problem_user", "secret_sauce"); | ||
|
||
// Verification - we on Product page | ||
Assert.assertTrue(isOnProductsPage()); | ||
} | ||
|
||
public void login(String user, String pass){ | ||
|
||
WebDriverWait wait = new WebDriverWait(driver, 5); | ||
final WebElement usernameEdit = wait.until(ExpectedConditions.visibilityOfElementLocated(new MobileBy.ByAccessibilityId(usernameID))); | ||
|
||
usernameEdit.click(); | ||
usernameEdit.sendKeys(user); | ||
|
||
WebElement passwordEdit = driver.findElementByAccessibilityId(passwordID); | ||
passwordEdit.click(); | ||
passwordEdit.sendKeys(pass); | ||
|
||
WebElement submitButton = driver.findElementByAccessibilityId(submitButtonID); | ||
submitButton.click(); | ||
} | ||
|
||
public boolean isOnProductsPage() { | ||
//Create an instance of a Appium explicit wait so that we can dynamically wait for an element | ||
WebDriverWait wait = new WebDriverWait(driver, 5); | ||
|
||
//wait for the product field to be visible and store that element into a variable | ||
try { | ||
wait.until(ExpectedConditions.visibilityOfElementLocated(ProductTitle)); | ||
} catch (TimeoutException e){ | ||
System.out.println("*** Timed out waiting for product page to load."); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
|
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,6 @@ | ||
package tests; | ||
|
||
public class Config { | ||
public static final String region = System.getProperty("region", "us"); | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
Mod2/2.07/src/test/java/tests/Mobile_Android_Browser_Test.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,96 @@ | ||
package tests; | ||
|
||
import io.appium.java_client.MobileBy;// removed | ||
import io.appium.java_client.android.AndroidDriver; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.TimeoutException; // removed | ||
import org.openqa.selenium.WebElement; // removed | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; // removed | ||
import org.openqa.selenium.support.ui.WebDriverWait; // removed | ||
import org.testng.Assert; | ||
import org.testng.ITestResult; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.lang.reflect.Method; | ||
import java.net.URL; | ||
|
||
import static tests.Config.region; | ||
|
||
public class Mobile_Android_Browser_Test { | ||
// private static final String APP = "/Users/lindsaywalker/Documents/Example_Tests/Android.SauceLabs.Mobile.Sample.app.2.7.0.apk"; | ||
// private static final String APPIUM = "http://localhost:4723/wd/hub"; // See the new URL declared according to region. | ||
String appUrl = "https://www.saucedemo.com/"; //added | ||
private AndroidDriver driver; | ||
// String usernameID = "test-Username"; | ||
// String passwordID = "test-Password"; | ||
// String submitButtonID = "test-LOGIN"; | ||
// By ProductTitle = By.xpath("//android.widget.TextView[@text='PRODUCTS']"); | ||
By usernameInput = By.id("user-name"); | ||
By passwordInput = By.id("password"); | ||
By submitButton = By.className("btn_action"); | ||
By productTitle = By.className("product_label"); | ||
//all 4 vars changed from app test | ||
|
||
@BeforeMethod | ||
public void setUp () throws Exception { | ||
System.out.println("Sauce Android Mobile Browser EMU - BeforeMethod hook"); //added | ||
// URL url; //added | ||
String username = System.getenv("SAUCE_USERNAME"); | ||
String accesskey = System.getenv("SAUCE_ACCESS_KEY"); | ||
String sauceUrl; | ||
if (region.equalsIgnoreCase("eu")) { | ||
sauceUrl = "@ondemand.eu-central-1.saucelabs.com:443"; | ||
} else { | ||
sauceUrl = "@ondemand.us-west-1.saucelabs.com:443"; | ||
} | ||
String SAUCE_REMOTE_URL = "https://" + username + ":" + accesskey + sauceUrl + "/wd/hub"; | ||
URL url = new URL(SAUCE_REMOTE_URL); | ||
|
||
DesiredCapabilities capabilities = new DesiredCapabilities(); | ||
capabilities.setCapability("deviceName", "Android GoogleAPI Emulator"); //changed to GoogleAPI Emulator | ||
capabilities.setCapability("platformName", "Android"); | ||
capabilities.setCapability("platformVersion","9.0" ); | ||
capabilities.setCapability("automationName", "UiAutomator2"); | ||
// capabilities.setCapability("appWaitActivity", "com.swaglabsmobileapp.MainActivity"); //deleted | ||
capabilities.setCapability("browserName", "Chrome");// added | ||
// driver = new AndroidDriver(new URL(APPIUM), capabilities); //removed | ||
driver = new AndroidDriver(url, capabilities); //added | ||
|
||
} | ||
|
||
@AfterMethod | ||
public void teardown() { | ||
if (driver != null) { | ||
driver.quit(); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void loginToSwagLabsTestValid() { | ||
System.out.println("Sauce - Start loginToSwagLabsTestValid test"); | ||
login("standard_user", "secret_sauce"); | ||
|
||
// Verification | ||
Assert.assertTrue(isOnProductsPage()); | ||
} | ||
|
||
public void login(String user, String pass){ | ||
driver.get(appUrl); | ||
driver.findElement(usernameInput).sendKeys(user); | ||
driver.findElement(passwordInput).sendKeys(pass); | ||
|
||
driver.findElement(submitButton).click(); | ||
|
||
} | ||
|
||
public boolean isOnProductsPage() { | ||
|
||
return driver.findElement(productTitle).isDisplayed(); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.