【发布时间】:2017-03-07 17:30:42
【问题描述】:
因此,我目前正在尝试查看使用 Node.js 的非常基本的 selenium 设置对于 Work 的外观,以便我们可以开始实施 E2E 测试。
所以我用 express 启动了一个基本的 node.js 服务器
const express = require('express');
const path = require('path')
const app = express()
const PORT = 3000
app.use(express.static('public'))
app.get('/', (req,res) => res.status(200).end() );
app.listen(PORT, 'localhost', (req,res) => console.log(`port running on ${PORT}`))
为了测试,我创建了一个非常基本的 html/css/js FE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<link rel="stylesheet" href="./styles.css">
<body>
<div id="testing-file">
This is a test
<span>
<p id="ryan">Ryan</p>
</span>
</div>
<script>
console.log('hello')
</script>
</body>
</html>
//样式
#testing-file {
color: red;
font-size: 2em;
}
#ryan {
color: blue;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
现在这里是测试设置,这是我第一次使用 Selenium,并且真正尝试像这样从头开始设置 E2E。所以,在阅读了整个上午的文档后,我来到了这里。
Nightwatch.json 文件
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : false,
"server_path" : "",
"log_path" : "",
"port" : 9515,
"cli_args" : {
"webdriver.chrome.driver" : "./chromedriver/",
"webdriver.gecko.driver" : "",
"webdriver.edge.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost:3000",
"selenium_port" : 9515,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "firefox",
"marionette": true
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome"
}
},
"edge" : {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
}
}
}
nightwatch.js 文件
module.exports = {
src_folders: ['test/e2e/']
}
test.js 文件
module.exports = {
'step one' : browser => {
browser
.url('http://localhost:3000')
.waitForElementVisible('body', 200);
}
}
现在我正在学习基础知识,但是当我运行测试时,我收到了错误:
[E2e\test] Test Suite
=========================
Running: step one
Error processing the server response:
unknown command: wd/hub/session
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ value: -1, error: 'Unexpected token u in JSON at position 0' }
所以我当然认为我没有正确设置 selenium web 驱动程序,这很可能是我的问题,因为它非常困难。需要注意的是,我在窗户上。我确实将我的 PATH 变量设置为我在项目文件夹中拥有 selenium 驱动程序的路径。它似乎试图运行测试,但问题似乎与 selenium 驱动程序没有启动有关。
我的节点服务器在 3000 上,如果我双击 Windows Web 驱动程序应用程序说驱动程序在端口 9515 上,只是提供静态文件和硒。现在我到目前为止在网上阅读的所有内容都说端口在 4444,但我真的不明白我现在在读什么。所以基本上我需要在浏览器chrome上运行一个简单的测试。如果需要任何其他信息,请告诉我
【问题讨论】:
标签: javascript selenium testing nightwatch.js e2e-testing