今天,我开始通过Selenium WebDriver进行测试,但是遇到了这个问题(错误):
ReferenceError: after is not defined
我设法从after
和Jasmine
库中发现Mocha
是全局变量。但是我还是不能做任何事情。
我的单元测试是使用Jest
进行的,我不想将其更改为Mocha
。
测试(基本)看起来像这样(google_search_test.js):
const {Browser, By, Key, until} = require('selenium-webdriver');
const {ignore, suite} = require('selenium-webdriver/testing');
suite(function(env) {
describe('Google Search', function() {
let driver;
beforeEach(async function() {
driver = await env.builder()
.forBrowser('chrome')
.build();
});
it('demo', async function() {
await driver.get('https://www.google.com/ncr');
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
});
ignore(env.browsers(Browser.CHROME)).it('demo 2', async function() {
await driver.get('https://www.google.com/ncr');
await driver.wait(until.urlIs('https://www.google.com/'), 1500);
});
after(() => driver.quit());
});
});
Package.json看起来像这样:
{
"name": "crmvuesimple",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"unit": "jest"
},
"dependencies": {
"axios": "^0.19.0",
"core-js": "^3.3.2",
"i": "^0.3.6",
"idle-vue": "^2.0.5",
"jwt-decode": "^2.2.0",
"moment": "^2.24.0",
"socket.io-client": "^2.3.0",
"vue": "^2.6.10",
"vue-lodash": "^2.0.2",
"vue-router": "^3.1.3",
"vue-select": "^3.2.0",
"vue-tel-input": "^4.0.0",
"vuelidate": "^0.7.4",
"vuex": "^3.0.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.0.0",
"@vue/cli-service": "^4.0.0",
"@vue/test-utils": "^1.0.0-beta.30",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.9.0",
"chromedriver": "^79.0.0",
"geckodriver": "^1.19.1",
"jest": "^24.9.0",
"jest-environment-selenium": "^2.1.2",
"selenium-webdriver": "^4.0.0-alpha.5",
"vue-jest": "^3.0.5",
"vue-template-compiler": "^2.6.10"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
"^.+\\.(js)$": "babel-jest",
".*\\.(vue)$": "vue-jest"
},
"modulePaths": [
"<rootDir>"
]
}
}
提前谢谢!