问题
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