Best Testsigma code snippet using com.testsigma.automator.actions.ElementAction
Source:IfElementProxyAction.java
1package com.testsigma.automator.actions.mobile.ios.ifconditional;2import com.testsigma.automator.exceptions.AutomatorException;3import com.testsigma.automator.actions.ElementAction;4import com.testsigma.automator.actions.constants.ActionConstants;5import com.testsigma.automator.actions.mobile.ios.verify.VerifyElementAbsenceAction;6import com.testsigma.automator.actions.mobile.ios.verify.VerifyElementDisabledAction;7import com.testsigma.automator.actions.mobile.ios.verify.VerifyElementEnabledAction;8import com.testsigma.automator.actions.mobile.ios.verify.VerifyElementPresenceAction;9import java.lang.reflect.InvocationTargetException;10public class IfElementProxyAction extends ElementAction {11 @Override12 public void execute() throws Exception {13 String status = getTestData();14 switch (status) {15 case ActionConstants.ENABLED:16 VerifyElementEnabledAction enabled = (VerifyElementEnabledAction) this.initializeChildSnippet(VerifyElementEnabledAction.class);17 enabled.execute();18 this.setSuccessMessage(enabled.getSuccessMessage());19 break;20 case ActionConstants.DISABLED:21 VerifyElementDisabledAction disabled = (VerifyElementDisabledAction) this.initializeChildSnippet(VerifyElementDisabledAction.class);22 disabled.execute();23 this.setSuccessMessage(disabled.getSuccessMessage());24 break;25 case ActionConstants.VISIBLE:26 VerifyElementPresenceAction visible = (VerifyElementPresenceAction) this.initializeChildSnippet(VerifyElementPresenceAction.class);27 visible.execute();28 this.setSuccessMessage(visible.getSuccessMessage());29 break;30 case ActionConstants.NOT_VISIBLE:31 VerifyElementAbsenceAction notVisible = (VerifyElementAbsenceAction) this.initializeChildSnippet(VerifyElementAbsenceAction.class);32 notVisible.execute();33 this.setSuccessMessage(notVisible.getSuccessMessage());34 break;35 default:36 setErrorMessage("Unable to Perform Verify Action due to error at test data");37 throw new AutomatorException("Unable to Perform Verify Action due to error at test data");38 }39 }40 protected Object initializeChildSnippet(Class<?> snippetClassName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {41 ElementAction snippet = (ElementAction) snippetClassName.getDeclaredConstructor().newInstance();42 snippet.setDriver(this.getDriver());43 snippet.setElement(this.getElement());44 snippet.setElementPropertiesEntityMap(this.getElementPropertiesEntityMap());45 snippet.setTestDataPropertiesEntityMap(this.getTestDataPropertiesEntityMap());46 snippet.setAttributesMap(this.getAttributesMap());47 snippet.setRuntimeDataProvider(this.getRuntimeDataProvider());48 snippet.setEnvSettings(this.getEnvSettings());49 return snippet;50 }51}...
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!!