Set browser timezone in a Protractor test

前端 未结 1 631
生来不讨喜
生来不讨喜 2020-12-21 19:33

I\'m working on a project where the e2e tests are made using protractor.

Some tests, need to validate date/times. Tests are ok on our continuous deliver platforms th

相关标签:
1条回答
  • 2020-12-21 19:52

    Late answer, but maybe someone in the future can use this...It is a bit ugly, but I haven`t found anything prettier.It might not work for you, it depends on how your app detects timezone. If it is with getTimezoneOffset() this will work.

    Basically it rewrites Date() class, and adds setTimezoneOffset() to it.

    1. Add TimeShift.js into your helpers: https://github.com/cvakiitho/TimeShift-js/blob/master/timeshift.js
    2. Load TimeShift in your tests: var TimeShift = require('./helpers/timeshift.js');
    3. Execute TimeShift, and alter timezone:

      dvr = browser.driver;
      dvr.executeScript(TimeShift).then(function(){
              dvr.executeScript('' +
                  'angular.isDate = function(x){return x instanceof Date};' +
                  'Date = TimeShift.Date;' +
                  'TimeShift.setTimezoneOffset(60);' +
          });
      

    Note: Every page refresh destroys this.

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