Using cross-platform keyboard shortcuts in end-to-end testing

后端 未结 1 1220
予麋鹿
予麋鹿 2020-12-03 22:30

The Problem:

In our rather big test codebase, we are using different keyboard shortcuts. For instance, to copy selected text we are using CTRL

相关标签:
1条回答
  • 2020-12-03 22:48

    Here's my best to answer your first question, for the two scenarios -

    • If multiple testers run the scripts in their own machine, the helper method can be placed in onPrepare() function assigning the value to a constant global variable, which will be available for all the tests.

    • If all the tests are run on a distributed platform where all tests are randomly assigned to different machines, in that case writing the helper method assigning the value to a constant local variable for that test in beforeAll() function will be useful.

    Moving to your second question, there is also another way where we can get the platform on which the test spec is being executed using protractor's getCapabilities() method.

    Code for getting the platform type -

    //Below code can be placed either in `onPrepare()` function or `beforeAll()` function depending the need.
    //If the below code is placed in the `beforeAll()` function then i guess there won't be any need for a global variable.
    
    browser.controlKey = protractor.Key.CONTROL; //browser.controlKey is a global variable and can be accessed anywhere in the test specs
    browser.getCapabilities().then(function(capabilities){
        if(capabilities.caps_.platform === "MAC")
            browser.controlKey = protractor.Key.COMMAND;
    });
    

    Usage:

    elm.sendKeys(protractor.Key.chord(browser.controlKey, "c")); //if its stored as global variable
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题