How should I write functional tests for Yii web application that will be run on selenium server?

I am currently setting up a development environment for my new project and I am thinking hard about one thing. I plan on using Yii. I want to have functional tests automated, I already have gerrit and Jenkins in place, working.

I read this note and found out that selenium has something like html suite. I never heard of it before, I always wrote my tests to be run via PHPUnit. I used default Yii functional tests environment as described here.

So my question is, what are pros and cons of both approaches? I already can think of one pro and con of html suite. Pro is, that writing tests is really easy - you just "click" them in Selenium IDE. The con is, that I probably would have to run db fixtures before testing and I couldn't change them, or run them like - load fixtures, run test, load fixture, run test, but I guess that would be make the tests much sloppier. What do you think/what is your experience in that matter?

Answers


there is an easy way to write functional tests. you can downlaod an addon for selenium IDE and then add the php formatter for this addon, and you can make and export functional tests very eeeasy.

then you should configure your protected/config/test.php and protected/tests/bootstrap.php

you should probably edit protected/tests/phpunit.xml and remove any browser, other than fire fox.

then do like Willem Renzema said and change the test made by this addon and change the name of the class to WebTestCase and remove the setUp()

then you are ready to run tests!

cheers


The two packages that are well integrated with Yii, is PhPUnit and Selenium Remote Control. So these two are more common between Yii developers.

Regarding, deploying functional test, I'm not sure how deep you want to go, but as far as I used it, it was pretty easy. Functional tests, are literally php classes, which are extended from CWebTestCase. Yii CWebTestCase class description

Naming convention is you have to name you class ending with Test like ExampleTest.php, and store the files under protected/tests/functional. You need to set up everything including, both packages and also changing Yii configuration file and your default browser. If everything goes well, a sample test can be like this:

class ExampleTest extends WebTestCase
{

public function testContact()
{
    $this->open('?r=site/contact');
    $this->assertTextPresent('A string on contact page');
    $this->assertElementPresent('name=ContactForm[name]');
    $this->type('name=ContactForm[name]','tester');
    $this->type('name=ContactForm[email]','tester@example.com');
    $this->type('name=ContactForm[subject]','test subject');
    $this->click("//input[@value='Submit']");
    $this->waitForTextPresent('Body cannot be blank.');
}
}

That's all I knew about it and I hope it helped.


Need Your Help

C++ - Why is boost::hash_combine the best way to combine hash-values?

c++ c++11 boost hash

I've read in other posts that this seems to be the best way to combine hash-values. Could somebody please break this down and explain why this is the best way to do it?

How can I get Git to truly *ignore* line endings?

git tfs line-endings git-tf

How can I tell Git to truly not care about line endings? To leave them as LF or CRLF, as they originally were, and check them in the same way?