我需要使用javascript从文本文件中读取用户名和密码。你能帮助我吗?

时间:2019-02-26 10:17:19

标签: javascript protractor cucumber readfile

我正在使用带有Javascript的黄瓜和量角器来测试我的Web应用程序。我必须并行登录不同的用户,并且在config / userFile.txt中的文本文件上具有相关的凭据。 我该怎么办?

这是我在台式机上拥有的config / userFile.txt:

Giacomo,1234
Veronica,5908
Marcela,48ff21

这是我的test.config

    const path = require("path");
const jsonReports = process.cwd() + "/reports/json";
const Reporter = require("../support/reporter_login_2/reporter");

exports.config = {
  ignoreUncaughtExceptions: true,
  seleniumAddress: "http://localhost:4444/wd/hub",
  getPageTimeout: 60000,
  allScriptsTimeout: 500000,
  capabilities: {
    browserName: process.env.TEST_BROWSER_NAME || "chrome",
    'chromeOptions': {
     //'args': ['--user-data-dir=~/.e2e-chrome-profile'],
      'args': ['--disable-web-security', '--user-data-dir=~/.e2e-chrome-profile']
    }
  },
  framework: "custom",
  frameworkPath: require.resolve("protractor-cucumber-framework"),
  specs: ["../features/login_2/*.feature"],
  // resultJsonOutputFile: "./reports/json/protractor_report.json",
  onPrepare: function() {
    var chai = require('chai');
    chaiAsPromised = require('chai-as-promised');
    chai.use(chaiAsPromised);
    chai.should();
    global.expect = chai.expect;
    browser.ignoreSynchronization = true;
    browser.manage().window().maximize();
    require('babel-register');
    Reporter.createDirectory(jsonReports);
  },
  cucumberOpts: {
    //strict: true,
    format: 'json:./reports/json/cucumber_report.json',
    require: ["../stepDefinitions/login_2/*.js"],
    tags: "(@login2Step1)"
    //@manualTask1Step1 or @manualTask1Step2 or 
      },
  onComplete: function () {
    Reporter.createHTMLReport();
  }
};

这是我的功能文件:

    Feature: Verify the login action of mysite
  As we are sites user
  We want to complete the login action


  @login2Step1
  Scenario: Verify the login of myapp
    Given I am on mysite
    When I insert the related credential
    Then I want to access portal

这是我的空Stepdefinition.js:

import { browser } from 'protractor';
//var browser = require("protractor");
//var Given, When, Then = require("cucumber");
import { Given, When, Then } from "cucumber";
//var Given = require("cucumber");
//var When = require("cucumber");
//var Then = require("cucumber");
var Globals = require("../../support/Globals");
//import Globals from '../../../support/Globals';
//import { Given, When, Then } from "cucumber";

// Chai
//const globals = new Globals();
//const expect = globals.expect;
//const assert = globals.assert;
var chai = require('chai');
chai.should();

function getArrPath(){
    var path = document.location.href;
    console.log("path",path);
    var urlArray = path.split('/');
    console.log("urlArray",urlArray[3]);
    return urlArray;
}

var until = protractor.ExpectedConditions;


Given('I am on mysite', function (next) {
    browser.get('www.mynewsite.com');
    browser.sleep(5000);
    next();    
});

When('I insert the related credential', function (next) {
    next();
});

Then('I want to access portal', function (next) {
    next();
});

要执行此操作,我必须在步骤定义文件中编写哪些代码?我需要其他东西来做这些东西吗?

0 个答案:

没有答案