在我正在开发的验收测试套件中(在堆栈顶部具有 mocha、sinon 和 chai),我能够在 phantomjs 中加载页面并根据网络上可用的示例执行各种操作。
唯一让我难以理解的是检索页面启动期间产生的 JS 变量。我在这里附上了一个完整的示例,它显示了如何app
无法测试变量,而jQuery
可以。
两者之间的唯一区别app
是由运行产生的$(document).ready(function() {... create var app ...})
我得到的错误是maximum call stack exceeded
(?!?!?!?)
如果可用,我该怎么做才能执行应用程序检查?也许使用承诺的东西?我看不清楚这一切(**)。
这是错误堆栈:
19:29:02.918 INFO [14] org.openqa.selenium.remote.server.DriverServlet - Executing: [execute script: return app, []] at URL: /session/73437950-3c14-4392-81ed-c6bd83c3f3fb/execute)
19:29:06.481 WARN [14] org.openqa.selenium.remote.server.DriverServlet - Exception thrown
org.openqa.selenium.WebDriverException: {"errorMessage":"Maximum call stack size exceeded.","request":{"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"33","Content-Type":"application/json; charset=utf-8","Host":"localhost:1693"},"httpVersion":"1.1","method":"POST","post":"{\"args\":[],\"script\":\"return app\"}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","queryKey":{},"chunks":["execute"]},"urlOriginal":"/session/9ca480b0-3c34-11e4-b1c7-0d43d6ab90ff/execute"}}
Command duration or timeout: 3.56 seconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'vagrant-xxx-yyyy', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-60-generic', java.version: '1.7.0_65'
Session ID: 9ca480b0-3c34-11e4-b1c7-0d43d6ab90ff
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{platform=LINUX, acceptSslCerts=false, javascriptEnabled=true, browserName=phantomjs, rotatable=false, driverVersion=1.1.0, locationContextEnabled=false, version=1.9.7, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=false, browserConnectionEnabled=false, webStorageEnabled=false, nativeEvents=true, proxy={proxyType=direct}, applicationCacheEnabled=false, driverName=ghostdriver, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
这里是测试:getTitle
, getTagName
, getElementSize
and execute('return jQuery')
succeed; execute('return app')
失败。
describe('AAA Test acceptance XXXXX', function(){
var client = {}
before(function(done) {
client = webdriverjs.remote({
desiredCapabilities: {
browserName: 'phantomjs'
},
});
client.init(done) // starts session and opens the browser
});
it('The merchant button',function(done){
client.url('http://www.dev.xxxx.com/api/purchase/index.html')
.getTitle(function(err,title){
expect(err).to.be.null
expect(title).to.have.string('Mobile Payment');
})
.getTagName('.merchant-div',function(err,tagName){
expect(err).to.be.null
expect(tagName).to.be.equal('div')
})
.getElementSize('#ms-input',function(err,size){
expect(err).to.be.null
expect(size.width).to.be.equal(184)
})
.execute('return jQuery', function(err,jquery) {
expect(err).to.be.null
expect(jquery).not.to.be.undefined
expect(jquery).not.to.be.null
})
.execute('return app', function(err,appInstance) {
expect(err).to.be.null
expect(appInstance).not.to.be.undefined
expect(appInstance).not.to.be.null
})
.call(done);
})
after(function(done) {
client.end(done); // ends session and closes the browser
})
});
(**)我已经按照Selenium WebDriver JS - Explicit Wait中的说明进行操作,但错误是Object #<WebdriverIO> has no method 'wait'
(这很有意义......)