本人的代码是基于python的,java的可参考底部链接。
1、创建Root窗口(即桌面窗口)会话
# 配置Root窗口 desired_caps = {'app': 'Root', 'deviceName': 'windowsPC', 'platformName': 'windows'} # 创建Root窗口会话 driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities=desired_caps)
2、在Root窗口会话中枚举你想要测试的程序窗口的句柄(可根据窗口名称枚举)
# 在Root窗口中根据 测试窗口的名称,获取句柄 main_win = self.driver.find_element(AppiumBy.NAME, "软件中心 - NW.js") # 注意,句柄需要转为16进制 hd = hex(int(main_win.get_attribute("NativeWindowHandle")))
3、根据窗口句柄创建新会话
# 使用取到的句柄,配置测试窗口 caps = {"appTopLevelWindow": str(hd)} # 建立测试窗口的会话 driver2 = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities=caps)
4、 *** 作你的测试窗口吧(比如点击测试窗口的升级按钮)
driver2.find_element_by_name("升级").click()
参考链接:
GitHub - microsoft/WinAppDriver at v1.0https://github.com/Microsoft/WinAppDriver/tree/v1.0#creating-a-desktop-session
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)