gpt4 book ai didi

javascript - casperjs测试注册表

转载 作者:行者123 更新时间:2023-11-28 21:30:47 25 4
gpt4 key购买 nike

我的页面内有一个表单供想要在网站内注册的用户使用。注册后,我在数据库中插入用户,创建一个激活 key 并发送一封电子邮件,直到用户不使用激活 key 单击电子邮件中的链接,他就无法在网站内登录。

我想使用 CasperJS 测试此功能,fillForm 没问题,但我如何测试激活 key ?

我曾想过创建一个使用激活 key 隐藏的输入(仅当处于测试模式而不是生产模式时!)并使用 getFieldValue 函数检索此值。

这是正确的方法还是有更好的模式?

这是我在注册后检索激活 key 的 casperjs 测试(我创建了一个隐藏激活码的输入):

view            = 'users/registered';

casper
.start(webroot + view)
.then(function() {
__utils__.log("Retrieving data from input activation-key");
activationKey = __utils__.getFieldValue('activation-key');
}).then(function() {
__utils__.log("Activating account with the key " + activationKey);

}).then(function(){
this.evaluate(function() {
__utils__.log("Activating account with the key " + activationKey);
window.location = webroot + 'users/activate/' + activationKey;
});
}).then(function(){
this.echo(this.getCurrentUrl());
});

casper.run(function() {
this.echo('test registeration successful!').exit();
});

casper.viewport(page.width, page.height);

casper.test.done();

最佳答案

我设法通过注册完成了我想做的事情,它可以帮助你:CasperJS- Register on a site and validate the mail sent on Gmail -for both slimer and phantom-

在我也用激活码抓取之前,手动激活(纯 JS,这里没有 jQuery,我不想在 gmail DOM 环境中注入(inject) JQuery):

this.waitForSelector("div.msg",function(){
this.test.assertSelectorHasText("a","Activation message");
//var code declared in the main scope
code = this.evaluate(function(){
var strongs = document.getElementsByTagName('strong')
,i
,l = strongs.length
;
for (i = 0; i < l; ++i) {
if(strongs[i].textContent === "activation code:"){
//get back the code in DOM context -> split to get back only what I want
return (strongs[i].parentNode.textContent.split(' ')[2]);
}
}
});
this.echo("code : " + code,"INFO");
});

关于javascript - casperjs测试注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23195294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com