【发布时间】:2018-10-10 22:27:38
【问题描述】:
我正在尝试将现有的、正在运行的 JavaScript 项目转换为 TypeScript,并且我特别想使用 PageObject 模式。
运行 npm test 时出现此错误:TypeError: client.page.signinPage is not a function。
这就是我所说的:
import * as dotenv from "dotenv";
dotenv.config();
module.exports = {
'User can sign in'(client: any) {
const signinPage = client.page.signinPage();
我的功能在这里:
const signinCommands = {
signin(email: String, password: String) {
return this
.waitForElementVisible('@emailInput')
.setValue('@emailInput', email)
.setValue('@passwordInput', password)
.waitForElementVisible('@signinButton')
.click('@signinButton')
}
};
module.exports = {
url: 'https://cjdocs.herokuapp.com/auth/signin',
commands: [signinCommands],
elements: {
emailInput: {
selector: 'input[type=email]'
},
passwordInput: {
selector: 'input[name=password]'
},
signinButton: {
selector: 'button[type=submit]'
}
}
};
我的 page_object_path 是在 nightwatch.json 文件中设置的。
那么,它怎么不认为我的函数是函数呢?
整个项目可以从:https://github.com/hellfireSteve/nightwatch-typescript-pageobject下载
【问题讨论】:
-
signinPage是您使用new关键字实例化的类。然后你有一个所述类的对象,你可以在其上调用函数。请查看打字稿教程,因为这是非常基本的东西...... -
顺便说一句...类应该以大写字母开头。
-
@Wernerson 我现在正在上 TypeScript 课程。
-
不要运行测试,因为您使用的是 TypeScript,请查看 TypeScript 给您的错误。
-
正如我在the previous question 上所说的,我认为问题在于您没有正确遵循documentation 中的“使用页面对象”说明。你的项目的文件结构是什么?您是否设置了
page_objects_path选项?我们可以尝试帮助您进行故障排除,但我们可能无法解决问题,除非您努力拼凑一个不依赖于您公司网络的可重现示例。
标签: typescript