这似乎是一个不是很常见的任务,但非常有趣的一个。我不认为有一些标准的方法,所以必须实施。
我不知道的Perl多,我使用Java,所以这只是抬起头:
我将扩展DefaultSelenium
类我的测试中,将使用扩展HttpCommandProcessor
,将记录所有的命令进行:
import com.thoughtworks.selenium.HttpCommandProcessor;
public class ExtHttpCommandProcessor extends HttpCommandProcessor {
public ExtHttpCommandProcessor(String serverHost, int serverPort,
String browserStartCommand, String browserURL) {
super(serverHost, serverPort, browserStartCommand, browserURL);
}
public String doCommand(String commandName, String[] args) {
StringBuffer sb = new StringBuffer();
sb.append("|" + commandName + "|");
if (args!=null) {
for (String arg : args) {
sb.append(arg + "|");
}
if (args.length<2) {
sb.append(" |");
}
} else {
sb.append(" | |");
}
System.out.println(sb.toString());
// or log it where you want
return super.doCommand(commandName, args);
}
}
而且
import com.thoughtworks.selenium.DefaultSelenium;
public class ExtSelenium extends DefaultSelenium {
public ExtSelenium(String serverHost, int serverPort,
String browserStartCommand, String browserURL) {
super(new ExtHttpCommandProcessor(serverHost, serverPort, browserStartCommand, browserURL));
}
}
然后我会使用扩展SeleneseTestCase
在我的测试基地:
import com.thoughtworks.selenium.SeleneseTestCase;
public class ExSeleneseTestCase extends SeleneseTestCase {
public void setUp(String url, String browserString) throws Exception {
int port = 4444;
if (url==null) {
url = "http://localhost:" + port;
}
selenium = new ExtSelenium("localhost", port, browserString, url);
selenium.start();
selenium.setContext(this.getClass().getSimpleName() + "." + getName());
}
}
这种测试的输出如下:
| getNewBrowserSession | * IEXPLORE | http://localhost:8080/|
| setContext | SimpleTest.testNew | |
| open | /webapp/test.html | |
| isTextPresent |示例文本| |
| click | sampleLink | |
| waitForPageToLoad | 10000 | |
| testComplete | | |
该解决方案将无法登录verify
S和assert
是如此,他们也可以在ExSeleneseTestCase被overrided产生一些痕迹。