selenium-webdriver - Appium 和 iOS Mobile Safari 自动化,能做到吗?

标签 selenium-webdriver remotewebdriver appium

我无法在 iOS 模拟器上使用 Appium 与 Safari 移动浏览器进行任何自动化。在我的 Java 项目中,Safari 将启动,但浏览器甚至不会导航到指定的网站。谁能告诉我我的代码做错了什么?

1) 在我的 OSX 机器上启动 Appium 应用程序。它配置了以下设置:

IP Address: 127.0.0.1
Port: 4723
Force Device: Checked - iPhone
User Mobile Safari: Checked

(注意:当我运行我的项目时,Appium 应用程序日志屏幕上没有消息滚动。以前,我提示缺少 iOS 6.0 库,但是当我复制 6.1 iOS 库然后将目录重命名为 6.0 时,消息消失了.)

2)启动Eclipse并打开Appium项目

3) 右键单击​​测试代码,然后单击 RunAs Junit

4) iPhone 模拟器启动——iPhone iOS 6.1

5) Mobile Safari 启动...然后无处可去(应该去cnn.com)。我没有错误。

Appium Java 项目真的可以用于移动 Safari 自动化吗? 我在 Appium 示例代码存储库中没有看到任何 Safari 自动化示例。

是什么赋予了?

谢谢,

拉里

------------------Java代码如下--------------------- -----------

Eclipse Juno 用于运行我的 Java/Appium 项目。这是 Java JUnit 项目代码的简化列表(经过相应修改,并与 iWebDriver 和已弃用的 iPhoneDriver() 一起使用,效果很好):
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class AppiumiPhoneWebDriverDemo {

    private String baseUrl;
    private WebDriver driver;

    @Before
    public void setup() throws Exception
    {

        WebDriver driver;
        DesiredCapabilities cap = new DesiredCapabilities();
        //cap.setCapability("", "");
        //cap.setCapability("browsername", "");
        //cap.setCapability("os", "iOS 6.1");
        cap.setCapability("device", "iPhone Simulator");
        cap.setCapability("app", "safari");

        driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), cap);

    baseUrl = "http://www.cnn.com";

    }   

    @After
    public void tearDown() throws Exception
    {

    driver.quit();

    }


    @Test
    public void test_searchWorks() throws Exception
    {
        this.driver.get(baseUrl);

        driver.quit();
    }

  }

最佳答案

你绝对可以做到这一点。

看到这个代码

"use strict";

require("./helpers/setup");

var wd = require("wd"),
    _ = require('underscore'),
    serverConfigs = require('./helpers/appium-servers');

describe("ios safari", function () {
  this.timeout(300000);
  var driver;
  var allPassed = true;

  before(function () {
    var serverConfig = process.env.SAUCE ?
      serverConfigs.sauce : serverConfigs.local;
    driver = wd.promiseChainRemote(serverConfig);
    require("./helpers/logging").configure(driver);

    var desired = _.clone(require("./helpers/caps").ios81);
    desired.browserName = 'safari';
    if (process.env.SAUCE) {
      desired.name = 'ios - safari';
      desired.tags = ['sample'];
    }
    return driver.init(desired);
  });

  after(function () {
    return driver
      .quit()
      .finally(function () {
        if (process.env.SAUCE) {
          return driver.sauceJobStatus(allPassed);
        }
      });
  });

  afterEach(function () {
    allPassed = allPassed && this.currentTest.state === 'passed';
  });


  it("should get the url", function () {
    return driver
      .get('https://www.google.com')
      .sleep(1000)
      .waitForElementByName('q', 5000)
        .sendKeys('sauce labs')
        .sendKeys(wd.SPECIAL_KEYS.Return)
      .sleep(1000)
      .title().should.eventually.include('sauce labs');
  });

  it("should delete cookie passing domain and path", function () {
    var complexCookieDelete = function(name, path, domain) {
      return function() {
        path = path || '|';
        return driver.setCookie({name: name, value: '', path: path, 
          domain: domain, expiry: 0});        
      };
    };

    return driver
      .get('http://en.wikipedia.org')
      .waitForElementByCss('.mediawiki', 5000)
      .allCookies() // 'GeoIP' cookie is there
      .deleteCookie('GeoIP') 
      .allCookies() // 'GeoIP' is still there, because it is set on
                    // the .wikipedia.org domain
      .then(complexCookieDelete('GeoIP', '/', '.wikipedia.org'))
      .allCookies() // now 'GeoIP' cookie is gone
      .sleep(1000);
  });

});

关于selenium-webdriver - Appium 和 iOS Mobile Safari 自动化,能做到吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16678203/

相关文章:

java - 元素尚未准备好被选择,但 wait.until() 仍然继续吗?

java - selenium webdriver 中 xpath 的区别?

android - 错误 : Could not get the Java version. 是否安装了 Java?

java - appium - 选择父节点

selenium - 如何在远程webdriver/grid配置中在节点端设置firefox配置文件

java - 使用 Appium 删除用于 IPAD 和 IPHONE 真实设备的移动 Safari 浏览器 Cookie

java - 无法增加android模拟器内存

python-3.x - Runtime.callFunctionOn 抛出异常 : Error: LavaMoat - property "Proxy" of globalThis is inaccessible under scuttling mode

java - RemoteWebDriver 无法转换为 org.openqa.selenium.TakesScreenshot (Java)

java - RemoteWebDriver - 调试 headless Docker 容器