Protractor: How to access global variables that we have inside our application?

妖精的绣舞 提交于 2019-12-13 08:57:21

问题


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.

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

Thanks, Madhan


回答1:


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')


来源:https://stackoverflow.com/questions/26241520/protractor-how-to-access-global-variables-that-we-have-inside-our-application

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