Appium iOS自动接受本机应用程序警报,关闭本机应用程序警报。

huangapple go评论69阅读模式
英文:

Appium iOS autoAcceptAlerts Closing Native App Alert

问题

我试图在物理iPhone上使用Appium、Cucumber和TestNG运行测试。该应用程序有很多权限警报,我通过设置驱动程序能力 appium:autoAcceptAlerts, true 来处理这些警报。然而,这也会关闭一些本机应用程序警报。

具体来说,有一个警报询问用户是否要确认更改密码。当启用autoAcceptAlerts时,它会为我选择CANCEL选项,而我想逐个测试来处理警报。

我尝试过使用驱动程序设置 acceptAlertButtonSelector,但从未奏效。

我如何让Appium过滤掉某些警报以用于autoAcceptAlerts,或在我的测试步骤中临时禁用它?

注意:有一些警报有相同的选项,但Appium会忽略autoAcceptAlerts,但有些警报它会自行处理。

英文:

I am trying to run tests on an physical iPhone using Appium, Cucumber, and TestNG. The app has quite a few permission alerts that I am handling by setting the driver capability appium:autoAcceptAlerts, true. However this is also closing some native app alerts.

Specifically there is an alert that asks the user to confirm if they want to change their password. When autoAcceptAlerts is enabled it is selecting the CANCEL option for me when I would like to handle the alert on a test by test bases.

I tried using the driver setting acceptAlertButtonSelector but that never worked for me.

How can I get Appium to filter out certain alerts for autoAcceptAlerts or temporarily disable it as part of my test step?

Note: There are some alerts with the same options that appium ignores for the autoAcceptAlert but others it handles itself.

答案1

得分: 1

调用此方法在需要的地方,使用所需的参数。

import io.appium.java_client.MobileBy;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.Alert;
/**
 * 处理弹窗。
 *
 * @param 如果为true,接受弹窗;如果为false,关闭弹窗。
 */
public void handleAlert(boolean accept) {
    try {
        Alert alert = driver.switchTo().alert();
        if (accept) {
            alert.accept();
        } else {
            alert.dismiss();
        }
    } catch (Exception e) {
        // 处理可能在处理弹窗时发生的任何异常。
    }
}
英文:

call this method where needed with the required parameter

import io.appium.java_client.MobileBy;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.Alert;
/**
 * Handle alert .
 *
 * @param If true, accept the alert; if false, dismiss the alert.
 */
public void handleAlert(boolean accept) {
    try {
        Alert alert = driver.switchTo().alert();
        if (accept) {
            alert.accept();
        } else {
            alert.dismiss();
        }
    } catch (Exception e) {
        // Handle any exception that might occur while handling the alert.
    }
}

</details>



huangapple
  • 本文由 发表于 2023年7月7日 01:31:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76631256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定