量角器:使用CLI中特定于环境的参数运行测试

时间:2018-07-27 20:54:23

标签: typescript testing protractor cucumber command-line-interface

我正在研究量角器打字稿测试框架,并希望根据我在CLI中发送的特定于环境的参数在不同的环境中运行测试。例如:我想以“ npm test SIT”或“ npm test dit”运行测试。基本URL在情况1中选择SIT的URL,在情况2中选择DIT的URL,以在不同的SIT和DIT环境中启动应用程序。

我已将文件名为Url.js(root / data / Url.js)

'use strict';
var env = browser.params.environment;

module.exports = {
  baseURL: function() {
    var baseUrl = '';
    if (env.toLowerCase().indexOf('sit') === -1) {
      baseUrl = 'https://'+env+'-site.com/app/home';
    } else if(env.toLowerCase().indexOf('dit') === -1){
      baseUrl = 'https://'+env+'-site.com/app/home';
    } else if(env.toLowerCase().indexOf('rit') === -1){
      baseUrl = 'https://'+env+'-site.com/app/home';
      }
    return baseUrl;
  }, 
  internalPage1: 'app/page/details/fff/ttt.html'  
};

这是我的配置文件

let path = require('path');
import { browser, Config } from "protractor";
import { Reporter } from "../support/reporter";
import * as oracledb from 'oracledb';
const jsonReports = process.cwd() + "/reports/json";


export const config: Config = {
    params:{
        environment: 'fdi', //dit or rit can be passed from cmd line        
    },

    seleniumAddress: "http://localhost:4444/wd/hub",

    SELENIUM_PROMISE_MANAGER: false,    

    capabilities: {

        browserName: 'chrome',
        maxInstances: 6

    },

    framework: "custom",
    frameworkPath: require.resolve("protractor-cucumber-framework"),

    specs: [
        "../../features/automation/regression/*.feature",
    ],

    onPrepare: () => {
        browser.ignoreSynchronization = true;
        browser.manage().timeouts().implicitlyWait(12000);
        browser.manage().window().maximize();
        Reporter.createDirectory(jsonReports);      

    },

    cucumberOpts: {
        compiler: "ts:ts-node/register",
        format: "json:./reports/json/cucumber_report.json",
        require: ["../../typeScript/stepdefinitions/*.js",
         "../../typeScript/support/*.js", 
         "../../dbUtils/index"],
        strict: true,
        tags: "@dataTable",        
        restartBrowserBetweenTests: true


    },

    onComplete: () => {
        Reporter.createHTMLReport();
    },
};

黄瓜挂钩:

const { BeforeAll, After, AfterAll, Status, setDefaultTimeout, Before  } = require("cucumber");
import * as fs from "fs";
import { browser } from "protractor";
import { config } from "../config/config";
import { build$ } from "protractor/built/element";
var env = browser.params.environment;

//setDefaultTimeout(600 * 1000);

Before(async function ()  {
    await browser.get(env);
});

After(async function(scenario) {
    if (scenario.result.status === Status.FAILED) {
        // screenShot is a base-64 encoded PNG
         const screenShot = await browser.takeScreenshot();
         this.attach(screenShot, "image/png");
    }    
});

 AfterAll(async () => {
     await browser.quit();
 });

我不知道是否应该在config.ts中调用Url.js,我想可以,但是我不确定该怎么做。有人可以给我一些指示,让我知道谁可以确定这一点吗?

0 个答案:

没有答案