Created
September 15, 2021 18:23
-
-
Save dannyshain/12155a4dfe0a6de1f4af8a50d0ecdd1d to your computer and use it in GitHub Desktop.
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
import io.appium.java_client.AppiumDriver; | |
import io.appium.java_client.MobileElement; | |
import io.appium.java_client.android.AndroidDriver; | |
import org.openqa.selenium.By; | |
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.AfterTest; | |
import org.testng.annotations.BeforeTest; | |
import org.testng.annotations.Test; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.List; | |
@SuppressWarnings("rawtypes") | |
public class FirstAndroidTest { | |
AppiumDriver driver; | |
private static final By addPlant = By.id("add_plant"); | |
private static final By add = By.id("fab"); | |
@BeforeTest | |
public void setUp() throws MalformedURLException { | |
DesiredCapabilities caps = new DesiredCapabilities(); | |
caps.setCapability("platformName", "Android"); | |
caps.setCapability("platformVersion", "10"); | |
caps.setCapability("deviceName", "Android Emulator"); | |
caps.setCapability("app", "/Users/moataz.eldebsy/sunflower/app/build/outputs/apk/debug/app-debug.apk"); | |
driver = new AndroidDriver(new URL("http://localhost:4724/wd/hub"), caps); | |
} | |
@Test | |
public void add_plant_test() { | |
WebDriverWait wait = new WebDriverWait(driver, 10); | |
MobileElement plantList = (MobileElement) driver.findElementByAccessibilityId("Plant list"); | |
MobileElement myGarden = (MobileElement) driver.findElementByAccessibilityId("My garden"); | |
wait.until(ExpectedConditions.elementToBeClickable(plantList)).click(); | |
wait.until(ExpectedConditions.elementToBeClickable(myGarden)).click(); | |
wait.until(ExpectedConditions.presenceOfElementLocated(addPlant)).click(); | |
List<MobileElement> listElements = driver.findElements(By.id("plant_item_title")); | |
for (MobileElement el : listElements) { | |
if (el.getText().equalsIgnoreCase("Avocado")) { | |
el.click(); | |
break; | |
} | |
} | |
wait.until(ExpectedConditions.presenceOfElementLocated(add)).click(); | |
driver.navigate().back(); | |
driver.findElementByAccessibilityId("My garden").click(); | |
By plant_name = By.id("plant_name"); | |
wait.until(ExpectedConditions.presenceOfElementLocated(plant_name)); | |
Assert.assertTrue(driver.findElement(plant_name).getAttribute("text") | |
.equalsIgnoreCase("Avocado")); | |
} | |
@AfterTest | |
public void tearDown() { | |
if (null != driver) { | |
driver.quit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment