【问题标题】:Removing a specific adb shell command in favor of using Appium删除特定的 adb shell 命令以支持使用 Appium
【发布时间】:2016-08-30 20:57:00
【问题描述】:

我正在审查一些现有的基于 Appium 的 Android 应用自动化,并且在一些地方有从代码中对 adb 的直接 shell 调用。我怀疑作者这样做是因为他或她找不到使用 Appium 执行等效操作的好方法。这是 adb 命令:

adb shell am start -d https://<various_url_details_here>

当自动化执行时,它会触发“打开方式”对话框,以便用户可以点击各种选项,例如浏览器或应用程序。有没有办法在不直接执行 shell 命令的情况下使用 Appium 执行这个特定命令?如果存在这样的方式,是不是一个好主意?

【问题讨论】:

    标签: android shell adb appium


    【解决方案1】:

    使用AndroidDriver.get()函数:

    private WebDriver driver;
    
    @Before
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(..., ...);
        //--------------------------------------------------------------//
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }
    
    @Test
    public void testcase_001() throws Exception{
        driver.get("https://<various_url_details_here>");  // Here is what you want
        WebDriverWait wait = new WebDriverWait(driver, 30);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.id(...")));
        Thread.sleep(5000);
     }
    
    @After
    public void tearDown() throws Exception {
        driver.quit();
    }
    

    【讨论】:

    • 谢谢!我没想到会这么简单。考虑到解决方案的简单性,我不确定为什么还要以这种方式使用 adb。也许还有一些我不知道的额外内容。
    猜你喜欢
    • 2015-05-28
    • 2013-04-02
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 2013-12-21
    • 2019-03-20
    相关资源
    最近更新 更多