简体   繁体   English

量角器-将JavaScript注入测试页面

[英]Protractor - inject JavaScript into tested page

I am writing an auto-login script for Chrome Extension, I would like to use Protractor to be able to run multiple test against different web pages. 我正在为Chrome扩展程序编写自动登录脚本,我希望使用Protractor能够针对不同的网页运行多种测试。

Chrome Extension is adding JavaScript code into the webpage/tab. Chrome扩展程序正在将JavaScript代码添加到网页/标签中。

Can use Protractor to do the same? 可以使用量角器做同样的事情吗? ie Create a script tag inside tested page & run the code? 即在测试页面内创建脚本标签并运行代码?

Any suggestions much appreciated. 任何建议,不胜感激。

You can use executeScript or executeAsyncScript: 您可以使用executeScript或executeAsyncScript:

http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.executeScript http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.executeScript

http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.executeAsyncScript http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.executeAsyncScript

Those functions come from the webdriver api itself. 这些功能来自webdriver api本身。 To access them just use: 要访问它们,只需使用:

browser.executeScript('js code to run on the browser')

or 要么

browser.executeAsyncScript(function fnToRunInBrowser(inputFromTest) {}, inputForSript).then(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM