【问题标题】:work with IOS and android together in same code在相同的代码中与 IOS 和 android 一起工作
【发布时间】:2021-09-21 14:10:04
【问题描述】:

我正在寻找一种方法来使用适用于 android 和 IOS 真实设备的一个驱动程序,例如,现在如果我以 IOS = IOSDriver<MobileElement> driver; 开头并解锁我的设备,例如我的代码是 driver = new IOSDriver<>(url, dc); 和 @ android 的 987654323@ 相同,但如果我的驱动程序是 AppiumDriver driver;,代码将无法在 driver.unlockDevice(); 上运行,那么在一个驱动程序中同时使用 android 和 ios 的选项有哪些?

【问题讨论】:

    标签: java android ios selenium appium


    【解决方案1】:

    这是 POC - 处理得不是很好。只是为了快速浏览。
    而且...我不确定 iOS 驱动程序 - 如果它甚至可以处理设备解锁 - 可能只在模拟器上...

    public static AppiumDriver<MobileElement> driver;
    public static DesiredCapabilities iosCaps;
    public static DesiredCapabilities androidCaps;
    
    public void caps() {
        iosCaps = new DesiredCapabilities();
        iosCaps.setCapability("deviceName", "iPhone 5");
    
        androidCaps = new DesiredCapabilities();
        androidCaps.setCapability("deviceName", "Samsung X");
    }
    
    
    protected void startDriver() throws MalformedURLException {
        caps();
        if (device == android) {
            driver = new AndroidDriver<>(new URL("appium url"), androidCaps);
        } else if (device == ios) {
            driver = new IOSDriver<>(new URL("appium url"), iosCaps);
        }
    }
    
    public void iosLock() {
        ((IOSDriver) driver).lockDevice();
        ((IOSDriver<MobileElement>) driver).lockDevice();
    }
    
    public void androidLock() {
        ((AndroidDriver) driver).lockDevice();
    }
    

    【讨论】:

      猜你喜欢
      • 2023-02-02
      • 1970-01-01
      • 2021-07-16
      • 1970-01-01
      • 2021-11-21
      • 2014-05-08
      • 2021-02-27
      • 1970-01-01
      • 2013-08-22
      相关资源
      最近更新 更多