views:

25

answers:

1

I need to run a javascript function from a phpunit test with selenium and check the javascript returns true. I've looked into using runScript but it never seems to run (I've tested this by adding an alert to the code, but it never shows..).

My javascript needs to check the opacity of an element is 1, if not use setTimeout to run the function again. - What this code is basically trying to do is ensure an ajax call has been called (the element to be replaced goes to half opacity when being updated and back to full when updated)

Is runScript the correct function, or is there a better way to check the ajax has run? Here's the JS:

function seleniumCheckOpacity(elementId, counter) {
    if(counter >= 5) return false;
    else if($(elementId).opacity == 1) return true;
    else {
        counter++
        return setTimeout('seleniumCheckOpacity('+elemelementId+', '+counter+')', 500);
    }
}
+1  A: 

I would suggest using waitForCondition and use the javascript you want to check on the opacity. This waitForX command will do the looping for you and then error if it fails or the test will carry on if it succeeds.

AutomatedTester
Docs says it all, in big red letters. http://wiki.openqa.org/display/SEL/waitForCondition
Ashley