扩展 Selenium:如何调用命令?

发布于 2024-10-18 13:37:46 字数 1017 浏览 1 评论 0原文

我阅读了有关用户扩展扩展 selenium 但我想知道如何从我正在创建的自定义命令中调用命令。

我在 Selenium IDE 选项中向 Selenium 核心扩展 (user-extensions.js) 添加了一个类似于以下内容的文件。

// selenium-action-example.js

Selenium.prototype.doExample = function() {
  this.doOpen("/"); // doesn't waitForPageToLoad like the command does

  // These two commands are equivalent to the clickAndWait command. NOT!
  // For proof, see the filterForRemoteControl function:
  // http://code.google.com/p/selenium/source/browse/trunk/ide/src/extension/content/formats/formatCommandOnlyAdapter.js?r=8284#68
  this.doClick("css=a#example");
  this.doWaitForPageToLoad(); // doesn't wait at all

  this.doClick("link=Example");
  this.doWaitForElementPresent("example"); // error! undefined function
  this.doClick("example");
};

换句话说,我如何在自定义操作中的点击之间等待事件?

I read about user extensions and extending selenium but am wondering how to call a command from within a custom command I'm creating.

I added a file similar to the following to Selenium core extensions (user-extensions.js) in Selenium IDE Options.

// selenium-action-example.js

Selenium.prototype.doExample = function() {
  this.doOpen("/"); // doesn't waitForPageToLoad like the command does

  // These two commands are equivalent to the clickAndWait command. NOT!
  // For proof, see the filterForRemoteControl function:
  // http://code.google.com/p/selenium/source/browse/trunk/ide/src/extension/content/formats/formatCommandOnlyAdapter.js?r=8284#68
  this.doClick("css=a#example");
  this.doWaitForPageToLoad(); // doesn't wait at all

  this.doClick("link=Example");
  this.doWaitForElementPresent("example"); // error! undefined function
  this.doClick("example");
};

In other words, how can I wait for things between clicks within a custom action?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

追风人 2024-10-25 13:37:46

您的命令

this.doWaitForPageToLoad(); // doesn't wait at all

不等待,因为您没有在括号中指定等待时间。您应该将其写为

this.doWaitForPageToLoad(30000); // time in milliseconds

Tour another Command

this.doWaitForElementPresent("example"); // error! undefined function

,因为 Selenium 中没有函数。每当它等待一个元素时,它都会检查该元素是否存在,因此您应该等待时间直到它可见/存在。
使用 For 循环和 ispresent 命令就可以做到这一点。

问候

Your command

this.doWaitForPageToLoad(); // doesn't wait at all

Doesn't wait as you have not specified wait time in brackets. You should write it as

this.doWaitForPageToLoad(30000); // time in milliseconds

Tour another Command

this.doWaitForElementPresent("example"); // error! undefined function

as no function is there in Selenium. whenever it waits for an element it checks that element is present or not so you should wait for time until it is visible/present.
Using For loop and ispresent commands you can do it.

Regards

倦话 2024-10-25 13:37:46

等待页面加载在当前版本的 Selenium 中不起作用。据我所知,这是因为 doWaitForPageToLoad 将等待推迟到当前 Selenium IDE 命令结束,即等待页面加载会停止 test 执行,直到页面加载完毕,但不会执行此函数的实际 javascript 函数的执行。

此时您必须将函数一分为二。

Waiting for an page load does not to work in current versions of Selenium. As far as I can see, this is because the doWaitForPageToLoad defers the waiting until the end of the current Selenium IDE command, i.e. waiting for a page load stops the test execution until the page has loaded, but not the execution of the actual javascript function that this was executed in.

You will have to split your function in two at this point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文