如何在Appium中检索短信确认码

发布于 2025-01-12 16:46:51 字数 116 浏览 3 评论 0原文

我正在使用 Appium 和 TestNG 对应用程序运行测试。但是,我必须首先登录该应用程序,该应用程序需要输入短信确认码。有什么方法可以将其包含在我的代码中吗?有什么方法可以拦截该短信代码并将其输入到应用程序中吗?

I am running tests to an app with Appium and TestNG. However, I must first log in to the app which requires an SMS confirmation code to be entered. Is there any way I can include this in my code? Some way to intercept that SMS code and enter it in the app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味拾荒者 2025-01-19 16:46:51

最简单的解决方案是单击 OTP 输入框,然后会出现“自动填充代码”文本,然后等待“验证”按钮显示“启用/选中”。然后单击它并继续测试。

第二个解决方案是我在 appium 论坛上找到的
https://discuss.appium.io/t/how-to-read-sms-from-native-messaging-app-pe-to-read-otp/10409

Simplest solution is click on the OTP inputbox then there would be text to 'Autofill code' and make a wait till your "Verify" button says either is "enabled/checked". Then click on it and proceeds with the test .

2nd Solution would be something i found on appium discussion forum
https://discuss.appium.io/t/how-to-read-sms-from-native-messaging-app-p-e-to-read-otp/10409

深空失忆 2025-01-19 16:46:51

这在 java、C# 和 Python 中运行良好。返回的 JSON 格式错误,因此需要进行字符串操作来读取它。这里贴出Java代码供大家参考。

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("platformName", "android");
cap.setCapability("appium:deviceName", "mydevice-redmi");
cap.setCapability("udid", "emulator-5554");

AppiumDriver driver = new AppiumDriver(new URL("http://localhost:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
        
HashMap<String, Integer> map=new HashMap<>();
map.put("max", 3);      
String result=driver.executeScript("mobile: listSms", map).toString();      
System.out.println(result);
    

This works well in java, C#, and Python. The returned JSON format is wrong so work on string manipulation to read it. Posting here Java code for your reference.

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("platformName", "android");
cap.setCapability("appium:deviceName", "mydevice-redmi");
cap.setCapability("udid", "emulator-5554");

AppiumDriver driver = new AppiumDriver(new URL("http://localhost:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
        
HashMap<String, Integer> map=new HashMap<>();
map.put("max", 3);      
String result=driver.executeScript("mobile: listSms", map).toString();      
System.out.println(result);
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文