TestCafe - Narbeans Ide - ReferenceError: Selector is not defined
TestCafe - Narbeans Ide - ReferenceError: Selector is not defined
大家好:我是 TestCafe 的新手(昨天开始),我正面临页面对象的下一个问题:
这是项目结构:
.
├── main.js
├── nbproject
│ ├── private
│ │ ├── private.properties
│ │ └── private.xml
│ ├── project.properties
│ └── project.xml
├── node_modules
│ └── testcafe -> ../../../../../usr/local/lib/node_modules/testcafe
├── package.json
├── page-object
│ └── First_Page.js
└── test
└── First_Test.js
我的页面模型是下一个:
import { selector, t } from 'testcafe';
class FirstPage {
constructor () {
this.userName = Selector('#txtRutTrabajador');
this.passWord = Selector('#txtPwdTrabajador');
this.accessButton = Selector('#submit2');
}
async login () {
await t
.typeText(this.userName, 'MyLogin')
.typeText(this.passWord, 'Pa$$word')
.click(this.accessButton);
}
}
export default new FirstPage();
接下来是测试 class:
/* global fixture, Fist_Page */
import First_Page from '../page-object/First_Page';
const first_Page = new First_Page();
fixture('First')
.page('https://www.123.com');
test( 'User should log in to system', async() => {
await First_Page.login();
});
另一方面,我正在研究 NetBeans IDE,我不太了解这个 IDE,所以通过终端 (Mac) 我输入了项目的位置并执行下一条命令:
npx testcafe firefox test/
或
testcafe firefox test/ -e
结果如下:
ERROR Cannot prepare tests due to an error.
ReferenceError: Selector is not defined
at new FirstPage (/Users/nosequeweaponer.g/NetBeansProjects/automation_test_cafe/page-object/First_Page.js:14:9)
at Object.<anonymous> (/Users/nosequeweaponer.g/NetBeansProjects/automation_test_cafe/test/First_Test.js:11:20)
at Function._execAsModule (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:50:13)
at ESNextTestFileCompiler._runCompiledCode (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:150:42)
at ESNextTestFileCompiler.execute (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:174:21)
at ESNextTestFileCompiler.compile (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:180:21)
at Compiler._getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:86:31)
at Compiler._compileTestFiles (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:98:35)
at Compiler.getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:111:34)
at Bootstrapper._getTests (/usr/local/lib/node_modules/testcafe/src/runner/bootstrapper.ts:239:21)
你能帮我解决这个问题吗?
更新:在 Alex Skorkin 发表评论后,错误消息已修复,但我面临下一个问题:
ERROR Cannot prepare tests due to an error.
TypeError: _First_Page2.default is not a constructor
at Object.<anonymous> (/Users/rodrigo.g/NetBeansProjects/automation_test_cafe/test/First_Test.js:11:20)
at Function._execAsModule (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:50:13)
at ESNextTestFileCompiler._runCompiledCode (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:150:42)
at ESNextTestFileCompiler.execute (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:174:21)
at ESNextTestFileCompiler.compile (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:180:21)
at Compiler._getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:86:31)
at Compiler._compileTestFiles (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:98:35)
at Compiler.getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:111:34)
at Bootstrapper._getTests (/usr/local/lib/node_modules/testcafe/src/runner/bootstrapper.ts:239:21)
at Bootstrapper._bootstrapParallel (/usr/local/lib/node_modules/testcafe/src/runner/bootstrapper.ts:386:38)
请任何人帮助我。
您似乎没有在测试中使用为第一页创建的对象。试试下面的代码
test( 'User should log in to system', async t => {
await first_Page.login();
});
JavaScript 是区分大小写的语言。尝试导入 Selector,而不是 selector
。
import { Selector } from 'testcafe';
大家好:我是 TestCafe 的新手(昨天开始),我正面临页面对象的下一个问题:
这是项目结构:
.
├── main.js
├── nbproject
│ ├── private
│ │ ├── private.properties
│ │ └── private.xml
│ ├── project.properties
│ └── project.xml
├── node_modules
│ └── testcafe -> ../../../../../usr/local/lib/node_modules/testcafe
├── package.json
├── page-object
│ └── First_Page.js
└── test
└── First_Test.js
我的页面模型是下一个:
import { selector, t } from 'testcafe';
class FirstPage {
constructor () {
this.userName = Selector('#txtRutTrabajador');
this.passWord = Selector('#txtPwdTrabajador');
this.accessButton = Selector('#submit2');
}
async login () {
await t
.typeText(this.userName, 'MyLogin')
.typeText(this.passWord, 'Pa$$word')
.click(this.accessButton);
}
}
export default new FirstPage();
接下来是测试 class:
/* global fixture, Fist_Page */
import First_Page from '../page-object/First_Page';
const first_Page = new First_Page();
fixture('First')
.page('https://www.123.com');
test( 'User should log in to system', async() => {
await First_Page.login();
});
另一方面,我正在研究 NetBeans IDE,我不太了解这个 IDE,所以通过终端 (Mac) 我输入了项目的位置并执行下一条命令:
npx testcafe firefox test/
或
testcafe firefox test/ -e
结果如下:
ERROR Cannot prepare tests due to an error.
ReferenceError: Selector is not defined
at new FirstPage (/Users/nosequeweaponer.g/NetBeansProjects/automation_test_cafe/page-object/First_Page.js:14:9)
at Object.<anonymous> (/Users/nosequeweaponer.g/NetBeansProjects/automation_test_cafe/test/First_Test.js:11:20)
at Function._execAsModule (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:50:13)
at ESNextTestFileCompiler._runCompiledCode (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:150:42)
at ESNextTestFileCompiler.execute (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:174:21)
at ESNextTestFileCompiler.compile (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:180:21)
at Compiler._getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:86:31)
at Compiler._compileTestFiles (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:98:35)
at Compiler.getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:111:34)
at Bootstrapper._getTests (/usr/local/lib/node_modules/testcafe/src/runner/bootstrapper.ts:239:21)
你能帮我解决这个问题吗?
更新:在 Alex Skorkin 发表评论后,错误消息已修复,但我面临下一个问题:
ERROR Cannot prepare tests due to an error.
TypeError: _First_Page2.default is not a constructor
at Object.<anonymous> (/Users/rodrigo.g/NetBeansProjects/automation_test_cafe/test/First_Test.js:11:20)
at Function._execAsModule (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:50:13)
at ESNextTestFileCompiler._runCompiledCode (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:150:42)
at ESNextTestFileCompiler.execute (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:174:21)
at ESNextTestFileCompiler.compile (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:180:21)
at Compiler._getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:86:31)
at Compiler._compileTestFiles (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:98:35)
at Compiler.getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:111:34)
at Bootstrapper._getTests (/usr/local/lib/node_modules/testcafe/src/runner/bootstrapper.ts:239:21)
at Bootstrapper._bootstrapParallel (/usr/local/lib/node_modules/testcafe/src/runner/bootstrapper.ts:386:38)
请任何人帮助我。
您似乎没有在测试中使用为第一页创建的对象。试试下面的代码
test( 'User should log in to system', async t => {
await first_Page.login();
});
JavaScript 是区分大小写的语言。尝试导入 Selector,而不是 selector
。
import { Selector } from 'testcafe';