How to suppress FuncUnit unit errors in tests?

130 Views Asked by At

I have a FuncUnit test case wherein I open a webpage using

F.open("http://www.example.com");

There is a known issue in our page that approximately one in around 20 times the webpage would not load for whatever reason. I want to retry when it does not load. But in FuncUnit there is no way to suppress error if it fails to load the page. Is there a way to suppress error message in Funcunit?

2

There are 2 best solutions below

0
On
var url = "http://www.example.com"
F.get(url, function(data){
    console.log("Made an ajax call to make sure that F.open is always second call");
})
// Wait for few seconds before making the actual F.open
F.wait(5000,function(){
   F.open(url);
})

Whenever F.open fails ( i.e during one out of 20 times) I noticed that the second test point that uses F.open passes.However I cannot do F.open again in case the first one does not work as there is no way to suppress F.open error when the page does not load.

So I always make a simple ajax call before making the actual F.open. This is not the right way to do it but it works for us as we don't actually care whether the page is a first/second time load in our tests.

1
On

Couldn't something like this work for you?

module("test", {
  setup: function() {
    let startMeUp = () => F.open('http://www.example.com'); // unfortunately doesn't return a usable value
    let checkCondition = () => {
      // grab F(F.window), and check for a known element in the page
      return elementFound;
    };
    while(!checkCondition()) {
      // element wasn't found, so let's try it again
      startMeUp();
      // maybe set a wait here
    }
  }
});