量角器:如何访问我们的应用程序中的全局变量?

时间:2022-12-12 01:20:11

Hope if someone could help. I am working on an Angular based application. I am automating my End to End tests with the help of Protractor. I have a global variable set in my Application called "selectedPlatform", which conveys, for which platform(iOS/Android) I have my current application build for.

希望有人能帮忙。我正在研究一个基于角度的应用程序。在量角器的帮助下,我自动结束测试。我在我的应用程序中设置了一个名为“selectedPlatform”的全局变量,该变量表示我当前应用程序构建的平台(iOS/Android)。

I need to access this variable for me write my test cases accordingly. Any help on this ground is greatly appreciated.

我需要访问这个变量,以便编写我的测试用例。对这方面的任何帮助都深表感谢。

Thanks, Madhan

谢谢,Madhan

1 个解决方案

#1


2  

If I understand correctly, your variable is a global inside your website, i.e. it's on window. Generally, your end to end tests should avoid accessing variables directly in your site's code, but if you have to do this you can do:

如果我理解正确,你的变量在你的网站内是一个全球性的,也就是说它在窗口。一般情况下,结束测试应该避免直接访问站点代码中的变量,但是如果您必须这样做,您可以这样做:

browser.executeScript('return window.selectedPlatform')

#1


2  

If I understand correctly, your variable is a global inside your website, i.e. it's on window. Generally, your end to end tests should avoid accessing variables directly in your site's code, but if you have to do this you can do:

如果我理解正确,你的变量在你的网站内是一个全球性的,也就是说它在窗口。一般情况下,结束测试应该避免直接访问站点代码中的变量,但是如果您必须这样做,您可以这样做:

browser.executeScript('return window.selectedPlatform')