- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建用于电子邮件验证的脚本。我的意思是当我们在网站上创建一个帐户时,验证邮件将发送到给定的邮件地址,然后我们必须转到该邮件并验证它(单击链接/或获取代码)。我试过 this solution .但我一直卡在特定错误上。
这是我正在尝试的代码。
describe("Sample test case", function () {
function getLastEmail() {
let deferred = protractor.promise.defer();
console.log("Waiting for an email...");
mailListener.on("mail", function(mail){
deferred.fulfill(mail);
});
return deferred.promise;
}
beforeAll(function () {
browser.waitForAngularEnabled(false);
browser.get("https://mail.google.com/mail/");
isAngularSite(false);
browser.sleep(3000);
});
it("should login with a registration code sent to an email", function () {
element(by.id("username")).sendKeys("MyemailID");
element(by.id("password")).sendKeys("mypassword");
element(by.id("loginButton")).click();
browser.controlFlow().await(getLastEmail()).then(function (email) {
expect(email.subject).toEqual("BillPledge Email Verification");
expect(email.headers.to).toEqual("support@billpledge.com");
// extract registration code from the email message
let pattern = /Registration code is: (\w+)/g;
let regCode = pattern.exec(email.text)[1];
console.log(regCode);
});
});
});
这是我的配置文件。
// An example configuration file.
exports.config = {
// The address of a running selenium server.
// seleniumAddress: 'http://localhost:4444/wd/hub',
// if we are using protractor's webdriver-manager locally, you cannot use selenium Address
// If the webdriver-manager needs to start a local server, you can use
selenium: 'http://localhost:4445/wd/hub',
seleniumPort: 4445, // Port matches the port above
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['./e2eTest/GmailTest.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 300000
},
allScriptsTimeout: 200000,
onPrepare: function () {
global.isAngularSite = function (flag) {
browser.ignoreSynchronization = !flag;
};
browser.driver.manage().window().maximize();
//To generate the report.
let HtmlReporter = require('protractor-beautiful-reporter');
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'Results/Report'
}).getJasmine2Reporter());
let reporter = new HtmlReporter({
baseDirectory: 'Results/Report'
});
let path = require('path');
new HtmlReporter({
baseDirectory: 'Results/Report'
, preserveDirectory: false
, cssOverrideFile: 'css/style.css'
, takeScreenShotsForSkippedSpecs: true
, screenshotsSubfolder: 'images'
, jsonsSubfolder: 'jsons'
, takeScreenShotsOnlyForFailedSpecs: false
, gatherBrowserLogs: true
, pathBuilder: function pathBuilder(spec, descriptions, results, capabilities) {
// Return '<browser>/<specname>' as path for screenshots:
// Example: 'firefox/list-should work'.
return path.join(capabilities.caps_.browser, descriptions.join('-'));
}
, metaDataBuilder: function metaDataBuilder(spec, descriptions, results, capabilities) {
// Return the description of the spec and if it has passed or not:
return {
description: descriptions.join(' ')
, passed: results.passed()
};
}
});
let MailListener = require("mail-listener2");
// here goes your email connection configuration
let mailListener = new MailListener({
username: "myemailid",
password: "mypassword",
host: "imap.gmail.com",
port: 993, // imap port
tls: true,
tlsOptions: {rejectUnauthorized: false},
mailbox: "INBOX", // mailbox to monitor
searchFilter: ["UNSEEN", "FLAGGED"], // the search filter being used after an IDLE notification has been retrieved
markSeen: true, // all fetched email willbe marked as seen and not fetched next time
fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
attachments: true, // download attachments as they are encountered to the project directory
attachmentOptions: {directory: "attachments/"} // specify a download directory for attachments
});
mailListener.start();
mailListener.on("server:connected", function () {
console.log("Mail listener initialized");
});
global.mailListener = mailListener;
},
onCleanUp: function () {
mailListener.stop();
},
};
但是在执行脚本时出现以下错误。错误是:
Error: Please log in via your web browser:
https://support.google.com/mail/accounts/answer/78754 (Failure)
和
Failed: browser.controlFlow(...).await is not a function
我知道我做错了,但我无法弄清楚。因此,任何人都可以帮助我指出并解决它,而不是解决问题,但至少可以提供一些有助于完美运行此脚本的建议。
谢谢
最佳答案
尝试使用 browser.wait(getLastEmail)
而不是 browser.controlFlow().await(getLastEmail()
关于javascript - Protractor 端到端测试;验证帐户激活电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48499322/
我有一个表,其中包含3行数据和3个删除按钮。我想删除所有数据行,因此想在我的页面对象中编写一个方法来做到这一点……这应该很简单,但我无法使其正常工作。我正在这样尝试: this.rows = elem
我们有一个应用程序,在本地进行测试会显示无效的SSL证书警告。通常,我只添加一个异常并继续处理。但是, Protractor 有无视这一点吗? 我已经看到了 Selenium 中的一些功能,其中可以忽
我有一个关于我的代码和不同行为的问题,具体取决于使用的 Protractor 版本。 我的测试使用 Protractor 版本 2.5.1。但要从最新发展中获得所有好处,我 试图移动到版本 3.x。
我有一个项目已经运行了很长时间。 最近(几周)系统测试失败了。 经过大量调查,我们得出结论, Protractor 无法识别和关闭警报。 曾经工作的代码 exports.removeFaq = fun
我能够成功运行 Protractor 脚本。下面是我用来运行 Protractor 脚本的 protractor.config.js 文件。 var Jasmine2Reporter = requir
在 Protractor 中,如何处理重复的内容,比如一张表格?例如,给定以下代码,它会踢出一个包含 3 列的表:Index , Name和 Delete-Button在每一行中: {{$in
我为 Protractor 编写了一个自定义定位器,可以找到 anchor元素由他们 ui-sref值(value)。在我的规范中,我刚刚使用了 by.addLocator添加自定义定位器,但我认为发
我遇到过 Protractor 的页面对象的不同类型的语法,我想知道它们的背景是什么以及建议采用哪种方式。 这是 Protractor 教程中的官方 PageObject 语法。我最喜欢它,因为它清晰
Protractor 中有两个 it() 测试用例 it('it1',function(){ }); it('it2',function(){ }); 完成 it1 后, Protractor 中的驱
我目前正在运行一套 Protractor 测试。我有一个 config.js 仅设置为运行具有“功能”的 Chrome。见下文。 capabilities: { } browserNa
我试图断言名称显示在表的列中。我写了一个 inResults将遍历列的文本以查看名称是否存在的函数。这是我正在尝试的: 页面对象: this.names = element.all(by.repeat
我可以使用检索浏览器日志 browser.manage().logs().get('browser').then(function(browserLog) { logger.info('log:
我按照文档中有关如何安装 Protractor 和 Selenium 的说明进行操作,但无法启动。 install -g protractor webdriver-manager update 之后我
我在 Protractor 中使用 --suites config 运行多个案例。我必须为每种情况重新启动我的 web 应用程序,但我的应用程序有一个警报,每当页面重新加载或关闭时,都会弹出该警报以进
我想知道如何在测试套件中按顺序运行测试用例。 例如,加载 URL、登录系统等。 最佳答案 检查 protractor.conf.js example . 您可以指定一个按字母顺序加载文件的 glob,
row1Col1 row1Col2 row1Co
如何从包含特定文本的转发器中搜索元素? 我试过这样的事情: element(by.repeater('item in array')).all(by.cssContainingText('.xyz',
只是想知道是否可以将 cli args 指定为 Protractor --multiCapabilities.0.browserName chrome --multiCapabilities.1.br
是否可以在 Protractor 中的任何套件运行之前运行一些测试或逻辑流程? 例如,我想将我的 Protractor 测试分解成一系列套件来测试我的应用程序的不同方面。假设 Jenkins 将在部署
我是 Protractor 的新手,我正在尝试使用 Protractor 设置单选按钮值。我在互联网和 SO 上搜索了徒劳的答案。 html: No Yes
我是一名优秀的程序员,十分优秀!