[英]How can I build simple UI screen for end user for automation in Node Js
I am using Selenium webdriver, Javascript and Node JS to automate test cases. 我正在使用Selenium Webdriver,Javascript和Node JS来自动化测试用例。 I have just wrote basic test case like :
我刚刚编写了基本的测试用例,例如:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('simple programmer');
driver.findElement(webdriver.By.name('btnK')).click();
driver.quit();
I can easily run above test case using command line node mytestcase.js
我可以使用命令行
node mytestcase.js
轻松地在测试用例之上运行
Now what I want it Give simple UI screen like web page to end user where I want to put button foe ex: Automate Google search
and as soon as user click on this button, test case will run automatically. 现在,我想要的东西给最终用户一个简单的UI屏幕,例如网页,我要在其上放置按钮。例如:
Automate Google search
,一旦用户单击此按钮,测试用例就会自动运行。
Is there any chance I can do above? 我有什么可以做的以上吗? I just need hint about how can I given simple UI screen to user to automate test cases by just clicking on button.
我只需要提示如何通过单击按钮就可以为用户提供简单的UI屏幕以自动执行测试用例。
Node
by itself won't provide a GUI
solution, so you need to use an external framework. Node
本身不会提供GUI
解决方案,因此您需要使用外部框架。
See: Is there any standlone gui module for node application 请参阅: 是否有用于节点应用程序的独立gui模块
Wrap your code inside a function and call it when the user clicks the button: 将您的代码包装在一个函数中,并在用户单击按钮时调用它:
function myTest() {
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('simple programmer');
driver.findElement(webdriver.By.name('btnK')).click();
driver.quit();
}
You can try to use some framework like express 您可以尝试使用一些框架,如快递
Fast, unopinionated, minimalist web framework for node.
快速,简单,极简的节点Web框架。
Since you will be using node
as a web Server you can create a route: /test
, and call your function every time the server gets that request: 由于将
node
用作Web服务器,因此可以创建路由/test
,并在服务器每次收到该请求时调用函数:
var express = require('express')
var app = express()
app.get('/test', function (req, res) {
// Webdriver test case code
var results = myTest();
// send results or render custom UI
res.send(results);
})
// http://localhost:3000
app.listen(3000, () => console.log('Example app listening on port 3000!'))
Now in the client side, trigger an http
request for your test every time the user clicks the button: 现在在客户端,每当用户单击按钮时,触发一个
http
请求以进行测试:
<script>
function runTest() {
// Run the test and do something with the results...
fetch("/test").then(res => {...});
}
</script>
<button onclick="runTest();">Run the test!</button>
If you don't want to use a server then you can use electron : 如果您不想使用服务器,则可以使用electronic :
Build cross platform desktop apps with JavaScript, HTML, and CSS
使用JavaScript,HTML和CSS构建跨平台的桌面应用程序
Electron exposes full access to Node.js both in the main and the renderer process. Electron在主进程和渲染器进程中都公开了对Node.js的完全访问权限。
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
function AutomateGoogleSearch() {
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('simple programmer');
driver.findElement(webdriver.By.name('btnK')).click();
driver.quit();
}
<button onclick="AutomateGoogleSearch();">Automate search test!</button>
For a full example see electron-quick-start 有关完整示例,请参见电子快速入门
// Clone this repository
git clone https://github.com/electron/electron-quick-start
// Go into the repository
cd electron-quick-start
// Install dependencies
npm install
// Run the app
npm start
This are minimal examples, please see the full documentation and guides of each project: 这是最小的示例,请参阅每个项目的完整文档和指南:
If you want to create a desktop app you could use libui-node . 如果要创建桌面应用程序,则可以使用libui-node 。
Npm install it: npm install --save libui-node
Npm安装它:
npm install --save libui-node
Create a UiWindow
, add a UiButton
. 创建一个
UiWindow
,添加一个UiButton
。
Set the onClicked
callback to launch your test. 设置
onClicked
回调以启动测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.