All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ui.auto.core.utils.AjaxTriggeredAction Maven / Gradle / Ivy

There is a newer version: 1.7.1
Show newest version
/*
Copyright 2010-2012 Michael Braiman

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package ui.auto.core.utils;

import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;

import ui.auto.core.pagecomponent.PageComponent;

/**
 * @author Michael Braiman [email protected]
 * 			

* This is utility to handle Ajax loaded components */ public abstract class AjaxTriggeredAction { public abstract void doAction(); /** * * @param affectedElement * @param time_out */ public void waitForAjax(PageComponent affectedElement,long time_out){ waitForAjax(affectedElement, time_out,true); } /** * * @param affectedElement * @param time_out * @param throwException */ public void waitForAjax(PageComponent affectedElement,long time_out,boolean throwException){ waitForAjax(this, affectedElement, time_out,throwException); } /** * * @param action * @param affectedElement * @param time_out */ public static void waitForAjax(AjaxTriggeredAction action, PageComponent affectedElement,long time_out){ waitForAjax(action, affectedElement, time_out, true); } /** * This method will wait for Ajax event to complete redrawing the DOM. * The idea behind this method is: first to trigger an action which will cause Ajax event and then to wait until affected * by Ajax element become stale. this means that affected element loses his handler as Ajax renders portion of the DOM * where affected element resides. * * @param action action to perform which will trigger Ajax event * @param affectedComponent affected by Ajax component * @param time_out maximum time to wait until component is affected by Ajax * @param throwException if true will throw exception if Ajax event is not detected */ public static void waitForAjax(AjaxTriggeredAction action, PageComponent affectedComponent,long time_out,boolean throwException){ long to=System.currentTimeMillis()+time_out; WebElement coreElement=affectedComponent.getCoreElement(); action.doAction(); do { try { coreElement.isDisplayed(); //This should trigger exception if element is detached from DOM } catch (StaleElementReferenceException e){ return; } } while (System.currentTimeMillis()





© 2015 - 2025 Weber Informatics LLC | Privacy Policy