1

I am writing a protractor test suite and I want to execute them across different OS platforms. I develop on Windows, hence my primary settings is set according to Windows, but my primary execution environment is linux. The issue is that before I push the code I need to comment settings specific to Windows and enable settings specific to linux. Is there any way to maintain both settings and select them based on execution profile?

Example: The settings for a video-reporter on windows is -

jasmine.getEnv().addReporter(new VideoReporter({
  baseDirectory: './test-output/videoreport',
  createSubtitles: false,
  saveSuccessVideos: true,
  singleVideo: true,
  ffmpegCmd: "C:/FFmpeg/bin/ffmpeg.exe",
  ffmpegArgs: [
    '-f', 'gdigrab',
    '-framerate', '30',
    '-video_size', 'wsxga',
    '-i', 'desktop',
    '-q:v', '10',
  ]
}));

While the same for linux is -

jasmine.getEnv().addReporter(new VideoReporter({
  baseDirectory: './test-output/videos',
  saveSuccessVideos: true,
  ffmpegCmd: '/usr/local/bin/ffmpeg',
  ffmpegArgs: [
    '-y',
    '-r', '30',
    '-f', 'x11grab',
    '-s', '1280x1024',
    '-i', process.env.DISPLAY,
    '-g', '300',
    '-vcodec', 'mpeg4'
  ]
}));

At present I disable one and enable other as I switch between windows/linux. I want this to go and have both of them enabled but activate based on execution environment. Is there a way to do it?

1 Answers1

0

A good way to handle this would be in your onPrepare(). You could pass in an environment flag from the command line and use the onPrepare to set the correct settings.

--params.environment=windows
--params.environment=linux

Then in your onPrepare you could do something like this:

onPrepare: () => {  

  if(browser.params.environment === "linux") {

    jasmine.getEnv().addReporter(new VideoReporter({
      baseDirectory: './test-output/videos',
      saveSuccessVideos: true,
      ffmpegCmd: '/usr/local/bin/ffmpeg',
      ffmpegArgs: [
        '-y',
        '-r', '30',
        '-f', 'x11grab',
        '-s', '1280x1024',
        '-i', process.env.DISPLAY,
        '-g', '300',
        '-vcodec', 'mpeg4'
      ]
    }));

  } else {

    jasmine.getEnv().addReporter(new VideoReporter({
      baseDirectory: './test-output/videoreport',
      createSubtitles: false,
      saveSuccessVideos: true,
      singleVideo: true,
      ffmpegCmd: "C:/FFmpeg/bin/ffmpeg.exe",
      ffmpegArgs: [
        '-f', 'gdigrab',
        '-framerate', '30',
        '-video_size', 'wsxga',
        '-i', 'desktop',
        '-q:v', '10',
      ]
    }));
  }   

}
tehbeardedone
  • 2,833
  • 1
  • 15
  • 23
  • Update 1: I used this configuration in my environment of Windows and it works. Thanks for the much needed solution. Is there any way to split this across multiple configuration file and then have one master config file to include them as per requirement? – Debasish Mukherjee Jan 22 '18 at 13:54
  • Yeah, of course. You could setup each configuration in it's own file and then just use something like `var reporterConfig = require('path/to/videoreporter.config.js')` and `jasmine.getEnv().addReporter(new VideoReporter(reporterConfig))` – tehbeardedone Jan 23 '18 at 14:26