Search code examples
javaseleniumselenium-webdriverselenide

Write a monitoring tool with selenium+java


Good day! I have an idea about using selenium as short-time monitoring tool. For example, need to check for an two-three hours about some table values changing.

I've got in mind a cycle "while", where i set up timer how long need to monitor values, and then print them for easy compare.

2016.04.26 | 160789 186491 0.76% 05:28:56

2016.04.26 | 160789 186491 0.76% 05:30:56

But I think there is better, smart solution. But i can't figure out how.

    open(projectUrl);

    int timer = 120;
    int i = 1;
    int iterations = 50;
    
    String var1 = $("cssSelector1").getText();

    while (i<iterations) {
      open(projectUrl);
      var1 = $("cssSelector1").getText();
      if (!$("cssSelector1").getText().equals(var1)) {

         System.out.print(
         var1+"  |  "+
         $("cssSelector2").getText()+"  "+
         $("cssSelector3").getText()+"  "+
         $("cssSelector4").getText()+"  ");
      
         Date dNow = new Date( );
         SimpleDateFormat ft = new SimpleDateFormat ("hh:mm:ss");
         System.out.println(ft.format(dNow));

      }

      sleep(timer*1000);
      i++;

    }

Now it's done, and works like I want. When var1 changes, update var1, then write value. And cycling again. Upper code works fine.


Solution

  • Now it's done, and works like I want. When var1 changes, update var1, then write value. And cycling again. Upper code works fine.