iOS Safari真机E2E自动化测试Session创建失败求助
iOS Safari真机E2E自动化测试失败问题
问题说明
测试代码在iOS 17 beta模拟器上可正常运行,但在iPhone 12(iOS 16.6)真机上无法创建会话,报错提示Remote Automation未开启(实际已开启相关设置)。
测试代码
const fs = require("fs"); const { Builder, By, Key, until } = require("selenium-webdriver"); const edge = require("selenium-webdriver/edge"); const ie = require("selenium-webdriver/ie"); const chrome = require("selenium-webdriver/chrome"); const safari = require("selenium-webdriver/safari"); const os = require("os"); const path = require("path"); const PNG = require("pngjs").PNG; const { NodeSSH, Config } = require("node-ssh"); const { execSync } = require("child_process"); const webdriver = require("selenium-webdriver") const { Preferences, Type, Level } = require("selenium-webdriver/lib/logging") const wdio = require('webdriverio') describe("test0", () => { const getDriver = async () => { const options = new safari.Options() const capabilities = webdriver.Capabilities.safari() capabilities.setPlatform('ios') capabilities.set('safari:deviceType', 'iphone') capabilities.set('safari:useSimulator', false) const driver = new Builder().forBrowser('safari').withCapabilities(capabilities).setSafariOptions(options).build() return driver } let driver beforeAll(async () => { driver = await getDriver() }, 10000000) afterAll(async () => { await driver.quit(); }); test("test", async () => { await driver.get("https://google.com"); }, 1000000); });
错误信息
SessionNotCreatedError: Could not create a session: Some devices were found, but could not be used: - iPhone (xxx-xxxxxxx): Remote Automation is turned off (turn it on via Settings > Safari > Advanced > Remote Automation) - [unknown wireless device]: device is not paired at Object.throwDecodedError (../node_modules/selenium-webdriver/lib/error.js:524:15) at parseHttpResponse (../node_modules/selenium-webdriver/lib/http.js:601:13) at Executor.execute (../node_modules/selenium-webdriver/lib/http.js:529:28)
已尝试的解决操作
- 开启iOS设备上的「Safari > 高级 > Web Inspector」
- 开启iOS设备上的「Safari > 高级 > Remote Automation」
- 开启iOS设备上的「开发者 > Enable UI Automation」
- 在Mac上执行命令
safaridriver --enable启用SafariDriver - Xcode的「Window > Device and Simulators」已成功识别到该iPhone 12真机
环境版本
- macOS Ventura 13.5
- Xcode 15 beta
- iOS 17 beta(模拟器)、iOS 16.6(iPhone 12真机)
内容的提问来源于stack exchange,提问作者Issei Morita
相关产品推荐
相关产品推荐

