java - 寻找 driver.scrollTo ("Views"的解决方案)

标签 java testing appium

我是 Apium 和 java 的初学者,我一直在寻找 driver.scrollTo("Views") 的解决方案,我尝试了以下代码,但在运行时出现以下错误:

无法创建新 session 。 (原始错误:用于启动应用程序的 Activity 不存在或无法启动!确保它存在并且是可启动的 Activity)(警告:服务器未提供任何堆栈跟踪信息)

package Android;
import static org.junit.Assert.assertNotNull;
import io.appium.java_client.android.AndroidDriver;

import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ScrollingToText {

     AndroidDriver driver;

     @BeforeTest
     public void setUp() throws Exception {
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability("deviceName", "0123456789ABCDEF");
      capabilities.setCapability("browserName", "Android");
      capabilities.setCapability("platformVersion", "5.0");
      capabilities.setCapability("platformName", "Android");
      capabilities.setCapability("appPackage", "com.hmh.api");
      capabilities.setCapability("appActivity","com.hmh.ApiDemos");
      driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
      driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
     }

     @Test
     public void findScrollable() throws InterruptedException {
      //Scroll till element which contains "Views" text If It Is not visible on screen.
     // driver.scrollTo("Views");
     driver.findElementByAccessibilityId("Views").click();
     WebElement radioGroup = driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"+ ".resourceId(\"android:id/list\")).scrollIntoView("
             + "new UiSelector().text(\"Radio Group\"));");
     assertNotNull(radioGroup.getLocation());

      // Click on Views/.
      driver.findElement(By.name("Views")).click();
      System.out.println("Scrolling has been started to find text -> Tabs.");
      // Scroll till element which contains Tabs text.
      // driver.scrollTo("Tabs");
      driver.findElementByAccessibilityId("Tabs").click();

      System.out.println("Tabs text has been found and now clicking on It.");
      // Click on Tabs.
      driver.findElement(By.name("Tabs")).click();
     }

     @AfterTest
     public void End() {
      driver.quit();
     }
    }

最佳答案

 (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity) 

当您的设备上没有安装应用程序时,会出现上述错误。

请先安装它,然后运行它应该运行的测试脚本。

希望这些对你有帮助。

关于java - 寻找 driver.scrollTo ("Views"的解决方案),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42644848/

相关文章:

java - Java 中的动态绑定(bind)。使用 Parent 作为类型和 Child 作为对象有什么好处和缺点?

java - 无法弄清楚如何让 Circle 类工作

java - 如何确定在哪个屏幕上显示 JDialog

c# - 如何使用 content-desc 单击按钮

testing - 使用 html 报告按顺序运行 Testcafe 测试

java - Appium 的 implicitlyWait 不起作用

android - Protractor 的 waitForAngular() 在 angular-webapp 上失败(真实设备上的 appium/chrome)

java - 如何以编程方式将webservice发布到tomcat

ruby-on-rails - 最快的 Rails 测试运行器 : spork and zentest?

gitlab - 使用 appium 为移动自动化设置 gitlab cicd?