开发者

Extending Selenium: How to call commands?

开发者 https://www.devze.com 2023-02-11 06:05 出处:网络
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 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 functio开发者_运维百科n
  this.doClick("example");
};

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号