54

有没有办法慢慢运行使用量角器编写的 Angular E2E 测试,以便我可以看到正在发生的事情?

4

5 回答 5

81

以下是我的解决方案。所以基本上我为当前的控制流execute函数创建了一个装饰器,它现在在每个排队的操作之前额外排队了 100 毫秒的延迟。

这需要在调用任何测试之前运行(外部describe块)

var origFn = browser.driver.controlFlow().execute;

browser.driver.controlFlow().execute = function() {
  var args = arguments;

  // queue 100ms wait
  origFn.call(browser.driver.controlFlow(), function() {
    return protractor.promise.delayed(100);
  });

  return origFn.apply(browser.driver.controlFlow(), args);
};
于 2014-12-15T12:20:29.213 回答
13

就像 George Stocker 在评论中所说的那样,我不知道您为什么要这样做……但是您始终可以在测试中的任何位置添加睡眠。

browser.sleep(6000);
于 2014-07-25T16:36:17.030 回答
12

以前的答案看起来更像是解决方法。另一种方法是将参数添加到 Protractor 配置中:

highlightDelay: 1000

并更改为:

directConnect: false

它将延迟量角器操作,例如单击或键入 1 秒,并以浅蓝色突出显示。

于 2019-01-17T14:31:32.957 回答
11

您可以通过在代码中输入以下命令进入“调试模式”:

browser.pause();

在调试模式下,您会在终端中看到以下输出:

------- WebDriver Debugger -------
ready

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
  • 通过输入继续下一个调试器语句 (next browser.pause())d
  • 进入交互模式,您可以通过输入与所有元素进行交互repl
于 2015-05-04T08:46:30.130 回答
0

执行此操作的 2 种方法

1.首先是很幼稚的方式,但我会留在这里

您可以突出显示您正在与之交互的元素!

highlightElement: async ($elementObject, time = 1000) => {
        async function setStyle(element, style) {
            const previous = await element.getAttribute('style');
            await element.setAttribute('style', style);
            await setTimeout(() => {
                element.setAttribute('style', previous);
            }, time);
        }
        await browser.sleep(time)
        return await browser.executeScript(await setStyle, $elementObject.getWebElement(), 'color: red; background-color: yellow; z-index: 9999;');
    },

这将突出显示该元素一秒钟

然后使用此元素包装您的操作

let click = async function ($elem) {
  await highlightElement($elem);
  await $elem.click();
}

let sendKeys = async function ($elem, text) {
  await highlightElement($elem);
  await $elem.sendKeys(text);
}

然后用它来尝试一些脚本

await sendKeys($login, username);
await sendKeys($password, password);
await click($submit);

这不应该真正用在真正的脚本中,只有在你玩它的时候

2. 在代码编辑器中设置调试配置

vs 代码示例https://medium.com/@ganeshsirsi/how-to-debug-protractor-tests-in-visual-studio-code-e945fc971a74,但同样的事情可以在 webstorm 中实现

这将允许您逐行执行代码并与变量实时交互。每个使用量角器的人都必须拥有。我是认真的

于 2021-02-09T01:04:10.480 回答