简体   繁体   中英

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.

var1..4需要在while循环中设置,否则它们只会在每次迭代时继续打印相同的数据

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM