我想使用CasperJS(1.1.0-beta5,使用PhantomJS 2.1.5)对我的网站进行端到端测试。我编写了有效的基本测试:我在“index.html”中明确写出的所有东西都是由Casper(标题,容器div等)找到的。
找不到我之后呈现的任何内容(即使使用waitForSelector
或wait
)。我正在使用React。
如果我转到我给Casper(localhost)的网址,我会看到必须存在的所有内容,并使用开发工具检查页面显示我的div存在。 Casper只是忽略了我的Javascript。
我怎样才能调试以找出问题所在?
以下是基本的HTML布局:
<body>
<div id="app-container"></div>
<div id="footer"></div>
<script src="scripts/app.js"></script>
</body>
App.js在“#app-container”中插入div“#app”。
如果我打印出Casper用this.getPageContent()
看到的DOM,我只看到上面的内容,而不是“#app”。如果我capture
截图,我会看到页脚,但页面的其余部分是空白的:
以下是我测试的代码:
casper.test.begin('Webapp basic layout', 6, function suite(test) {
casper.start(url, function () {
test.assertHttpStatus(200);
test.assertTitle('Varapp browser', '<title> found');
test.assertExists('#app-container', 'Main app container exists');
casper.waitForSelector("#app", function() {
test.assertExists('#app', 'Sub app div exists');
})
});
casper.run(function () {
test.done();
});
});
这是输出:
# Webapp basic layout
PASS Webapp basic layout (6 tests)
PASS HTTP status code is: 200
PASS <title> found
PASS Main app container exists
FAIL "#app" still did not exist in 5000ms
# type: uncaughtError
# file: ...
# error: "#app" still did not exist in 5000ms
# stack: not provided
我做错了什么?