[英]run testcafe tests from Python
我的问题摘要:目标:我有一个 javascript package,它使用 testcafe 在 python.org 上执行简单搜索。 我正在尝试使用 js2py 在 python 测试框架中使用这个 package 但是当我尝试'require(“pyCafe”)时它给了我错误。
预期:能够在 python 中毫无问题地使用 js package。 我的目标是使用 Python 中的 testcafe 自动化脚本,不确定是否可行。
错误:解析文件 /private/var/folders/1n/tr0826l14yv89b5ypl4sbsc46qb010/T/tmpgnnrdlan/node_modules/fast-glob/out/readers/sync.js:在 Deps.parseDeps (/private/var/) 出现意外的令牌 (15:10)在 getDeps (/private/var/folders/1n/tr0826l14yv89b5ypl4sbsc46qb010/T/tmpgnnrdlan/node_modules/module-deps/ js:447:44) 在 /private/var/folders/1n/tr0826l14yv89b5ypl4sbsc46qb010/T/tmpgnnrdlan/node_modules/module-deps/index.js:430:38 在 ConcatStream。 (/private/var/folders/1n/tr0826l14yv89b5ypl4sbsc46qb010/T/tmpgnnrdlan/node_modules/concat-stream/index.js:37:43) 在 ConcatStream.emit (events.js:327:22) 在 finishMaybe (/private/var /folders/1n/tr0826l14yv89b5ypl4sbsc46qb010/T/tmpgnnrdlan/node_modules/readable-stream/lib/_stream_writable.js:630:14)在endWritable(/private/var/folders/1n/tr0826l14yv89b5ypl4sbsc46qb010/T/tmpgnnrdlannodes/-可读模块/ /lib/_stream_writable.js:638:3) 在 ConcatStream.Writable.end (/private/var/folders/1n/tr0826l14yv89b5ypl4sbsc46qb010/T/tmpgnnrdlan/node_modules/readable-stream/lib/_stream_writable.js:594:41) 在Object.onceWrapper (events.js:421:28)
到目前为止我已经尝试过:
我在 javascript/testCafe 中创建了一个 UI 自动化框架并在内部发布
创建整个 javascript/testcafe 框架的 npm package 'pyCafe' 并将其推送到内部工件。 通过运行 'npm install pyCafe' 进行测试,它安装得很好,但在 python 中使用 'require('pyCafe')' 会出现上述错误。
还尝试从 js 代码本身调用上述 package ,这也会产生错误。 {"code":"E1","isTestCafeError":true,"callsite":{"filename":"/Users/xxx/work/newjstest/node_modules/pyCafe/features/search.js","lineNum":23 ,"callsiteFrameIdx":5,"stackFrames":[{},{},{},{},{},{},{},{},{},{},{},{},{} ,{},{},{},{},{},{},{}],"isV8Frames":true},"errStack":"错误:未找到广告展示位置。\n at w ( https:/ /media.ethicalads.io/media/client/v1.4.0/ethicalads.min.js:2:12068 )\n 在https://media.ethicalads.io/media/client/v1.4.0/ethicalads.min。 js:2:13187","pageDestUrl":"https://www.python.org/","id":"KgxFSGD"}下面的代码,因为我无法上传到 git。
Pycafe/features/serach.js
var { Selector, t, ClientFunction } = require('testcafe');
class SearchPageModel {
constructor () {
this.TIMEOUT = 500
this.search = Selector('#id-search-field')
this.go = Selector('#submit')
this.noResult = Selector('p').withExactText('No results found.')
}
}
class SearchPage {
constructor() {
this.model = new SearchPageModel()
}
async search(item='webdriver') {
await t
.typeText(this.model.search, item)
.click(this.model.go)
.expect(this.model.noResult.exists).ok()
}
}
module.exports = new SearchPage()
#!/usr/bin/env node
module.exports = {
Search: require('./features/search.js'),
}
{
"name": "pyCafe",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cd tests; testcafe chrome test.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"browserify-shim": "^3.8.15",
"js-yaml": "^3.14.1",
"minimist": "^1.2.5",
"testcafe": "^1.18.0",
"winston": "^3.8.1"
}
}
var { t } = require('testcafe');
var {search} = require('../features/search.js')
fixture `Test`
.page("https://www.python.org/")
test
.meta({
'testcase': 'C221913',
})
('Test https://www.python.org/', async t => {
try {
console.log('search python.org')
await search.search()
} catch (e) {
console.log('Testcase C221913 failed...')
}
});
所以这是我的问题:
您可以通过命令行界面使用任何语言执行 TestCafe 测试。 如我所见,您已经在使用它。 代码片段:
"scripts": {
"test": "cd tests; testcafe chrome test.js"
},
您正确运行了 TestCafe 测试。 您对Java Script error tracking
功能感到困惑。 默认情况下,TestCafe 会在测试的 web 页面上处理 JavaScript 错误,如果发生则无法通过测试。 https://www.python.org/出现 JavaScript 错误。
TestCafe 处理它。 要禁用此行为,您可以指定“--skip-js-error”选项。 对于您的用例,它需要更改代码如下:
"scripts": {
"test": "cd tests; testcafe chrome test.js -e"
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.