18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

suggestion for _wait: stop execution if condition returns false

nickleusnickleus Members
edited March 2014 in Sahi - Open Source
i wish there was an additional "_wait(maxTime, condition)" function that would stop execution if condition returns false.

as of now, it seems as if "wait + condition" continues execution no matter the outcome of "condition", which makes it an "OR" test, but my suggestion would be for an "AND" test, i.e.:
wait, up until maxTime is reached, and if condition is still false, then stop execution.

i want this because of network/server response timing issues, specifically related to ajax operations.

http://sahi.co.in/w/_wait

Comments

  • Hi nickleus

    i got this snippet
    function waitForElement($element, $time) {
      var $waitTime=500;
      var $maxI = $time/$waitTime;
      while (_condition(!(_exists($element)))) {
        _wait($waitTime);
        $maxI--;
        if ($maxI<=0) throw "Waited too long, stopping execution";
      }
    }
    

    which could be modified to
    function waitForSomeThing($condition, $time) {
      var $waitTime=500;
      var $maxI = $time/$waitTime;
      while ($condition()) {
        _wait($waitTime);
        $maxI--;
        if ($maxI<=0) throw "Error";
      }
    }
    
    // which can be used like
    function testSomething($b) {
      return $b;
    }
    waitForSomeThing(testSomething, 10000);
    


    could this help?
Sign In or Register to comment.