- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对casperJS比较陌生。我有一个脚本,我想在页面B中执行操作(即验证用户的确认邮件),然后在页面A中继续执行。代码片段如下
casper.waitFor(function(){
return this.run(function(){
return verifyEmail(user_details['email']);
});
},function then(){
this.wait(60000, function() {
this.reload(function(){
this.echo("Refresh");
this.capture('after-reload-a.png');
});
});
});
函数verifyEmail定义如下:
function verifyEmail(email){
return casper.open('someURL').then(function(response){
//extract URL from response
this.echo("URL"+url);
casper.start().thenOpen(url, function() {
this.waitForText('someText',function(){
this.capture("final.jpg");
});
});
return url;
});
};
在执行过程中,Casper 从不执行函数 verifyEmail(从不打印 URL)并继续执行 then() 函数。我在这里缺少什么?
最佳答案
对于脚本中的每个 casper
实例,您应该只使用一次 start
和 run
函数。由于 CasperJS 的执行是异步的,因此您不能返回任何东西。你必须等待它。
您可以使用第二个 casper
实例来设置全局变量,并在前一个实例中使用 waitFor
来等待它发生变化,如 here 所示。 .
根据您从响应中提取 URL 的方式,使用 __utils__.sendAJAX(someURL)
可能更容易在页面上下文中(通过 casper.evaluate
)。请注意,这不应在 casper.waitFor
中完成,因为它具有默认的同步模式,无需等待。此外,waitFor
的第一个回调函数经常被调用以检查值是否更改,因此不应该那样使用。
第三种可能性是仅使用一个实例进行简单导航。似乎您在解析其他页面后重新加载了原始页面。为什么您通常不使用 thenOpen
访问 'someURL'
,进行解析然后使用 thenOpen
打开原始 URL 而无需任何等待?你甚至可以get the current URL并将其保存为(半)全局变量,以确保您返回到正确的页面。
关于javascript - CasperJS WaitFor 不等待条件完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28060096/
运行测试时获取。 FAIL 35 tests executed in 16.806s, 35 passed, 0 failed, 2 dubious, 0 skipped. “可疑”意味着什么?如何查
是否有人已经使用 casperjs 实现了著名的“页面对象模式”,从长远来看,它对于测试的可维护性非常有用? 当您必须将测试的机制和目的分开时,使用它非常非常酷。以这种方式编写测试会变得更加愉快。 有
所以,我试图在我的服务器上运行 casperJS 作为 cron 作业,这是 crontab: * * * * * /usr/local/bin/casperjs /var/www/javascrip
我知道如何禁用图像和插件,但似乎没有明显的选项来禁用 CasperJS 中的 css。 有谁知道这是如何工作的? 最佳答案 假设您想抑制所有外部样式表的加载,您可以通过中止加载 css 文件的请求来实
我在删除网站时从创建的 URL 下载文件时遇到问题。目前我发现了一个文件的月份和年份,然后替换了 url 中的值并尝试从该位置下载。我了解到您无法使用评估范围内的下载功能。 this.evaluate
在 CasperJS 中,如何在使用 casper.thenOpen() 时保持 session 例如: var casper = require('casper').create(); casper
我希望我的 casper 在 session 期间登录并保持登录状态。有可能吗?如果是这样,如何? 最佳答案 如果你想在 CasperJS 中存储 cookie,你可以使用 PhantomJS coo
我用 casperjs 编写了一些测试。他们与 phantomjs 一起运行得很好。但是,当我尝试通过以下命令使用 slimerjs 时: casperjs --verbose --engine=sl
我用 casperjs 编写了一些测试。他们与 phantomjs 一起运行得很好。但是,当我尝试通过以下命令使用 slimerjs 时: casperjs --verbose --engine=sl
我想单击“提交”按钮,等待下一页加载,然后在第二页上获取html。。我先做然后再运行,但然后一步仍在首页上运行。有任何想法吗? var casper = require('casper').creat
在我的页面自动化脚本中,当我单击标签链接时,将打开一个新窗口。链接的 url 是由复杂的 javascript 生成的。 办理任务 触发后 url 变为: https://oa.phicomm.co
CasperJS(带有 phantomJS)可以直接在浏览器中运行而不是通过命令行运行吗? 我想从浏览器运行交互式测试,我从用户那里获取输入并相应地进行。我想将 casperJS 作为在浏览器中执行的
我正在尝试使用 CasperJS 将图像上传到网络表单。 我的表格看起来像这样: ... Campaign Banner
错误: casper.test property is only available using the `casperjs test` command 在我的整个代码库中搜索了“casper.tes
假设我有一组网址。我不想使用 thenOpen 函数。因为它等待每个以前的 url 被加载并且它减少了加载时间。 casper.each(hrefs,function(self,href){
我正在尝试导航到从脚本本身创建的 url。 此示例代码不像(我曾)预期的那样工作。不知道为什么:( var casper = require('casper').create({ viewpo
我有一个链接列表,我必须模拟这些链接才能使用CasperJS进行点击。他们都共享同一个类(class)。 但是,使用this.click('.click-me')仅单击第一个链接。 单击所有链接的正确
casper.then(function(){ phone_number = '7wqeqwe6'; phone_password = 'Teqweqweqw34'; }); casper.t
我如何告诉 casper 不要加载图像、css、js 视频等。所以我只对 DOM 元素感兴趣。 最佳答案 看看 CasperJS API . var casper = require('casper'
在Phantom中生成PDF时,我可以这样设置纸张大小: page.paperSize = { height: '8.5in', width: '11in', orientation: '
我是一名优秀的程序员,十分优秀!