mardi 26 mars 2019

Dynamic browser resolution for Protractor testing

my question concerns end to end testing scenario involving a responsive web app. I have written my test scenario for the pages to test with different test cases depending on the screen resolution. I am using array variables to store the different selectors linked to the same element, for example:

  it('should display the log in page', function () {
    gVar.signInButton = element(by.css(gVar.signInButtonSelector[gVar.SelectedMode]));
    gVar.signInButton.click().then(function(){
      expect(element(by.css(gVar.titleLoginPageSelector[gVar.SelectedMode])).getText()).toEqual(gVar.titleLoginPage[i]);
    });

Here I am trying to select the login page title to test it. Depending on the resolution, only the selector is different, and I stored them in arrays...

In my conf.js I have a parameter variable that I use in the command line to set the configuration I want to use:

    exports.config = {
    //...

      params:{
            resolutionConfig:'default'
            },  

    //...
    }       

the run command can go:

protractor conf.js --params.resolutionConfig=Classic or

protractor conf.js --params.resolutionConfig=Mobile or

protractor conf.js --params.resolutionConfig=Tablet ...

(Then I have a matching table to associate this parameter to the above integer value: gVar.SelectedMode)

What I would like to do now, is to set different resolutions values for my browser, a different one for each value of resolutionConfig parameter I am testing. So far, I know how to set that resolution with hardcoded values:

    exports.config = {
    //...

    capabilities: {
        browserName: 'chrome',
        chromeOptions: {
            args: ['--window-size=100,100'] // THIS!
        }

    //...
    }       

I have heard of "multicapabilities" to run parallel tests, but it is not exactly what I want… is it possible to have the resolution parameters in variable and add a logic to it? Something like:

    if(resolutionConfig) is "mobile" then: ['--window-size=xx,xx']; 
    if(resolutionConfig) is "tablet" then: ['--window-size=yy,yy'];

Aucun commentaire:

Enregistrer un commentaire