在 Protractor e2e 测试中设置时区
我有一些处理时区的 Protractor e2e 测试.在我的本地机器上它们通过了,在 Appveyor 上它们没有.
I have some Protractor e2e tests in which I deal with timezone. On my local machine they pass, on Appveyor they don't.
我发现这是一个时区设置问题(Appveyor 上的不同设置).
I found out it's a timezone setting issue (different settings on Appveyor).
有没有办法在测试套件开始时设置时区并在结束时将其恢复为旧时区?
Is there a way to set the timezone at the start of the test suite and bring it back the old one at the end?
我尝试了这个解决方案(所以请不要将其标记为重复):在量角器测试中设置浏览器时区
I tried this solution (so please don't mark this as duplicate): Set browser timezone in a Protractor test
我发现这是一个非常丑陋的解决方法.有更漂亮的吗?
which I found to be a very ugly workaround. Anything prettier?
推荐答案
您可以使用 PowerShell 更新时区并在之后重置.这可以使用 AppVeyor 环境变量、Get-TimeZone &设置时区.这是一个 appveyor.yml
示例:
You could use PowerShell to update the timezone and reset it after. This can be achieved using AppVeyor environment variables, Get-TimeZone & Set-TimeZone. Here is an appveyor.yml
sample:
init:
- ps: $env:ORIGIONAL_TZ = Get-TimeZone
- ps: Set-TimeZone -Name "Pacific Standard Time"
on_finish:
- ps: Set-TimeZone -Name $env:ORIGIONAL_TZ
相关文章