javascript browser.pause() 和 browser.enterRepl() 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31413300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between browser.pause() and browser.enterRepl()?
提问by alecxe
In protractor, there is the browser.pause()
function:
在量角器中,有以下browser.pause()
功能:
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.
pause
用于调试 webdriver 测试的Beta(不稳定)功能。在测试中使用 browser.pause() 从控制流中的那个点进入量角器调试器。
element(by.id('foo')).click();
browser.pause();
// Execution will stop before the next click action.
element(by.id('bar')).click();
And, also, there is a less-known one - browser.enterRepl()
:
而且,还有一个鲜为人知的 - 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').
enterRepl
用于从控制流中的任何点进入 repl 循环的Beta(不稳定)函数。在您的测试中使用 browser.enterRepl()。不需要更改命令行(无需添加“调试”)。
element(by.id('foo')).click();
browser.enterRepl();
// Execution will stop before the next click action.
element(by.id('bar')).click();
From the provided documentation and examples, it is clear that they both are used for debugging the tests. But, it is not clear, what is the difference between the two.
从提供的文档和示例中,很明显它们都用于调试测试。但是,目前还不清楚,两者之间有什么区别。
When should we use pause()
and when enterRepl()
?
我们应该什么时候使用pause()
,什么时候使用enterRepl()
?
回答by Michael Radionov
It's explained in the docsin general, but I'll try to get a bit deeper.
它在文档中一般都有解释,但我会尝试更深入一些。
Protractor has two modesfor debugging: DebuggerRepland CommandRepl.
Protractor 有两种调试模式:DebuggerRepl和CommandRepl。
Replhere stands for Read-eval-print-loopwhich usually means that whatever command you type in, it gets evaluated right away in the current context and you are provided with a result immediately. For example, the console in Chrome Developer Toolsis kinda a REPLfor Chrome'simplementation of JavaScript/DOM, or when you run node
in terminal, you get a REPLfor Node.js's JavaScriptcontext - you can type commands and get the result.
这里的Repl代表Read-eval-print-loop,这通常意味着无论您输入什么命令,它都会立即在当前上下文中进行评估,并立即为您提供结果。例如,在控制台Chrome开发者工具是有点儿REPL对于Chrome的执行的JavaScript / DOM,或当您运行node
在终端,你会得到一个REPL对Node.js的的JavaScript方面-你可以输入命令并得到结果。
When you use browser.pause()
you are activating DebuggerRepl. It brings you a Replwhere you can execute commands of this mode. You usually see this list of commands in the terminal:
当您使用时,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
So you can go to the next WebDriver command using c
command or jump to the next browser.pause()
statement in your test using d
command. They are executed right away as you use them. So this mode basically allows you to jump over page statesand explore the result. (Note: this mode provides more commands; they do work, but I'm not sure what is the meaning of their output and if they are useful for a Protractor user at all.)
因此,您可以使用c
command转到下一个 WebDriver 命令,或者使用command 跳转到browser.pause()
测试中的下一个语句d
。当您使用它们时,它们会立即执行。所以这种模式基本上允许你跳过页面状态并探索结果。(注意:此模式提供了更多命令;它们确实有效,但我不确定它们输出的含义是什么,以及它们是否对 Protractor 用户有用。)
When you use browser.enterRepl()
you are activating CommandRepl mode. It allows you to use Protractormethods which you would use in tests, but in an interactive mode. You get access to element
, browser
and protractor
objects, so you could run for example:
当您使用时,browser.enterRepl()
您正在激活CommandRepl 模式。它允许您使用在测试中使用的量角器方法,但在交互模式下。您可以访问element
,browser
和protractor
对象,因此您可以运行例如:
> $('.hello').getText();
> 'World'
It prints you back the result immediately, so it's sort of a sandbox where you can query the DOM on the current page stateand see the results.
它会立即将结果打印回来,因此它类似于一个沙箱,您可以在其中查询当前页面状态的 DOM并查看结果。
As you may have noticed, the browser.pause()
list of commands has a line:
您可能已经注意到,browser.pause()
命令列表中有一行:
type "repl" to enter interactive mode
It means that when you are in DebuggerRepl mode, you can execute the repl
command to activate CommandRepl modefor the current page statewhere you've just run browser.pause()
, so you can play with DOM as if you've just used browser.enterRepl()
. You can go back to DebuggerRepl modeusing the exit
command. But if you've entered to CommandRepl modeusing browser.enterRepl()
, you can't switch to DebuggerRepl mode.
这意味着当您处于DebuggerRepl 模式时,您可以执行repl
命令为您刚刚运行的当前页面状态激活CommandRepl 模式,这样您就可以像刚刚使用 DOM 一样玩 DOM 。您可以使用该命令返回DebuggerRepl 模式。但是,如果你已经进入到CommandRepl模式使用,不能切换到DebuggerRepl模式。browser.pause()
browser.enterRepl()
exit
browser.enterRepl()
Also, CommandRepl modecan be activated with a feature called elementExplorer. It can be used without any written tests; it just opens a URL in CommandRepl mode.
此外,可以使用称为elementExplorer的功能激活CommandRepl 模式。无需任何笔试即可使用;它只是在CommandRepl 模式下打开一个 URL 。
tl;dr
tl;博士
To summarize, I believe that they supposed to be used according to how they are called.
总而言之,我认为应该根据它们的名称来使用它们。
browser.pause()
- I want a browser to pause exactly in that place so I can see what's happening on the page. Then, on my command, I want it to jump to the next state so I can see what is happening here. If I need more information for current state, I can run repl
and use the Protractor API(browser
, element
, protractor
) to investigate. I can then exit
this mode and continue jumping through states.
browser.pause()
- 我希望浏览器正好停在那个地方,这样我就可以看到页面上发生了什么。然后,根据我的命令,我希望它跳转到下一个状态,以便我可以看到这里发生了什么。如果我需要有关当前状态的更多信息,我可以运行repl
并使用Protractor API( browser
, element
, protractor
) 进行调查。然后我可以使用exit
这种模式并继续跳过状态。
browser.enterRepl()
- I want a browser to pause exactly in that place and let me investigate a page using the Protractor API(browser
, element
, protractor
) right away, and I don't need to be able to jump between states of the page.
browser.enterRepl()
- 我希望浏览器正好停在那个地方,让我立即使用量角器 API( browser
, element
, protractor
)调查页面,并且我不需要能够在页面状态之间跳转。
回答by Paulo Merson
Protractor version 5.3 with Node version 8.10 do not supportbrowser.pause()
anymore. More info here.
Protractor 5.3 版和 Node 8.10 版不再支持browser.pause()
。更多信息在这里。
There's a chance you can do what you need with protractor async aswait.
您有机会使用量角器 async aswait做您需要的事情。