Selenium tests fail in new 1.1.7 webapp

Just starting out in Yii, not entirely sure if the issue is with me. I have been making my way through the AWDWY book and following the create a blog tutorial using 1.1.6. Now I am starting on my own webapp, and upgraded to 1.1.7.

I created a new webapp with Yii 1.1.7 and configured phpunit & selenium how I thought it should be done and ran phpunit functional/SiteTest.php to make sure all was good. It stops when trying to save a post without a body - even though "Body cannot be blank." does appear in the browser. Eventually the test times out (the browser does open and go to the right pages). I check and rechecked the settings and they seem ok.

After spending several hours checking settings, googling I finally gave up and created another webapp using 1.1.6. I configured phpunit & selenium exactly the same way and the tests pass without stumbling. Is this a know problem? Both instances are using freshly generated webapps.

System:

Ubuntu 10.10

PHP:

PHP 5.3.3-1ubuntu9.3 with Suhosin-Patch (cli) (built: Jan 12 2011 16:07:38)

Copyright © 1997-2009 The PHP Group

Zend Engine v2.3.0, Copyright © 1998-2010 Zend Technologies

with Xdebug v2.1.2dev, Copyright (c) 2002-2011, by Derick Rethans

Firefox 4

Yii 1.1.6 - tests pass

Yii 1.1.7 - tests fail

bootstrap.php (1.1.7):


<?php


// change the following paths if necessary

$yiit=dirname(__FILE__).'/../../../../yii-117/framework/yiit.php';

$config=dirname(__FILE__).'/../config/test.php';


require_once($yiit);

require_once(dirname(__FILE__).'/WebTestCase.php');


Yii::createWebApplication($config);

bootstrap.php (1.1.6):


<?php


// change the following paths if necessary

$yiit=dirname(__FILE__).'/../../../../yii-116/framework/yiit.php';

$config=dirname(__FILE__).'/../config/test.php';


require_once($yiit);

require_once(dirname(__FILE__).'/WebTestCase.php');


Yii::createWebApplication($config);



WebTestCase.php:


<?php


/**

 * Change the following URL based on your server configuration

 * Make sure the URL ends with a slash so that we can use relative URLs in test cases

 */

define('TEST_BASE_URL','');


/**

 * The base class for functional test cases.

 * In this class, we set the base URL for the test application.

 * We also provide some common methods to be used by concrete test classes.

 */

class WebTestCase extends CWebTestCase

{

        /**

         * Sets up before each test method runs.

         * This mainly sets the base URL for the test application.

         */

        protected function setUp()

        {

                parent::setUp();

                $this->setBrowserUrl(TEST_BASE_URL);

        }

}

phpunit.xml:


<phpunit bootstrap="bootstrap.php"

                colors="false"

                convertErrorsToExceptions="true"

                convertNoticesToExceptions="true"

                convertWarningsToExceptions="true"

                stopOnFailure="false">


        <selenium>

<!--            <browser name="Internet Explorer" browser="*iexplore" /> -->

                <browser name="Firefox" browser="*custom /usr/lib/firefox-4.0/firefox.sh -p Selenium" />

        </selenium>


</phpunit>

(as this is my first post, I cannot put a url in here, but there is a correct URL in WebTestCase.php)

Is anyone else having the same issue with 1.1.7?

Or should I spend more time trying to figure out why 1.1.6 works and 1.1.7 doesn’t using exactly the same phpunit/selenium setup on my two systems?

I don’t want to start using 1.1.7 if it means I am unable to be sure that the test pass/fail is not suspect.

I was running Yii 1.1.7 on Windows XP/Apache2/PHP5.3 and had the same issues. I followed your advice and downgraded to Yii 1.1.6. It seemed to fix the issue.

If you think it’s a bug, please open a bug report http://code.google.com/p/yii/issues/list

I was asking here in case it was something I had done wrong (I always assume it’s me first!) I will post a report there as well as here. Thanks for the link, wasn’t aware of it before (had to snip off URL as I couldn’t post with it still there).

Have added bug report here: http://bit.ly/hEJ1gA

I too had the same problem as described.

I followed your diections, downgraded to 1.1.6, generated a fresh webapp, executed phpunit functional\sitetest.php on my windows xp box and worked like a champ.

1.1.7 however is broken in the same manor as he describes above.

Windows XP SP3

Apache 2.2

PHP 5.3.6

1.1.7 Is Broken [SiteTest.php Fails with PHPUnit & Selenium]

1.1.6 Works perfectly as intended, against same PHPUnit & Selenium on same box, same etc…

Hi just wanted to mention having the same problem with 1.1.7 and the failing tests.

Where:

$this->clickAndWait("//input[@value=‘Submit’]");

That instruct selenium to wait for a page reload that doesn’t happen and the function timeouts failing the test

This is due to the fact that the validation is done in js (without reload). I have found and old note regarding rails [@ codelevy.com/2007/11/05/selenium-and-ajax-requests] that explains the problem and a possible solution/work around, but not being familiar with Yii or Selenium it will take me a while to figure out where to put the pieces.

Will appreciate any suggestions ;)

Sergio

"Be kind whenever possible. It is always possible" - 14th DL

I can confirm that this is an issue in the current version of Yii. I’m using MAMP 1.95 and the latest versions of Pear, PHPUnit, and Selenium (2.0b3). It appears that the first test passes, but the other two fail (at the clickandwait part).

Hi guys,

Just to let you know that I’m running into the same issue.

Any fix/workaround yet ?

Khad

Disable javascript validation or use 1.1.6 ::)

Thanks I’ll try disabling JS.

Disabling javascript validation worked for me.

See reply I made in the book forum re: a workaround. URL at:

http://www.yiiframework.com/forum/index.php?/topic/11920-identified-issues/page__view__findpost__p__97613

Another, (I think) better approach other than the one with disabling client side validation (why would you do that? since Selenium should be built to test anything (including JS validation)):

  1. If you enabled nice URLs make sure you change the way the contact page gets called (you can use something similar to the way login gets called:

clickAndWait('link=Contact')

);

  1. Change

clickAndWait()

to


click()

on the login and submit buttons respectively (don’t change the


clickAndWait()

that is supposed to log you in though, only change the one that is supposed to throw a validation error);

  1. You can use the PHP function

sleep()

to delay some parts of the execution to gain a better perspective over what gets called and when.

I still had problems with IE9 throwing weird script errors when Selenium opened it, didn’t struggle to fix this yet, Chrome and FF4 work like a charm under x64 Se7en.

I hope I got everything you have to do because I struggled a bit with it and tried multiple things

Thanks to Paul I got this to work. I simple added sleep(5); before the two tests that failed.

Namely

$this->assertTextPresent(‘Body cannot be blank.’);

and

$this->assertTextPresent(‘Password cannot be blank.’);

and I get all tests passing.

Were these failing in 1.1.8?

I can confirm these two tests fail under 1.1.8:

            &#036;this-&gt;assertTextPresent('Body cannot be blank.') and 


            &#036;this-&gt;assertTextPresent('Password cannot be blank.');

I’m using the latest selenium-server-standalone-2.3.0.jar

Adding:


 sleep(1); 

before each of the failing assertTextPresent commands fixes the failing tests.

code.google.com/p/yii/issues/detail?id=2335 may be related to this.