4

我无法在 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();
    }

  }
4

4 回答 4

2

你绝对可以做到这一点。

看到这个代码

"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);
  });

});
于 2013-05-31T20:27:46.010 回答
1

为什么要在 setUp 方法中定义第二个 WebDriver ?删除第二个定义以设置类成员驱动程序。

于 2013-06-07T12:43:02.110 回答
0
  DesiredCapabilities cap = new DesiredCapabilities();
        //cap.setCapability("", "");
        //cap.setCapability("browsername", "");
        //cap.setCapability("os", "iOS 6.1");
        cap.setCapability("device", "iPhone Simulator");
        cap.setCapability("app", "safari");

应该

  DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("deviceName", "iPhone Simulator");
        cap.setCapability("browsername", "safari");
        cap.setCapability("platformVersion", "7.1");
        cap.setCapability("platformName", "iOS");

这个对我有用。希望它能解决您的问题。祝你好运。

于 2014-07-16T21:46:47.560 回答
0

假设您在 Mac 上使用 Java,这对我有用,包括启动 Appium 服务本身的代码,然后是连接到它的驱动程序:

package baseTest;

import com.groupon.tests.mainapp.pages.*;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

import java.io.File;
import java.io.IOException;
import java.net.URL;


public class AppiumSafariBaseUITest {

private WebDriver wd;

protected WebDriver getDriver(){
    return wd;
}

String nodePath = "/Applications/Appium.app/Contents/Resources/node/bin/node";
String appiumJSPath = "/usr/local/lib/node_modules/appium/build/lib/main.js";

AppiumDriverLocalService service;
String service_url;

private void startAppiumServer() throws IOException {
    service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
                    .usingPort(4890)
                    .usingDriverExecutable(new File(nodePath))
                    .withAppiumJS(new File(appiumJSPath))
    );
    service.start();
}

@BeforeClass(alwaysRun = true)
public void setUpAppiumDriver() throws IOException {

    startAppiumServer();

    service_url = service.getUrl().toString();

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("appium-version", "1.0");
    capabilities.setCapability("platformName", "iOS");
    capabilities.setCapability("platformVersion", "9.3");
    capabilities.setCapability("deviceName", "iPhone 5s");
    capabilities.setCapability("newCommandTimeout", 600);
    capabilities.setCapability("bundleId", "com.apple.mobilesafari");
    capabilities.setCapability("useLocationServices", false);

    wd = new IOSDriver(new URL(service_url), capabilities);
}

@BeforeMethod(alwaysRun = true)
public void beforeMethod(){
    if(!service.isRunning())
    {
        service.start();
    }
}

@AfterClass(alwaysRun = true)
public void killSimulatorAndAppium(){
    service.stop();
}
}
于 2016-06-21T18:23:16.140 回答