Ruby on rails 3 如何让Selenium更好地使用引导模式?

Ruby on rails 3 如何让Selenium更好地使用引导模式?,ruby-on-rails-3,selenium,twitter-bootstrap,cucumber,Ruby On Rails 3,Selenium,Twitter Bootstrap,Cucumber,我正努力以BDD的方式生活。我正在使用Cucumber(含Selenium)并在我的应用程序中使用Twitter引导模式 在运行Cucumber测试时,我遇到了一个“Selenium::WebDriver::Error::MoveTargetOutOfBoundsError”错误。经过大量的搜索、调试和绝望之后,我得出结论,这与在我的引导模式中使用“fade”参数有关。如果我使用“淡入淡出”,则会抛出错误: <div class="modal hide fade" id="info-sha

我正努力以BDD的方式生活。我正在使用Cucumber(含Selenium)并在我的应用程序中使用Twitter引导模式

在运行Cucumber测试时,我遇到了一个
“Selenium::WebDriver::Error::MoveTargetOutOfBoundsError”
错误。经过大量的搜索、调试和绝望之后,我得出结论,这与在我的引导模式中使用
“fade”
参数有关。如果我使用“淡入淡出”,则会抛出错误:

<div class="modal hide fade" id="info-share-edit-modal" style="display: none;">
  .
  .
  .
</div>
因此,我现在从我的各种模态中删除
“fade”
。但是,这让我很难过,因为我喜欢淡入淡出的效果

是否有其他人在使用Selenium和淡入引导模式时遇到过问题?如果是这样的话,有没有什么聪明的方法可以让这两个人很好地合作


顺便说一句(不确定这是否重要),我是Rails 3.2.3、Firefox 13.0.1和Ubuntu12.04LTS。

加入一个标志,这样在测试环境中它不会褪色,但在其他环境中它会褪色。

我做了一个快速测试,插入一个WebDriverWait,查看模式的不透明度。这似乎有效,但时间会证明这是一个间歇性问题(至少对我来说)。这是我的Java实现

//Ensure the modal is done animating
new WebDriverWait(driver, 5).until(
    new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver webDriver) {         
            return webDriver.findElement(By.id("videoModal")).getCssValue("opacity").equals("1");
        }
    }
);
//确保模式已完成动画制作
新WebDriverWait(驱动程序,5)。直到(
新的ExpectedCondition(){
@凌驾
公共布尔应用(WebDriver WebDriver){
返回webDriver.findElement(By.id(“videoModal”).getCssValue(“不透明”).equals(“1”);
}
}
);

在selenium测试用例中,当应用程序打开引导模式时,添加一个暂停命令,要求selenium在与模式内容交互之前暂停一秒钟:

Command: pause /
Target: 1000 /
Value: (leave empty)
我是这样解决的(用c#)。它速度很快,一次也没有失败

public static void WaitForModal(this RemoteWebDriver driver)
{
    using (driver.NoImplicitWait())
    {
        var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
        wait.Until(d => d.FindElements(By.ClassName("modal-backdrop").Count == 0);
    }
}
NoImplicitWait用于临时禁用驱动程序隐式等待

public static NoImplicitWait NoImplicitWait(this IWebDriver driver)
{
    return new NoImplicitWait(driver);
}

public sealed class NoImplicitWait : IDisposable
{
    private readonly IWebDriver _driver;

    public NoImplicitWait(IWebDriver driver)
    {
        _driver = driver;
        _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0));
    }

    public void Dispose()
    {
        _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
    }
}
c#代码

我也遇到了同样的问题,这段代码从2个多月以来一直在为我工作,不再崩溃

 public static void WaitForModal(this IWebDriver driver)
    {
        wait.Until<IWebDriver>((d) =>
        {
            if (driver.FindElements(By.ClassName("modal-backdrop")).Count == 0)
            {
                return driver;
            }
            return null;
        });
    }
publicstaticvoidwaitformodal(此IWebDriver)
{
等待。直到((d)=>
{
if(driver.FindElements(By.ClassName(“模态背景”)).Count==0)
{
返回驱动器;
}
返回null;
});
}

它会一直等待,直到它发现不再有
IWebElement
具有
的“模态背景”。

改进了user1965252的答案,这对我有效。只需将模态id替换为模态div id即可

new WebDriverWait(driver, TIME_OUT_IN_SECONDS).until(and(
        new ExpectedCondition<Boolean>() {
           @Override
           public Boolean apply(WebDriver webDriver) {
               return webDriver.findElement(id("the-modal-id"))
                       .getCssValue("opacity").equals("0");
           }
        },
        numberOfElementsToBe(cssSelector("div.modal-backdrop"), 0)
));
新的WebDriverWait(驱动程序,超时,以秒为单位)。直到(和(
新的ExpectedCondition(){
@凌驾
公共布尔应用(WebDriver WebDriver){
返回webDriver.findElement(id(“模式id”))
.getCssValue(“不透明度”)。等于(“0”);
}
},
元件编号STOBE(cssSelector(“div.model-background”),0)
));

我通常会针对一些应该在模式上可见(或在淡出时不可见)的内容进行断言:

重要的是要使用
。有无内容
和不
。没有内容
,因为
有无内容
会等待一段时间,事情才会发生

必要时,您还可以检查模式CSS选择器。当模态可见时,引导在类中添加一个

expect(page).to have_selector('.modal.in')
expect(page).to have_no_selector('.modal.in')

我遇到了同样的错误,使用了《基础ZURB》中的<代码> Real.js<代码>,感谢您的建议,我通过删除<代码>淡出>代码>动画来工作。但我没有找到真正的解决办法。很想听听其他人是如何解决这个问题的。这个错误到底是什么时候发生的?对于Chrome驱动程序来说,这表明你是对的。在这么多的话,它说,一个元素必须停止动画之前,你可以点击它。
expect(page).to have_content('My Modal Header')
expect(page).to have_no_content('My Modal Header')
expect(page).to have_selector('.modal.in')
expect(page).to have_no_selector('.modal.in')