Actually, every time deleted the item and also clicked the next page, the table will reload again. every time the table load, the page will send the request to the server for the data. The difficulty is that the XPath of HTML Table is same and I can not use Wait to check if the table is loaded. Also, Thread. Sleep is not a good choice for test automation because it will make the testing slow down.
After I check the network of Chrome and I fond that once the table loaded, the response code is 200 and the request URL contains "getMultipleServiceListing", So I use another way to guarantee a load of table---Lightbody: BrowserMobProxy.
System.setProperty( "webdriver.chrome.driver", ConfigReader.getChromePath() );//****************************proxy = new BrowserMobProxyServer();proxy.start();// get the Selenium proxy objectseleniumProxy = ClientUtil.createSeleniumProxy( proxy );// configure it as a desired capabilitycapabilities = new DesiredCapabilities();capabilities.setCapability( CapabilityType.PROXY, seleniumProxy );// start the browser updriver = new ChromeDriver( capabilities );// enable more detailed HAR capture, if desired (see CaptureType for the complete list)proxy.enableHarCaptureTypes( CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT );
//initial Harpublic static void MonitorResponseStart() throws InterruptedException { //Initialize Har proxy.newHar( BrowserFactory.driver.getCurrentUrl() ); har = proxy.getHar(); //Must use the sleep to wait for Har to initialize, or there may be error. Thread.sleep( 500 );} //Check request url and response statusprivate static boolean CheckStatus(Har har,String subUrl,int statuCode) { //get entriesList List<HarEntry> entriesList = har.getLog().getEntries(); //loop to check for (HarEntry harEntry : entriesList) { if ((harEntry.getRequest().getUrl().contains( subUrl )) && (harEntry.getResponse().getStatus() == statuCode)) { BaseClass.testLog.log( Status.INFO, "Table reloaded done ! " ); return true; } } return false;} //It is used to make sure that the table are loaded completelypublic static void MMonitorResponseEnd(String subUrl,int statuCode) throws IOException, InterruptedException { //if check status fail, wait and keep checking. while (!CheckStatus( har,subUrl,statuCode)) { Thread.sleep( 200 ); } //write har to file, this step can be delete, just used for debugging.... har.writeTo( new File( "har.json" ) );}