使用 Javascript 的黄瓜和量角器 - 写入单独的文本文件 [英] Cucumber and Protractor with Javascript - Write in a separate text file
本文介绍了使用 Javascript 的黄瓜和量角器 - 写入单独的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将 Cucumber 和 Protractor 与 Node.js 结合使用来测试我的 Web 应用程序.我使用 javascript 编写具有 chai 期望的代码.我需要在单独的文本文件中写入一些结果.我该怎么做?我需要文本文件中的结果,因为我在 excel 中分析了结果.代码是这样的:
I'm using Cucumber and Protractor with Node.js to test my web application. I use javascript to write code with chai expectation. I need to write some results in a separate text file. How can I do it? I need the result in the text file because, I analize the result in the excel. The code is that:
When('I insert the related username and password to access it', {timeout: 90*1000}, function (next) {
let username_field = element(by.css('.UsernameInput'));
browser.wait(until.presenceOf(username_field), 1200000, 'Element taking too long to appear in the DOM');
let username_password = element(by.css('.PasswordInput'));
browser.wait(until.presenceOf(username_password), 1200000, 'Element taking too long to appear in the DOM');
const fs = require('fs');
const userFile = fs.readFileSync('parametri.txt', {encoding: 'utf8'});
const users = userFile.split('\n');
const randomUser = () => {
const number = Math.floor(Math.random() * Math.floor(users.length - 1));
const user = users[number].split(',');
return {username: user[0], password: user[1]}
}
const user = randomUser();
username_field.sendKeys(user.username);
username_password.sendKeys(user.password);
username_field.getText().then(function(text){
var n=new Date();
var time= n.getTime();
browser.sleep(d);
console.log(time);
console.log('1°When');
function WriteFile(){
const feat1_stepUno = require('feat1_stepUno');
let a= '5000';
const file_time = feat1_stepUno.writeFile('tempo.txt',a,(err) => {
if (err) throw err;
})
}
expect(username_field.isPresent()).to.eventually.be.true.and.notify(next);
})
});
非常感谢您的帮助!
推荐答案
这可以解决您的问题:
const fs = require('fs');
fs.writeFile("tempo.txt", "Hey there!", function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
再见!
这篇关于使用 Javascript 的黄瓜和量角器 - 写入单独的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文