当我具有多远程功能时,我需要有关如何使用对象模型的帮助,如下所示: 仅供参考,这是 webdriverio,并使用 multiremote appium 和 chromedriver
capabilities: {
myBrowser: {
"host": "localhost",
"port": 9515,
"path": "/",
capabilities: {
browserName: 'chrome',
//browserVersion: '122.0.6261.39'
}
},
myMobile: {
"host": "localhost",
"port": 4723,
capabilities: {
platformName: 'Android',
'appium:deviceName': 'Pixel 4',
'appium:platformVersion': '11.0',
'appium:automationName': 'UIAutomator2', //make sure it's in UIAutomator2, not UiAutomator2
'appium:app': path.join(process.cwd(), 'app\\android\\ApiDemos-debug.apk')
}
}
},
比方说,我的屏幕对象如下:
class TestScreen{
get firstText(){
return $('//android.widget.TextView[@content-desc="Accessibility"]');
}
async clickText(){
await this.firstText.click();
}
}
module.exports = new TestScreen();
所以我在我的规范文件中尝试了它,但失败了:
const { firstText } = require("../screen/test-screen.spec");
describe('test run', () =>{
it('test run', async () => {
await myMobile.firstText.click();
})
})
我希望代码能够使用具有多远程功能的对象模型
您正在使用多远程功能,您需要访问浏览器实例
const { myBrowser, myMobile } = browser;
class TestScreen {
get firstText() {
return $('//android.widget.TextView[@content-desc="Accessibility"]');
}
async clickText() {
await this.firstText.click();
}
}
module.exports = new TestScreen();
在您的测试规范文件中,您可以像这样使用多远程实例:
const testScreen = require("../screen/test-screen.spec");
describe('test run', () => {
it('test run', async () => {
await myMobile.url('your-app-url'); // Navigate to your app URL if required
await testScreen.clickText(); // Perform actions on your mobile instance
})
})
如果需要,请务必将
'your-app-url'
替换为您的移动应用程序的 URL。