Mình gặp 1 issue về việc click element sau khi swipe list view để tìm element. Phía dưới là source code của mình cho app Amazon. Nội dung vấn đề đơn giản là: Sau khi mình swipe và tìm được element hiển thị trên màn hình. Nhưng lúc này mình cho tao tác click vào element thì mình lại không thấy phản hồi chuyển trang. Mình nghĩ là thao tác click vẫn ko thực hiện được mặc dù ko có error nào hiện lên.
Mình tester trên thiết bị thật là Nexus 4. Đã thử trên galaxy V nhưng vẫn bị chung tình trạng. Bà kon ai có biết cách giải quyết thì tư vấn giùm mình. Mình cảm ơn nhiều.
Code: Select all
public class FirstTest {
private AppiumDriver driver;
private Dimension size;
@BeforeClass
public void Setup() throws MalformedURLException {
String appActivityText = "com.amazon.mShop.home.HomeActivity";
String appPackageText = "in.amazon.mShop.android.shopping";
String fileLocation = "/system/app/";
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "\\STC");
File app = new File(appDir, fileLocation);
System.out.println(app);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.PLATFORM, "Android");
capabilities.setCapability(CapabilityType.VERSION, "4.4.2");
capabilities.setCapability("deviceName", "420373d0de528100");//420373d0de528100 01a61316598f30e6
capabilities.setCapability("newCommandTimeout", "100");
// capabilities.setCapability("app", "Chrome"/*app.getAbsolutePath()*/);
capabilities.setCapability("appPackage", appPackageText);
capabilities.setCapability("appActivity", appActivityText);
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
@Test
public void Login() throws Exception {
// Click on Shop by Deparment link
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
System.out.println("Click on Shop by Deparment link");
driver.findElement(By.id("web_home_shop_by_department_label")).click();
Thread.sleep(1000);
WebElement element = driver.findElement(By.name("Office Products Link"));
ScrollToElement(driver, element);
Thread.sleep(3000);
// element = driver.findElement(By.name("Home"));
// TouchAction action = new TouchAction(driver);
// action.tap(372,466).perform();
// action.moveTo(element).perform();
driver.findElement(By.name("Office Products Link")).click();
}
@AfterClass
public void closeApp() {
// driver.closeApp();
}
public static void ScrollToElement(AppiumDriver driver, WebElement element){
size = driver.manage().window().getSize();
// Find swipe start and end point from screen's with and height.
// Find starty point which is at bottom side of screen.
int start = (int) (size.height * 0.20);
int starty = (int) (size.height * 0.80);
// Find endy point which is at top side of screen.
int endy = (int) (size.height * 0.20);
// Find horizontal point where you wants to swipe. It is in middle of
// screen width.
int startx = size.width / 2;
while (true) {
driver.swipe(startx, starty, startx, endy, 3000);
start = start + (starty - endy);
if (element.getLocation().getY() - start < size.height - endy) {
break;
}
}
}
}