TestCafe - Narbeans Ide - ReferenceError: Селектор не определен - PullRequest
0 голосов
/ 26 марта 2020

Привет, люди: я новичок в TestCafe (начат вчера) и сталкиваюсь со следующей проблемой с объектом Page:

Это структура проекта:

.
├── 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

My Модель страницы следующая:

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();

Класс теста следующий:

/* 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();    
});

С другой стороны, я работаю над IDE NetBeans и не очень хорошо понимаю эту IDE Таким образом, через Терминал (Ma c) я помещаю местоположение проекта и выполняю следующую команду:

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)

Не могли бы вы помочь мне с этим?

ОБНОВЛЕНО: После комментария Алекса Скоркина сообщение об ошибке было исправлено, но я столкнулся со следующей проблемой:

    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)

Пожалуйста, кто-нибудь, помогите мне.

Ответы [ 2 ]

2 голосов
/ 26 марта 2020

JavaScript является регистрозависимым языком. Попробуйте импортировать Selector, а не selector.

import { Selector } from 'testcafe';
1 голос
/ 26 марта 2020

Кажется, вы не используете объект, созданный для первой страницы в тесте. Попробуйте следующий код

test( 'User should log in to system', async t => {

       await first_Page.login();    
});
...