如何使用selenium 在iphone (iOS)上进行测试

131 views
Skip to first unread message

jest...@welocalize.com

unread,
Jul 20, 2011, 3:09:30 AM7/20/11
to WATF Forum
现在移动终端发展迅速,移动终端的网页测试也必须要跟上。 现在主流两大移动系统Android/iOs. 现在谈谈iOS的移动网页终端测试流程。

现在selenium与webDriver两个项目合并后,使浏览器的测试框架更强壮,功能更多,两者互补,为Web自动化测试带来了很大的方便。 在
ios上的测试就是通过webDriver实现的。

基本的工作原理呢就是在移动端装一个WebDriver的代理程序,使客户端可以通过http服务来进行通讯和测试。

基本步骤:

1. 拥有Mac操作系统(虚拟/真实机都行).
2. 配置好Xcode开发环境。并且一定要包含iOS SDK,如果你没有真实的iphone 机的话。
3. 中间步骤可以参考http://code.google.com/p/selenium/wiki/IPhoneDriver
4. 按照官方wiki的的步骤执行,会出现许多文件找不到的错误。(我使用的是simulator). debug后发现是因为缺失
errorcodes.h.
可以从selenium/cpp/webdriver-interactions/里把errorcodes.h和errorcodes.html都拷
贝到selenium/iphone/src/objc.然后正常运行,就应该没有问题了。

测试用的case:

iphone的和脚本是可以在不同的机子上的,所以不用在mac上配置运行环境。

import junit.framework.TestCase;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.iphone.IPhoneDriver;

public class Sample extends TestCase {
public void testGoogle() throws Exception {
IPhoneDriver driver = new
IPhoneDriver("http://10.10.216.180:3001/hub"); // And now use
this to visit Google
driver.get("http://www.google.com.hk"); // Find the text
input element by its name
WebElement element = driver.findElement(By.name("q")); //
Enter something to search for
element.sendKeys("Cheese!"); // Now submit the form.
WebDriver will find the form for us from the element
element.submit(); // Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}

其中的地址:http://10.10.216.180:3001/hub换成你的iphone或者iphone simulator的实际局域网地址
就行了。

只是做了个基本的连接测试。欢迎继续讨论。。。

Reply all
Reply to author
Forward
0 new messages