如何使用Cucumber来测试加载了javascript的内容

时间:2021-08-23 23:15:10

I've been developing a Rails application and I've decided to implement a mixture of Test Driven Development and Behavioral Driven Development.

我一直在开发一个Rails应用程序,我决定将测试驱动开发和行为驱动开发结合起来。

However the application I am building uses a web application user interface framework known as MochaUI which is built on top of the Mootools framework.

然而,我正在构建的应用程序使用一个名为MochaUI的web应用程序用户界面框架,该框架构建在Mootools框架之上。

I have just finished writing a portion of unit tests and have moved on to testing the user interface; which is where I start to run into problems.

我刚刚完成了单元测试的一部分,并开始测试用户界面;这就是我遇到问题的地方。

A lot of the things I want to test is content that is loaded via javascript, some data is loaded into iframes, some data is loaded into elements (ajax).

我想测试的很多内容是通过javascript加载的内容,一些数据被加载到iframe中,一些数据被加载到元素中(ajax)。

So I wrote a test

所以我写了一个测试

And I should see "Some text loaded into an iframe with javascript"

And as you guessed, it failed. I don't know where to begin to fix this problem, as I am very new to TDD and BDD but I'm working my way there, can anyone give me some pointers or possibly a solution so I can sleep at night?

正如你所料,它失败了。我不知道该从哪里开始解决这个问题,因为我对TDD和BDD非常陌生,但是我正在努力解决这个问题,谁能给我一些建议或者一个可能的解决方案,让我可以在晚上睡觉吗?

Thanks!

谢谢!

2 个解决方案

#1


2  

There is selenium for javascript-testing... Maybe this would be a tip?

还有用于javascript测试的selenium……也许这是一个提示?

see http://github.com/aslakhellesoy/cucumber/wiki/Setting-up-Selenium

参见http://github.com/aslakhellesoy/cucumber/wiki/Setting-up-Selenium

or

http://bddcasts.com/series/tools/episodes/using-selenium-with-webrat-and-cucumber

http://bddcasts.com/series/tools/episodes/using-selenium-with-webrat-and-cucumber

#2


1  

Use capybara, tagging the scenarios that require javascript with @javascript.

使用capybara,用@javascript标记需要javascript的场景。

#1


2  

There is selenium for javascript-testing... Maybe this would be a tip?

还有用于javascript测试的selenium……也许这是一个提示?

see http://github.com/aslakhellesoy/cucumber/wiki/Setting-up-Selenium

参见http://github.com/aslakhellesoy/cucumber/wiki/Setting-up-Selenium

or

http://bddcasts.com/series/tools/episodes/using-selenium-with-webrat-and-cucumber

http://bddcasts.com/series/tools/episodes/using-selenium-with-webrat-and-cucumber

#2


1  

Use capybara, tagging the scenarios that require javascript with @javascript.

使用capybara,用@javascript标记需要javascript的场景。