Best Carina code snippet using com.qaprosoft.carina.core.foundation.performance.ACTION_NAME
Source:AbstractUIObjectListHandler.java  
...35import org.openqa.selenium.support.ui.ExpectedCondition;36import org.openqa.selenium.support.ui.ExpectedConditions;37import org.openqa.selenium.support.ui.Wait;38import org.openqa.selenium.support.ui.WebDriverWait;39import com.qaprosoft.carina.core.foundation.performance.ACTION_NAME;40import com.qaprosoft.carina.core.foundation.performance.Timer;41import com.qaprosoft.carina.core.foundation.utils.Configuration;42import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;43import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedFieldDecorator;44import com.qaprosoft.carina.core.gui.AbstractUIObject;45public class AbstractUIObjectListHandler<T extends AbstractUIObject> implements InvocationHandler {46    private Class<?> clazz;47    private WebDriver webDriver;48    private final ElementLocator locator;49    private String name;50    private By locatorBy;51    private Logger LOGGER = Logger.getLogger(ExtendedFieldDecorator.class);52    public AbstractUIObjectListHandler(Class<?> clazz, WebDriver webDriver, ElementLocator locator, String name) {53        this.clazz = clazz;54        this.webDriver = webDriver;55        this.locator = locator;56        this.name = name;57        this.locatorBy = getLocatorBy(locator);58    }59    @SuppressWarnings("unchecked")60    public Object invoke(Object object, Method method, Object[] objects) throws Throwable {61    	62		// Hotfix for huge and expected regression in carina: we lost managed63		// time delays with lists manipulations64		// Temporary we are going to restore explicit waiter here with hardcoded65		// timeout before we find better solution66		// Pros: super fast regression issue which block UI execution67		// Cons: there is no way to manage timeouts in this places68    	waitUntil(ExpectedConditions.and(ExpectedConditions.presenceOfElementLocated(locatorBy),69    			ExpectedConditions.visibilityOfElementLocated(locatorBy)));70    	List<WebElement> elements = null;71    	try {72    		elements = locator.findElements();73		} catch (StaleElementReferenceException | InvalidElementStateException e) {74			LOGGER.debug("catched StaleElementReferenceException: ", e);75			elements = webDriver.findElements(locatorBy);76		}77        List<T> uIObjects = new ArrayList<T>();78        int index = 0;79        if (elements != null) {80            for (WebElement element : elements) {81                T uiObject;82                try {83                    uiObject = (T) clazz.getConstructor(WebDriver.class, SearchContext.class)84                            .newInstance(85                                    webDriver, element);86                } catch (NoSuchMethodException e) {87                    LOGGER.error("Implement appropriate AbstractUIObject constructor for auto-initialization: "88                            + e.getMessage());89                    throw new RuntimeException(90                            "Implement appropriate AbstractUIObject constructor for auto-initialization: "91                                    + e.getMessage(),92                            e);93                }94                uiObject.setName(String.format("%s - %d", name, index++));95                uiObject.setRootElement(element);96                uiObject.setRootBy(locatorBy);97                uIObjects.add(uiObject);98            }99        }100        try {101            return method.invoke(uIObjects, objects);102        } catch (InvocationTargetException e) {103            throw e.getCause();104        }105    }106    107    private By getLocatorBy(ElementLocator locator) {108    	By rootBy = null;109    	110        //TODO: get root by annotation from ElementLocator to be able to append by for those elements and reuse fluent waits111		try {112			Field byContextField = null;113			byContextField = locator.getClass().getDeclaredField("by");114			byContextField.setAccessible(true);115			rootBy = (By) byContextField.get(locator);116		} catch (NoSuchFieldException e) {117			e.printStackTrace();118		} catch (IllegalAccessException e) {119			e.printStackTrace();120		} catch (ClassCastException e) {121			e.printStackTrace();122		} catch (Throwable thr) {123			thr.printStackTrace();124			LOGGER.error("Unable to get rootBy via reflection!", thr);125		}126    	127    	return rootBy;128    }129    130    /**131     * Wait until any condition happens.132     *133     * @param condition - ExpectedCondition.134     * @param timeout - timeout.135     * @return true if condition happen.136     */137	@SuppressWarnings("unchecked")138	private boolean waitUntil(ExpectedCondition<?> condition) {139		boolean result;140		141		long timeout = Configuration.getLong(Parameter.EXPLICIT_TIMEOUT);142		long RETRY_TIME = Configuration.getLong(Parameter.RETRY_INTERVAL);143		144		Timer.start(ACTION_NAME.WAIT);145		@SuppressWarnings("rawtypes")146		Wait wait = new WebDriverWait(webDriver, timeout, RETRY_TIME).ignoring(WebDriverException.class)147				.ignoring(NoSuchSessionException.class);148		try {149			wait.until(condition);150			result = true;151			LOGGER.debug("waitUntil: finished true...");152		} catch (NoSuchElementException | TimeoutException e) {153			// don't write exception even in debug mode154			LOGGER.debug("waitUntil: NoSuchElementException | TimeoutException e..." + condition.toString());155			result = false;156		} catch (Exception e) {157			LOGGER.error("waitUntil: " + condition.toString(), e);158			result = false;159		}160		Timer.stop(ACTION_NAME.WAIT);161		return result;162	}163}...Source:LocatingElementListHandler.java  
...33import org.openqa.selenium.support.ui.ExpectedCondition;34import org.openqa.selenium.support.ui.ExpectedConditions;35import org.openqa.selenium.support.ui.Wait;36import org.openqa.selenium.support.ui.WebDriverWait;37import com.qaprosoft.carina.core.foundation.performance.ACTION_NAME;38import com.qaprosoft.carina.core.foundation.performance.Timer;39import com.qaprosoft.carina.core.foundation.utils.Configuration;40import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;41import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;42public class LocatingElementListHandler implements InvocationHandler {43    private final ElementLocator locator;44    private String name;45    private By by;46    private final WebDriver driver;47    48    protected static final Logger LOGGER = Logger.getLogger(LocatingElementListHandler.class);49    public LocatingElementListHandler(WebDriver driver, ElementLocator locator, String name, By by) {50    	this.driver = driver;51        this.locator = locator;52        this.name = name;53        this.by = by;54    }55    public Object invoke(Object object, Method method, Object[] objects) throws Throwable {56		// Hotfix for huge and expected regression in carina: we lost managed57		// time delays with lists manipulations58		// Temporary we are going to restore explicit waiter here with hardcoded59		// timeout before we find better solution60		// Pros: super fast regression issue which block UI execution61		// Cons: there is no way to manage timeouts in this places62//    	if (!waitUntil(ExpectedConditions.or(ExpectedConditions.presenceOfElementLocated(by),63//    			ExpectedConditions.visibilityOfElementLocated(by)))) {64//    		LOGGER.error("List is not present: " + by);65//    	}66    	67    	List<WebElement> elements = null;68    	try {69    		elements = locator.findElements();70		} catch (StaleElementReferenceException | InvalidElementStateException e) {71			LOGGER.debug("catched StaleElementReferenceException: ", e);72			elements = driver.findElements(by);73		}74    	75        List<ExtendedWebElement> extendedWebElements = null;76        if (elements != null) {77            extendedWebElements = new ArrayList<ExtendedWebElement>();78/*            for (WebElement element : elements) {79                extendedWebElements.add(new ExtendedWebElement(element, name, by));80            }*/81            82            int i = 1;83			for (WebElement element : elements) {84				String tempName = name;85				try {86					tempName = element.getText();87				} catch (Exception e) {88					 //do nothing and keep 'undefined' for control name 89				}90				ExtendedWebElement tempElement = new ExtendedWebElement(element, tempName, by);91//				tempElement.setBy(tempElement.generateByForList(by, i));92				extendedWebElements.add(tempElement);93				i++;94			}95        }96        97        98        try {99            return method.invoke(extendedWebElements, objects);100        } catch (InvocationTargetException e) {101            throw e.getCause();102        }103    }104    105    /**106     * Wait until any condition happens.107     *108     * @param condition - ExpectedCondition.109     * @param timeout - timeout.110     * @return true if condition happen.111     */112	@SuppressWarnings("unchecked")113	private boolean waitUntil(ExpectedCondition<?> condition) {114		boolean result;115		116		long timeout = Configuration.getLong(Parameter.EXPLICIT_TIMEOUT);117		long RETRY_TIME = Configuration.getLong(Parameter.RETRY_INTERVAL);118		119		Timer.start(ACTION_NAME.WAIT);120		@SuppressWarnings("rawtypes")121		Wait wait = new WebDriverWait(driver, timeout, RETRY_TIME).ignoring(WebDriverException.class)122				.ignoring(NoSuchSessionException.class);123		try {124			wait.until(condition);125			result = true;126			LOGGER.debug("waitUntil: finished true...");127		} catch (NoSuchElementException | TimeoutException e) {128			// don't write exception even in debug mode129			LOGGER.debug("waitUntil: NoSuchElementException | TimeoutException e..." + condition.toString());130			result = false;131		} catch (Exception e) {132			LOGGER.error("waitUntil: " + condition.toString(), e);133			result = false;134		}135		Timer.stop(ACTION_NAME.WAIT);136		return result;137	}138	139}...Source:CommonUtils.java  
...14 * limitations under the License.15 *******************************************************************************/16package com.qaprosoft.carina.core.foundation.utils.common;17import org.apache.log4j.Logger;18import com.qaprosoft.carina.core.foundation.performance.ACTION_NAME;19import com.qaprosoft.carina.core.foundation.performance.Timer;20public class CommonUtils {21    private static final Logger LOGGER = Logger.getLogger(CommonUtils.class);22    23    private CommonUtils() {24    	//hide public constructor25    }26    /**27     * pause28     *29     * @param timeout Number30     */31    public static void pause(Number timeout) {32    	Timer.start(ACTION_NAME.PAUSE);33        LOGGER.debug(String.format("Will wait for %s seconds", timeout));34        try {35            Float timeoutFloat = timeout.floatValue() * 1000;36            long timeoutLong = timeoutFloat.longValue();37            Thread.sleep(timeoutLong);38        } catch (InterruptedException e) {39            e.printStackTrace();40        }41        LOGGER.debug("Pause is overed. Keep going..");42        Timer.stop(ACTION_NAME.PAUSE);43    }44}...ACTION_NAME
Using AI Code Generation
1import com.qaprosoft.carina.core.foundation.performance.ACTION_NAME;2import com.qaprosoft.carina.core.foundation.performance.Performance;3import org.openqa.selenium.remote.DesiredCapabilities;4import io.appium.java_client.android.AndroidDriver;5import java.net.URL;6public class 1 {7	public static void main(String[] args) throws Exception {8		DesiredCapabilities capabilities = new DesiredCapabilities();9		capabilities.setCapability("deviceName", "Android Emulator");10		capabilities.setCapability("platformName", "Android");11		capabilities.setCapability("platformVersion", "7.1.1");12		capabilities.setCapability("appPackage", "com.android.calculator2");13		capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");ACTION_NAME
Using AI Code Generation
1import com.qaprosoft.carina.core.foundation.performance.ACTION_NAME;2import com.qaprosoft.carina.core.foundation.performance.Metric;3import com.qaprosoft.carina.core.foundation.performance.Performance;4import com.qaprosoft.carina.core.foundation.performance.PerformanceMetric;5import com.qaprosoft.carina.core.foundation.performance.PerformanceTimer;6import com.qaprosoft.carina.core.foundation.performance.Timer;7import com.qaprosoft.carina.core.foundation.performance.TimerContainer;8import com.qaprosoft.carina.core.foundation.performance.TimerContainerFactory;9import com.qaprosoft.carina.core.foundation.performance.TimerFactory;10import com.qaprosoft.carina.core.foundation.performance.TimerType;11import com.qaprosoft.carina.core.foundation.performance.Timing;12import com.qaprosoft.carina.core.foundation.performance.TimingContainer;13import com.qaprosoft.carina.core.foundation.performance.TimingContainerFactory;14import com.qaprosoft.carina.core.foundation.performance.TimingFactory;15import com.qaprosoft.carina.core.foundation.performance.TimingType;16import com.qaprosoft.carina.core.foundation.performance.TACTION_NAME
Using AI Code Generation
1import com.qaprosoft.carina.core.foundation.performance.ActionName;2import com.qaprosoft.carina.core.foundation.performance.Performance;3import com.qaprosoft.carina.core.foundation.performance.PerformanceMetric;4import com.qaprosoft.carina.core.foundation.performance.IPerformanceMonitor;5import com.qaprosoft.carina.core.foundation.performance.PerformanceListener;6import com.qaprosoft.carina.core.foundation.performance.PerformanceFactory;7import com.qaprosoft.carina.core.foundation.performance.IPerformanceFactory;8import com.qaprosoft.carina.core.foundation.performance.PerformanceType;9import com.qaprosoft.carina.core.foundation.performance.IPerformanceContainer;10import com.qaprosoft.carina.core.foundation.performance.IPerformanceContainerFactory;11import com.qaprosoft.carina.core.foundation.performance.PerformanceContainerFactory;12import com.qaprosoft.carina.core.foundation.performance.IPerformanceContainerListener;13import com.qaprosoft.carina.core.foundation.performance.PerformanceContainerListener;14import com.qaprosoft.carina.core.foundation.performance.IPerformanceContainerManager;15import com.qaprosoftACTION_NAME
Using AI Code Generation
1import com.qaprosoft.carina.core.foundation.performance.ActionName;2import com.qaprosoft.carina.core.foundation.performance.Performance;3public class TestClass {4    public void testMethod(){5        Performance perf = new Performance();6        perf.startMonitor();7        perf.startMonitor(ActionName.ACTION_NAME);8        perf.stopMonitor();9        perf.stopMonitor(ActionName.ACTION_NAME);10    }11}12import com.qaprosoft.carina.core.foundation.performance.ActionName;13import com.qaprosoft.carina.core.foundation.performance.Performance;14public class TestClass {15    public void testMethod(){16        Performance perf = new Performance();17        perf.startMonitor();18        perf.startMonitor(ActionName.ACTION_NAME);19        perf.stopMonitor();20        perf.stopMonitor(ActionName.ACTION_NAME);21    }22}23import com.qaprosoft.carina.core.foundation.performance.ActionName;24import com.qaprosoft.carina.core.foundation.performance.Performance;25public class TestClass {26    public void testMethod(){27        Performance perf = new Performance();28        perf.startMonitor();29        perf.startMonitor(ActionName.ACTION_NAME);30        perf.stopMonitor();31        perf.stopMonitor(ActionName.ACTION_NAME);32    }33}34import com.qaprosoft.carina.core.foundation.performance.ActionName;35import com.qaprosoft.carina.core.foundation.performance.Performance;36public class TestClass {ACTION_NAME
Using AI Code Generation
1import com.qaprosoft.carina.core.foundation.performance.ANIMATION;2import com.qaprosoft.carina.core.foundation.performance.ACTION_NAME;3public class Test {4public static void main(String[] args) {5ACTION_NAME action = ANIMATION;6System.out.println(action.name());7System.out.println(action.toString());8System.out.println(action.ordinal());9}10}ACTION_NAME
Using AI Code Generation
1import com.qaprosoft.carina.core.foundation.performance.ActionTimer;2import com.qaprosoft.carina.core.foundation.performance.ActionTimer.ACTION_NAME;3public class 1 {4    public static void main(String args[]) {5        ActionTimer.start(ACTION_NAME.action1);6        ActionTimer.stop(ACTION_NAME.action1);7    }8}9import com.qaprosoft.carina.core.foundation.performance.ActionTimer;10import com.qaprosoft.carina.core.foundation.performance.ActionTimer.ACTION_NAME;11public class 2 {12    public static void main(String args[]) {13        ActionTimer.start(ACTION_NAME.action2);14        ActionTimer.stop(ACTION_NAME.action2);15    }16}17import com.qaprosoft.carina.core.foundation.performance.ActionTimer;18import com.qaprosoft.carina.core.foundation.performance.ActionTimer.ACTION_NAME;19public class 3 {20    public static void main(String args[]) {21        ActionTimer.start(ACTION_NAME.action3);22        ActionTimer.stop(ACTION_NAME.action3);23    }24}25import com.qaprosoft.carina.core.foundation.performance.ActionTimer;26import com.qaprosoft.carina.core.foundation.performance.ActionTimer.ACTION_NAME;27public class 4 {28    public static void main(String args[]) {29        ActionTimer.start(ACTION_NAME.action4);30        ActionTimer.stop(ACTION_NAME.action4);31    }32}33import com.qaprosoft.carina.core.foundation.performance.ActionTimer;34import com.qaprosoft.carina.core.foundationACTION_NAME
Using AI Code Generation
1public class Test extends AbstractTest {2    WebDriver driver = getDriver();3    public void test() {4    }5}6public class Test extends AbstractTest {7    WebDriver driver = getDriver();8    public void test() {9    }10}11public class Test extends AbstractTest {12    WebDriver driver = getDriver();13    public void test() {14    }15}16public class Test extends AbstractTest {17    WebDriver driver = getDriver();Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
