我正在尝试运行以打字稿编写的量角器测试脚本。但是当我这样做时,我得到的是“ ManagedPromise ”。它不显示任何错误,只是返回“ ManagedPromise”
我的打字稿测试:
//import {describe, it} from "selenium-webdriver/testing";
import {browser, by, element} from "protractor";
describe("For testing purpose", () => {
it('should pass', () => {
browser.get("https://angularjs.org");
element(by.model('todoList.todoText')).sendKeys('write first
protractor test');
element(by.css('[value="add"]')).click();
let title = browser.getTitle();
console.log(title);
});
});
我的conf.js文件:
import {browser} from "protractor";
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine2',
specs: ['./JSfiles/appExample.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 9000
/* getPageTimeout: 3000,
allScriptsTimeout: 2000*/
},
onPreapre: () => {
browser.driver.manage().window().maximize();
}
};
我的package.json文件:
{
"name": "typescript-dev-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"@types/jasminewd2": "^2.0.3",
"jasmine": "^3.1.0",
"jasminewd2": "^2.2.0",
"protractor": "^5.3.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
我的tsconfig.json文件:
"compilerOptions": {
/* Basic Options */
"target": "es5",
"module": "commonjs",
"esModuleInterop": true,
"strict": true,
"outDir": "./JSfiles",
尝试运行测试时得到的响应:
Started
ManagedPromise {
flow_:
ControlFlow {
propagateUnhandledRejections_: true,
activeQueue_:
TaskQueue {
name_: 'TaskQueue::101',
flow_: [Circular],
tasks_: [Array],
interrupts_: null,
pending_: null,
subQ_: null,
state_: 'new',
unhandledRejections_: Set {} },
taskQueues_: Set { [TaskQueue] },
shutdownTask_: null,
hold_:
Timeout {
_called: false,
_idleTimeout: 2147483647,
_idlePrev: [TimersList],
_idleNext: [TimersList],
_idleStart: 1694,
_onTimeout: [Function],
_timerArgs: undefined,
_repeat: 2147483647,
_destroyed: false,
[Symbol(unrefed)]: false,
[Symbol(asyncId)]: 109,
[Symbol(triggerId)]: 104 } },
stack_: null,
parent_:
ManagedPromise {
flow_:
ControlFlow {
propagateUnhandledRejections_: true,
activeQueue_: [TaskQueue],
taskQueues_: [Set],
shutdownTask_: null,
hold_: [Timeout] },
stack_: null,
parent_:
ManagedPromise {
flow_: [ControlFlow],
stack_: null,
parent_: [ManagedPromise],
callbacks_: [Array],
state_: 'pending',
handled_: true,
value_: undefined,
queue_: null },
callbacks_: [ [Task] ],
state_: 'pending',
handled_: true,
value_: undefined,
queue_: null },
callbacks_: null,
state_: 'pending',
handled_: false,
value_: undefined,
queue_: null }
答案 0 :(得分:0)
Gunderson 在评论中说:You are console.logging a promise. You need to resolve it
发生在以下代码段:
let title = browser.getTitle();
console.log(title);
为了解决这个问题,您可以
browser.getTitle().then(function(text) {
console.log(text);
});
Protractor console log有更深入的解释。
如何通过异步执行:
it('should pass', async() => {
//other codez here
let title = await browser.getTitle();
console.log(title);
}