Set browser timezone in a Protractor test

此生再无相见时 提交于 2019-11-29 16:08:21

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!