[Logo] Enterprise Client Community
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Checking page status during Selenium tests  XML
Forum Index -> Development
Author Message
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

(from mail conversation)

...The problem that we often see while running automatic tests, is that clicks or text is ignored. ...that it is probably because roundtrips are executed...

How to find out the status of the client?

Björn Müller, CaptainCasa GmbH
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

Maybe this does not fully match your question:

There is a counter that is reachable by DOM-Element-investigastion that is incremented after a communication. So if you start some server-side activity then pick the current counter and wait for it to be incremented.

The counter is kept in a DIV-element with attribute "data-riscclientname" set to value "riscform_outest", the counter is kept in attribute "data-riscclientcounter".

In Selenium you can access by:

Code:
     private static int getCurrentResponseCounter(WebDriver driver)
     {
         WebElement formOutest = driver.findElement(By.cssSelector("div[data-riscclientname='riscform_outest']"));
         String text = formOutest.getAttribute("data-riscclientcounter");
         return Integer.valueOf(text);
     }
 


Hope this is at least covering some aspects of your question...

Björn Müller, CaptainCasa GmbH
wwillemsens

Power User

Joined: 14/11/2016 18:05:48
Messages: 32
Offline

Hi Bjorn,
I refactored my tests like you said in this thread, and overall this worked good.
I wait until the counter is increased by 1 and then I continue. If the counter is not increased in 3 seconds, then I also go further.
The only disadvantage is that also a lot of actions does not increase the counter, so my test duration is now much longer. > 9 hours (coming from 2)
If you have some fine tune ideas? Can we know somehow which actions trigger the counter?

Kind regards
Wim
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

...well, yes, if you in general wait for "counter-increased || 3 seconds gone" with every user action, then this does not accelerate the tests. ;-) - Only apply this, if the system is really expected to trigger a server update.

I currently (system as is) cannot offer a better possibility, but we can add some additional flag in a Selenium-read-able way to check, if communication is currently going on... It's just timing: not sure if we make it this or next week... We added it to our TODOs for "after community meeting".

Kind regards! Björn

Björn Müller, CaptainCasa GmbH
wwillemsens

Power User

Joined: 14/11/2016 18:05:48
Messages: 32
Offline

That would be great!
wwillemsens

Power User

Joined: 14/11/2016 18:05:48
Messages: 32
Offline

Hi Bjorn,
Any news on this?

Kind regards Wim
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

Uuuh,

sorry for not picking up this item for long time...!

We just published Maven version 20230919_INT1 which contains the corresponding change. There is now a value "data-riscclientcommunicatingtoserver" in the page that indicates if communication is going on.

Below there is some program that shows how to use it. The central method is "waitForResponse". This one checks...

...did the response counter change? If yes: then there was a communication to the server! (Maybe the communication did already happen when Selenium checks the comm. status!)

...is there any communication ongoing? This is the place where the new field is used.

...is some timeout timer reached?

Kind regards! Björn

Code:
 package testselenium1;
 
 import java.time.Duration;
 
 import org.openqa.selenium.By;
 import org.openqa.selenium.Dimension;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 import org.openqa.selenium.support.ui.WebDriverWait;
 
 public class Test1
 {
     static int s_compareCounter = -1;
     final static long DEFAULT_REQUEST_WAITINGTIME = 10000;
 
     public static void main(String[] args)
     {
         WebDriver driver = null;
         try
         {
             System.setProperty("webdriver.chrome.driver", "C:\\bmu_jtc\\selenium\\chrome117\\chromedriver.exe");
             driver = new ChromeDriver();
             driver.manage().window().setSize(new Dimension(1024, 768));
             driver.get("http://localhost:8080/demos/workplace.demominispread.risc");
             WebDriverWait waiter = new WebDriverWait(driver,Duration.ofMillis(30));
             waiter.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[data-riscclientname='riscform_outest']")));
             waitAfterLoadPage();
             for (int j=0; j<3; j++)
             {
                 WebElement addButton = driver.findElement(By.cssSelector("div[data-riscclientname='ADDITEM']"));
                 for (int i=0; i<5; i++)
                 {
                     prepareRequest(driver);
                     addButton.click();
                     waitForResponse(driver);
                 }
                 WebElement field = driver.findElement(By.cssSelector("input[data-riscclientname='REGION_0_field']"));
                 WebElement removeButton = driver.findElement(By.cssSelector("div[data-riscclientname='REMOVEITEMS']"));
                 for (int i=0; i<5; i++)
                 {
                     prepareRequest(driver);
                     field.click();
                     removeButton.click();
                     waitForResponse(driver);
                 }
             }
         }
         catch (Throwable t)
         {
             t.printStackTrace();
         }
         finally 
         {
             try { driver.close(); } catch (Throwable t) {}
             try { driver.quit(); } catch (Throwable t) {}
         }
     }
 
     private static void prepareRequest(WebDriver driver)
     {
         s_compareCounter = getCurrentResponseCounter(driver);
     }
     
     private static void waitForResponse(WebDriver driver)
     {
         waitForResponse(driver,DEFAULT_REQUEST_WAITINGTIME);
     }
     
     private static void waitAfterLoadPage()
     {
         try { Thread.sleep(2000); } catch (Throwable t) {}
     }
     
     private static void waitForResponse(WebDriver driver, long maxDuration)
     {
         System.out.print("Waiting for response: "+s_compareCounter + "\n");
         long start = System.currentTimeMillis();
         while (true)
         {
             try { Thread.sleep(50); } catch (Throwable t) {}
             long now = System.currentTimeMillis();
             if (now - start > maxDuration) 
             {
                 System.out.println("");
                 throw new Error("Time out - wating for response");
             }
             int currentResponseCounter = getCurrentResponseCounter(driver);
             if (currentResponseCounter != s_compareCounter)
             {
                 System.out.println("");
                 return;
             }
             if (checkIfCommunicatingToServer(driver) == false)
             {
                 return;
             }
             System.out.print(".");
         }
     }
     
     private static boolean checkIfCommunicatingToServer(WebDriver driver)
     {
         WebElement formOutest = driver.findElement(By.cssSelector("div[data-riscclientname='riscform_outest']"));
         String text = formOutest.getAttribute("data-riscclientcommunicatingtoserver");
         if ("true".equals(text))
             return true;
         else
             return false;
     }
 
     private static int getCurrentResponseCounter(WebDriver driver)
     {
         WebElement formOutest = driver.findElement(By.cssSelector("div[data-riscclientname='riscform_outest']"));
         String text = formOutest.getAttribute("data-riscclientcounter");
         return Integer.valueOf(text);
     }
 
 }
 

Björn Müller, CaptainCasa GmbH
wwillemsens

Power User

Joined: 14/11/2016 18:05:48
Messages: 32
Offline

Using this for a few days now, and this work great!
Thank you
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

...perrrfect! Thanks for your feedback! - Björn

Björn Müller, CaptainCasa GmbH
 
Forum Index -> Development
Go to:   
Powered by JForum 2.1.6 © JForum Team