Extending Selenium: How to call commands?

2019-06-21 08:31发布

问题:

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?

回答1:

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



回答2:

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.