我无法在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 Project
3)右键单击测试代码,然后单击RunAs Junit
4)推出iPhone模拟器 - iPhone iOS 6.1
5)移动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();
}
}
答案 0 :(得分: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);
});
});
答案 1 :(得分:1)
为什么在setUp方法中定义第二个WebDriver?删除第二个定义以设置类成员驱动程序。
答案 2 :(得分: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");
它对我有用。希望它能解决你的问题。祝你好运。
答案 3 :(得分:0)
假设你在Mac上使用Java,这里有一些对我有用的东西,包括启动Appium Service本身的代码,然后是连接它的驱动程序:
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();
}
}