Я получаю TypeError в консоли при попытке использовать javascript ECMAScript 6 в транспортире. Я хочу иметь базовый класс со всеми действиями, которые выполняет транспортир, и импортировать его в объекты другой страницы. Также регистрируйте все действия, которые транспортир выполняет на базовой странице.
пакет. json
{
"name": "Protractor-end-to-end-test-framework",
"private": true,
"dependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-transform-arrow-functions": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@babel/register": "^7.9.0",
"dotenv": "^8.2.0",
"jasmine-allure-reporter": "^1.0.2",
"log4js": "^6.2.1",
"moment": "^2.24.0",
"protractor": "^5.4.2"
},
"scripts": {
"test": "webdriver-manager start --standalone && protractor config.js"
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-plugin-protractor": "^2.1.1"
}
}
config. js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['./tests/test.js'],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--window-size=1920,1024" ]
}
},
//Global configuration
baseUrl: 'https://facebook.com',
//Allure configuration
onPrepare: () => {
require("@babel/register");
var AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter());
jasmine.getEnv().afterEach( done => {
if(done.status === "failed") {
browser.takeScreenshot().then(png => {
allure.createAttachment('Screenshot', () => {
return new Buffer(png, 'base64')
}, 'image/png')();
done();
})
}});
}
}
test. js
'use strict'
import { get } from '../page_objects/base_page';
import { fillLoginAndPasswordIntoWindow } from '../page_objects/pre_login_page';
import { getUserName, getPassword } from '../utils/constants';
describe('Collection data', () => {
beforeAll(() => {
browser.waitForAngularEnabled(false);
get(browser.baseUrl);
});
it('Demo tests', () => {
fillLoginAndPasswordIntoWindow(getUserName, getPassword);
});
});
base. js
import { browser } from 'protractor';
const log = require('../logger.config');
const constants = require('../utils/constants');
const EC = protractor.ExpectedConditions;
const GLOBAL_TIMEOUT = constants.getTimeout;
export default class Base {
constructor() {
}
get = url => {
browser.get(url);
log.info(`Navigate to the ${url}`);
}
click = element => {
element.click();
log.info(`Click on the ${element}`);
}
enterText = (element, text) => {
element.sendKeys(text);
log.info(`Enter text ${text} to the ${element}`);
}
getText = element => {
log.info(`Get text from the element ${element}`);
return element.getText();
}
getAttribute = (element, attribute) => {
log.info(`Get attribute ${attribute} from element ${element}`);
return element.getAttribute(attribute);
}
sDisplayed = element => {
log.info("Is element displayed on the page");
return element.isDisplayed();
}
//Wait section
waitToBePresent = element => {
log.info("Wait to element present");
browser.wait(EC.presenceOf(element), GLOBAL_TIMEOUT);
}
waitToBeInvisible = element => {
log.info("Wait to element invisible");
browser.wait(EC.invisibilityOf(element), GLOBAL_TIMEOUT);
}
waitToBeVisible = element => {
browser.wait( () => {
browser.sleep(2000);
return element.isDisplayed()
.then( isDisplayed => {
return isDisplayed;
}, error => {
return false;
});
}, GLOBAL_TIMEOUT);
}
wait = timeout => {
log.info(`Wait ${timeout} seconds`);
browser.sleep(timeout * 1000);
}
//Alert section
waitToAlertPresent = () => {
try {
browser.wait(EC.alertIsPresent(), GLOBAL_TIMEOUT);
log.info(`Wait to alert present`);
} catch (error) {
log.info(`No allert present in the page`);
}
}
enterTextAlert = text => {
waitToAlertPresent();
browser.switchTo().alert().sendKeys(text);
log.info(`Enter text ${text} to the alert window`);
}
acceptAlert = () => {
waitToAlertPresent();
browser.switchTo().alert().accept();
log.info(`Accept alert`);
}
}
Я ожидал, что транспортир должен работать с javascript с ECMAScript 6. Но теперь в журнале консоли произошла ошибка. Стек:
Message:
Failed: (0 , _base_page.get) is not a function
Stack:
TypeError: (0 , _base_page.get) is not a function
at UserContext.<anonymous> (/Users/tomashgombosh/Documents/protractor-framework/tests/test.js:10:9)
at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:112:25
at new ManagedPromise (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1077:7)
at ControlFlow.promise (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2505:12)
at schedulerExecute (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:95:18)
at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3084:14)
at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3067:27)
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2974:25
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:668:7
at processTicksAndRejections (internal/process/task_queues.js:93:5)