Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.appium.java_client.android;

import static org.junit.Assert.assertEquals;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
Expand All @@ -10,10 +11,17 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.DeviceRotation;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.File;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class UIAutomator2Test {
private static AppiumDriverLocalService service;
Expand All @@ -38,6 +46,7 @@ public class UIAutomator2Test {
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
driver = new AndroidDriver<>(service.getUrl(), capabilities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}

/**
Expand Down Expand Up @@ -74,4 +83,29 @@ public class UIAutomator2Test {
driver.rotate(landscapeRightRotation);
assertEquals(driver.rotation(), landscapeRightRotation);
}

@Test public void testToastMSGIsDisplayed() throws InterruptedException {
final WebDriverWait wait = new WebDriverWait(driver, 10);
driver.startActivity("io.appium.android.apis", ".view.PopupMenu1");

MobileElement popUpElement = driver.findElement(MobileBy.AccessibilityId("Make a Popup!"));
popUpElement.click();
driver.findElement(By.xpath(".//*[@text='Search']")).click();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I did tested (from latest android server) this from your branch yesterday :) I think it failed for me here. After adding wait it failed to find the TOAST on next step. Will retest again today.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, I would request you test with this test. Typically UiAutomator2 driver works faster then old driver, adding implicit wait would be more appropriate to avoid sync issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will do that. Between can you please fix codacy issues?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to write it by testng , it can not find wait.until

assertNotNull(wait.until(ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[@text='Clicked popup menu item Search']"))));

popUpElement.click();
driver.findElement(By.xpath(".//*[@text='Add']")).click();
assertNotNull(wait.until(ExpectedConditions
.presenceOfElementLocated(By.xpath("//*[@text='Clicked popup menu item Add']"))));

popUpElement.click();
driver.findElement(By.xpath(".//*[@text='Edit']")).click();
assertNotNull(wait.until(ExpectedConditions
.presenceOfElementLocated(By.xpath("//*[@text='Clicked popup menu item Edit']"))));

driver.findElement(By.xpath(".//*[@text='Share']")).click();
assertNotNull(wait.until(ExpectedConditions
.presenceOfElementLocated(By.xpath("//*[@text='Clicked popup menu item Share']"))));
}
}