angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

Support async protractor config #5148

Open Amy-Lynn opened 5 years ago

Amy-Lynn commented 5 years ago

Feature Request

In protractor.conf.js, allow the export to be either a config object (current behavior) or a promise that resolves to the config object.

Happy to try a PR.

troppoli commented 5 years ago

I was looking for more information about starting spectron within a protractor process. It seems that you did that with some success. The config for protractor seems to want the selenium session id at launch, I saw that there is a beforeLaunch hook that I was thinking might be a place to boot spectron and get the seleniumSessionId setup as well as stuffing the spectron object into browser for later use. Did you try that approach?

troppoli commented 5 years ago

here's where I ended up, seems to work. I expect that I could add app to the the 'params' object and that would be available in the tests.

import {Config} from 'protractor';
import { Application } from 'spectron';

let app:Application;

export let config: Config = {
    framework: 'jasmine',
    specs:['something_spec.js'],
    seleniumAddress:'http://localhost:9515/wd/hub',
    beforeLaunch: async()=>{
        app = new Application({
            path: 'PATH_TO_ELECTRON_APP.exe',
            webdriverLogPath:'c:\\temp\\webdriverlog.log'
          })
          await app.start();
          let s:any = await app.client.session();
          config.seleniumSessionId = s.sessionId;
    },
    afterLaunch: async (exitCode: number) =>{
        return app.stop();
    }
};