Selenium WebDriverJs commands



我第一次运行Node.js + Mocha + Selenium Webdriverjs的组合。我根据他们的文档在这里https://code.google.com/p/selenium/wiki/WebDriverJs设置一切,但我发现很难通过web驱动程序找到所有可用命令的列表。在使用Selenium webdriverjs编写测试时,是否有可用的命令列表?

例如,我如何使用Javascript实现以下java代码

new Wait("Couldn't find close button!") {
  boolean until() {
    return selenium.isElementPresent("button_Close");
  }
};

我知道我可以使用driver.wait,但它不识别until命令或isElementPresent

我在这里直接查看docs的源文件。它实际上很好:

https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js

回答你的问题,你真的不想在WebDriverJS中等待,你想习惯延迟对象和承诺api。我刚刚在这里写了一篇关于它的博文,应该会对你有所帮助:

http://xolv.io/blog/2013/04/end-to-end-testing-for-web-apps-meteor

我也在查看源代码。他们有一个编译版本的API文档,在这里更容易浏览:

http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver.html

不幸的是,没有只有方法名的摘要。你仍然需要滚动页面。

关于如何等待:

webdriver = require 'selenium-webdriver'
driver = ... // init your driver
driver.wait(webdriver.until...)

@op,最好使用链式语句。我使用until和isElementPresent命令,它们用于生产就绪(CI/CD)训练流程。这样调整代码应该可以工作

var isDisplayed = function(){
        driver.isElementPresent(by.id('button id')).then(function(isDisplayed){
            expect(isDisplayed).to.be.true
        });
    }; 

最新更新