javascript - browser.pause() 和 browser.enterRepl() 有什么区别?

标签 javascript angularjs selenium selenium-webdriver protractor

在 Protractor 中,有 browser.pause() function :

Beta (unstable) pause function for debugging webdriver tests. Use browser.pause() in your test to enter the protractor debugger from that point in the control flow.

element(by.id('foo')).click();
browser.pause();
// Execution will stop before the next click action.
element(by.id('bar')).click();

还有一个不太为人所知的 - browser.enterRepl() :

Beta (unstable) enterRepl function for entering the repl loop from any point in the control flow. Use browser.enterRepl() in your test. Does not require changes to the command line (no need to add 'debug').

element(by.id('foo')).click();
browser.enterRepl();
// Execution will stop before the next click action.
element(by.id('bar')).click();

从提供的文档和示例中,很明显它们都用于调试测试。但是,尚不清楚两者之间有什么区别。

我们什么时候应该使用pause(),什么时候应该使用enterRepl()

最佳答案

docs 中对此进行了解释总的来说,但我会尝试更深入一些。

Protractor 有two modes用于调试:DebuggerReplCommandRepl

Repl 这里代表 Read-eval-print-loop 这通常意味着无论您输入什么命令,它都会立即在当前上下文中进行评估,并且您可以立即提供结果。例如,Chrome 开发者工具中的控制台有点像REPL,用于Chrome实现JavaScript/DOM,或者当你运行node时在终端中,您将获得 Node.js 的 JavaScript 上下文的 REPL - 您可以键入命令并获取结果。

<小时/>

当您使用browser.pause()时您正在激活DebuggerRepl。它为您带来了一个Repl,您可以在其中执行此模式的命令。您通常会在终端中看到以下命令列表:

press c to continue to the next webdriver command
press d to continue to the next debugger statement
type "repl" to enter interactive mode
type "exit" to break out of interactive mode
press ^C to exit

因此您可以使用c转到下一个WebDriver命令命令或跳转到下一个browser.pause()在测试中使用 d 声明命令。当您使用它们时,它们会立即执行。因此,这种模式基本上允许您跳过页面状态并探索结果。 (注意:此模式提供 more commands ;它们确实有效,但我不确定它们的输出的含义是什么以及它们对 Protractor 用户是否有用。)

<小时/>

当您使用browser.enterRepl()时您正在激活CommandRepl 模式。它允许您使用在测试中使用的 Protractor 方法,但以交互模式进行。您可以访问element , browserprotractor对象,因此您可以运行例如:

> $('.hello').getText();
> 'World'

它会立即打印回结果,因此它有点像沙箱,您可以在其中当前页面状态查询 DOM 并查看结果。

您可能已经注意到,browser.pause()命令列表中有一行:

type "repl" to enter interactive mode

这意味着当您处于DebuggerRepl模式时,您可以执行repl命令为刚刚运行 browser.pause()当前页面状态激活 CommandRepl 模式 ,因此您可以像刚刚使用 browser.enterRepl() 一样使用 DOM 。您可以使用 exit 返回DebuggerRepl 模式命令。但如果您已使用 browser.enterRepl() 进入 CommandRepl 模式 ,您无法切换到 DebuggerRepl 模式。

此外,CommandRepl 模式可以通过名为 elementExplorer 的功能激活。无需任何笔试即可使用;它只是在 CommandRepl 模式下打开一个 URL。

<小时/>

tl;博士

总而言之,我相信它们应该根据它们的名称来使用。

browser.pause() - 我希望浏览器恰好在该位置暂停,以便我可以看到页面上发生的情况。然后,根据我的命令,我希望它跳到下一个状态,这样我就可以看到这里发生了什么。如果我需要当前状态的更多信息,我可以运行 repl并使用 Protractor API( browserelementprotractor )进行调查。然后我就可以exit此模式并继续跳过状态。

browser.enterRepl() - 我希望浏览器恰好在该位置暂停,让我立即使用 Protractor API 调查页面( browserelementprotractor ),而我不需要能够在页面状态之间跳转。

关于javascript - browser.pause() 和 browser.enterRepl() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31413300/

相关文章:

python - 如何使用 Python Selenium 选择输入元素

javascript - 隐藏函数 $ 控制台错误?

javascript - 奇怪的箭头函数参数行为

java - 使用 AngularJS 传递参数时 Resteasy @FormParam null

javascript - @ngrx/store 与 Angular 2 : Cannot read property of undefined

java - 如何使用 Selenium WebDriver 和 Java 发送 HTTP 请求代码?

java - J单元。并行运行。但是所有的测试方法都处理单例实例。怎么解决?

Javascript加密库(客户端加密|服务器端解密)

Javascript - 在 Chrome 53 上模拟按键事件

javascript - ng-repeat 只添加一次