Как вызвать функцию JavaScript из Selenium RC с помощью Java - PullRequest
1 голос
/ 25 января 2012

У меня есть user-extensions.js, который содержит следующий код:

Selenium.prototype.doTypeRepeated = function(locator, text) {
    // All locator-strategies are automatically handled by "findElement"
    var element = this.page().findElement(locator);

    // Create the text to type
    var valueToType = text + text;

        // Replace the element text with the new text
    this.page().replaceText(element, valueToType);
};

Я хочу вызвать эту функцию из кода Java, используя Selenium RC для текстового поля ("css = input.text«).Как я могу это назвать?

1 Ответ

1 голос
/ 25 января 2012

Сверху моей головы вы сможете назвать свой код следующим образом:

selenium.getEval("Selenium.prototype.doTypeRepeated('input.text', 'some text');");

Однако, если после предложенного подхода вы должны сделать как

HttpCommandProcessor proc;
proc = new HttpCommandProcessor("localhost", 4444, "*iexplore", "http://google.com/");
Selenium selenium = new DefaultSelenium(proc);
string[] inputParams = {"css=input.text", "Hello World"};
proc.DoCommand("doTypeRepeated", inputParams);

И не забудьте запустить селен как

java -jar selenium-server.jar -userExtensions user-extensions.js
...