简体   繁体   English

如何为最终用户构建简单的UI屏幕以在Node Js中实现自动化

[英]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屏幕以自动执行测试用例。

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模块

Basic concept 基本概念

演示应用

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();
}

Web application Web应用程序

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 ,并在服务器每次收到该请求时调用函数:

server.js server.js

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请求以进行测试:

index.html (End user) index.html(最终用户)

<script>
  function runTest() {
    // Run the test and do something with the results...
    fetch("/test").then(res => {...});
  }
</script>

<button onclick="runTest();">Run the test!</button>

Desktop application 桌面应用

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的完全访问权限。

renderer.js renderer.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();
}

Index.html Index.html

<button onclick="AutomateGoogleSearch();">Automate search test!</button>

Example

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

Notes 笔记

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.

相关问题 可以在Node js后端代码中进行构建吗? 如果是的话,如何使用npm获取节点js? - can i get build in node js back-end code ? if yes means, how to get node js build using npm? 我如何构建一个简单的节点js服务器来发送和接收到客户端? - How do I build a simple node js server that sends and receives to a client? 如何在Node中使用Passport.js模拟另一个用户? - How can I impersonate another user with Passport.js in Node? 如何在节点 js 中将用户重定向到他们的特定页面 - How can i redirect user to their specific page In node js 如何将新的 React JS 前端嵌入到我现有的单体 Node JS 应用程序中? - How can I embed new React JS Front-end in my existing monolithic Node JS App? 如何在简单的node.js应用中按用户查找和显示? - how to find and show by user in a simple node.js app? 如何在node.js中文件的每一行末尾添加文本? - How can I add text to the end of each line of a File in node.js? 如何存根Node.js MongoDB链式fn调用来模拟最终结果? - How can I stub a Node.js MongoDB chained fn call to mock my end result? 如何使用 v-model 和 v-if 使用 Vue.js 构建一个简单的计算器? - How can I build a simple calculator with Vue.js, using v-model and maybe v-if? node-webkit:如何检测用户使用的屏幕/监视器数量? - node-webkit: How can I detect how many screen/monitor user have using?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM