How do I parameterize the baseUrl property of the protractor config file

前端 未结 3 1002
感动是毒
感动是毒 2021-01-03 23:51

I need to run my protractor tests in different contexts with different baseUrls in the config files. I don\'t want to use separate config files for each situati

3条回答
  •  甜味超标
    2021-01-04 00:32

    I know, old one. but if anyone is still looking for a way to define a url based on capability (I had to do this because Ionic 5 will run in browser on port 8100, but in the app - unchangable - without port declaration on port 80, I use Appium)

    add a baseUrl parameter inside your capability declaration.

    {
        browserName: 'chrome',
        baseUrl: 'http://localhost:8100' //not required but as example
    }
    
    {
        ...
        app: 'path to app.apk',
        baseUrl: 'http://localhost'
        ... 
    }
    

    and then configure your onPrepare method as follows.

     async onPrepare() {
        const config = await browser.getProcessedConfig();
    
        if(config.capabilities.hasOwnProperty('baseUrl')) {
            browser.baseUrl = config.capabilities.baseUrl;
        }
    }
    

    OnPrepare runs for each capability you define in your multiCapabilities array. the getProcessedConfig returns the config as you defined it, with the addition of the current capability. Since that method returns a promise, I use async/await for readability.

    This way, you can have multiple capabilities running, with each different a different host.

提交回复
热议问题