Best Testsigma code snippet using com.testsigma.automator.actions.mobile.MobileElement
Source:DriverSessionCommand.java
...73 log.error(e.getMessage(), e);74 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);75 }76 }77 public void tapOnElement(String sessionId, MobileElement mobileElement) throws MobileAutomationServerCommandExecutionException {78 try {79 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);80 if (mobileElement.getWebViewName() != null)81 this.switchToContextByName(remoteWebDriver, mobileElement);82 MobileInspectorTapOnElement mobileInspectorTapOnElement = new MobileInspectorTapOnElement();83 mobileInspectorTapOnElement.setElementPropertiesEntityMap(createElementPropertiesMap(FindByType.XPATH, mobileElement.getXpath()));84 mobileInspectorTapOnElement.setDriver(remoteWebDriver);85 ActionResult result = mobileInspectorTapOnElement.run();86 if (ActionResult.FAILED.equals(result)) {87 log.error(mobileInspectorTapOnElement.getErrorMessage());88 throw new Exception("Failed to tap on element " + " : " + mobileInspectorTapOnElement.getErrorMessage());89 }90 } catch (Exception e) {91 log.error(e.getMessage(), e);92 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);93 } finally {94 if (mobileElement.getWebViewName() != null) {95 try {96 switchToNativeContext(sessionContainer.getSessionMap().get(sessionId), mobileElement);97 } catch (Exception e) {98 log.error(e.getMessage(), e);99 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);100 }101 }102 }103 }104 private void switchToContextByName(RemoteWebDriver remoteWebDriver, MobileElement mobileElement) throws Exception {105 SwitchToContextWithNameAction switchToContext = new SwitchToContextWithNameAction();106 switchToContext.setTestDataPropertiesEntityMap(createTestDataPropertiesMap(mobileElement.getWebViewName()));107 switchToContext.setDriver(remoteWebDriver);108 ActionResult result = switchToContext.run();109 if (ActionResult.FAILED.equals(result)) {110 log.error(switchToContext.getErrorMessage());111 throw new Exception("Failed to Switch to context " + " : " + switchToContext.getErrorMessage());112 }113 }114 private void switchToNativeContext(RemoteWebDriver remoteWebDriver, MobileElement mobileElement) throws Exception {115 SwitchToNativeAppContextAction switchToContext = new SwitchToNativeAppContextAction();116 switchToContext.setDriver(remoteWebDriver);117 ActionResult result = switchToContext.run();118 if (ActionResult.FAILED.equals(result)) {119 log.error(switchToContext.getErrorMessage());120 throw new MobileAutomationServerCommandExecutionException("Failed to Switch to back to native context " + " : " + switchToContext.getErrorMessage());121 }122 }123 public void clearElement(String sessionId, MobileElement mobileElement) throws MobileAutomationServerCommandExecutionException {124 try {125 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);126 if (mobileElement.getWebViewName() != null)127 this.switchToContextByName(remoteWebDriver, mobileElement);128 ClearElementAction clearElementAction = new ClearElementAction();129 clearElementAction.setElementPropertiesEntityMap(createElementPropertiesMap(FindByType.XPATH, mobileElement.getXpath()));130 clearElementAction.setDriver(remoteWebDriver);131 ActionResult result = clearElementAction.run();132 if (ActionResult.FAILED.equals(result)) {133 log.error(clearElementAction.getErrorMessage());134 throw new Exception("Failed to clear element " + " : " + clearElementAction.getErrorMessage());135 }136 } catch (Exception e) {137 log.error(e.getMessage(), e);138 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);139 } finally {140 if (mobileElement.getWebViewName() != null) {141 try {142 switchToNativeContext(sessionContainer.getSessionMap().get(sessionId), mobileElement);143 } catch (Exception e) {144 log.error(e.getMessage(), e);145 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);146 }147 }148 }149 }150 private Map<String, ElementPropertiesEntity> createElementPropertiesMap(FindByType findByType, String locatorValue) {151 ElementPropertiesEntity elementPropertiesEntity = new ElementPropertiesEntity();152 Map<String, ElementPropertiesEntity> elementPropertiesEntityMap = new HashMap<>();153 elementPropertiesEntity.setFindByType(findByType);154 elementPropertiesEntity.setLocatorValue(locatorValue);155 elementPropertiesEntityMap.put(NaturalTextActionConstants.TESTS_TEP_DATA_MAP_KEY_ELEMENT, elementPropertiesEntity);156 return elementPropertiesEntityMap;157 }158 private Map<String, TestDataPropertiesEntity> createTestDataPropertiesMap(String testDataValue) {159 Map<String, TestDataPropertiesEntity> testDataPropertiesEntityMap = new HashMap<>();160 TestDataPropertiesEntity testDataPropertiesEntity = new TestDataPropertiesEntity();161 testDataPropertiesEntity.setTestDataValue(testDataValue);162 testDataPropertiesEntityMap.put(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA, testDataPropertiesEntity);163 return testDataPropertiesEntityMap;164 }165 public void sendKeys(String sessionId, MobileElement mobileElement, String keys) throws MobileAutomationServerCommandExecutionException {166 try {167 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);168 if (mobileElement.getWebViewName() != null)169 this.switchToContextByName(remoteWebDriver, mobileElement);170 SendKeysAction sendKeysAction = new SendKeysAction();171 sendKeysAction.setElementPropertiesEntityMap(createElementPropertiesMap(FindByType.XPATH, mobileElement.getXpath()));172 sendKeysAction.setTestDataPropertiesEntityMap(createTestDataPropertiesMap(keys));173 sendKeysAction.setDriver(remoteWebDriver);174 ActionResult result = sendKeysAction.run();175 if (ActionResult.FAILED.equals(result)) {176 log.error(sendKeysAction.getErrorMessage());177 throw new Exception("Failed to send keys to element " + " : " + sendKeysAction.getErrorMessage());178 }179 } catch (Exception e) {180 log.error(e.getMessage(), e);181 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);182 } finally {183 if (mobileElement.getWebViewName() != null) {184 try {185 switchToNativeContext(sessionContainer.getSessionMap().get(sessionId), mobileElement);186 } catch (Exception e) {187 log.error(e.getMessage(), e);188 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);189 }190 }191 }192 }193 public String pageScreenshot(String sessionId) throws MobileAutomationServerCommandExecutionException {194 try {195 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);196 ScreenshotAction screenshotAction = new ScreenshotAction();197 screenshotAction.setDriver(remoteWebDriver);198 ActionResult result = screenshotAction.run();199 if (ActionResult.FAILED.equals(result)) {200 log.error(screenshotAction.getErrorMessage());201 throw new Exception("Failed to take a screenshot " + " : " + screenshotAction.getErrorMessage());202 }203 return (String) screenshotAction.getActualValue();204 } catch (Exception e) {205 log.error(e.getMessage(), e);206 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);207 }208 }209 public MobileElement pageSourceElements(String sessionId, Platform platform) throws MobileAutomationServerCommandExecutionException {210 try {211 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);212 PageElementsAction pageElementsAction = new PageElementsAction();213 pageElementsAction.setDriver(remoteWebDriver);214 pageElementsAction.setPlatform(platform);215 ActionResult result = pageElementsAction.run();216 if (result.equals(ActionResult.FAILED)) {217 log.error(pageElementsAction.getErrorMessage());218 throw new Exception("Failed to fetch page elements " + " : " + pageElementsAction.getErrorMessage());219 }220 return (MobileElement) pageElementsAction.getActualValue();221 } catch (Exception e) {222 log.error(e.getMessage(), e);223 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);224 }225 }226 public void back(String sessionId) throws MobileAutomationServerCommandExecutionException {227 try {228 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);229 MobileNavigateBackAction mobileNavigateBackAction = new MobileNavigateBackAction();230 mobileNavigateBackAction.setDriver(remoteWebDriver);231 ActionResult result = mobileNavigateBackAction.run();232 if (result.equals(ActionResult.FAILED)) {233 log.error(mobileNavigateBackAction.getErrorMessage());234 throw new Exception("Failed to navigate back to the previous page " + " : " + mobileNavigateBackAction.getErrorMessage());235 }236 } catch (Exception e) {237 log.error(e.getMessage(), e);238 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);239 }240 }241 public void goToHome(String sessionId) throws Exception {242 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);243 if (remoteWebDriver.getClass().equals(AndroidDriver.class)) {244 com.testsigma.automator.actions.mobile.android.generic.GoToHomeScreenAction homeScreenAction = new com.testsigma.automator.actions.mobile.android.generic.GoToHomeScreenAction();245 homeScreenAction.setDriver(remoteWebDriver);246 homeScreenAction.execute();247 } else {248 com.testsigma.automator.actions.mobile.ios.generic.GoToHomeScreenAction homeScreenAction = new com.testsigma.automator.actions.mobile.ios.generic.GoToHomeScreenAction();249 homeScreenAction.setDriver(remoteWebDriver);250 homeScreenAction.execute();251 }252 }253 public ScreenDimensions getScreenDimensions(String sessionId) throws MobileAutomationServerCommandExecutionException {254 try {255 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);256 ScreenDimensionsAction screenDimensionsAction = new ScreenDimensionsAction();257 screenDimensionsAction.setDriver(remoteWebDriver);258 ActionResult result = screenDimensionsAction.run();259 if (result.equals(ActionResult.FAILED)) {260 log.error(screenDimensionsAction.getErrorMessage());261 throw new Exception("Failed to get device screen dimensions " + " : " + screenDimensionsAction.getErrorMessage());262 }263 ScreenDimensions screenDimensions = new ScreenDimensions();264 Dimension dimension = (Dimension) screenDimensionsAction.getActualValue();265 screenDimensions.setScreenHeight(dimension.getHeight());266 screenDimensions.setScreenWidth(dimension.getWidth());267 return screenDimensions;268 } catch (Exception e) {269 log.error(e.getMessage(), e);270 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);271 }272 }273 public List<MobileElement> findElements(String sessionId, Platform platform, ElementSearchCriteria elementSearchCriteria) throws MobileAutomationServerCommandExecutionException {274 try {275 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);276 FindElementsAction findElementsAction = new FindElementsAction();277 findElementsAction.setDriver(remoteWebDriver);278 findElementsAction.setPlatform(platform);279 findElementsAction.setElementSearchCriteria(elementSearchCriteria);280 ActionResult result = findElementsAction.run();281 if (result.equals(ActionResult.FAILED)) {282 log.error(findElementsAction.getErrorMessage());283 throw new Exception("Failed to fetch searched elements " + " : " + findElementsAction.getErrorMessage());284 }285 return (List<MobileElement>) findElementsAction.getActualValue();286 } catch (Exception e) {287 log.error(e.getMessage(), e);288 throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);289 }290 }291 public void findElementByIndexAndTap(String sessionId, Platform platform, ElementSearchCriteria elementSearchCriteria,292 Integer index, String webViewName) throws Exception {293 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);294 FindElementByIndexAndTapAction findElementByIndexAndTapAction = new FindElementByIndexAndTapAction();295 findElementByIndexAndTapAction.setDriver(remoteWebDriver);296 if (webViewName != null)297 findElementByIndexAndTapAction.setWebViewName(webViewName);298 findElementByIndexAndTapAction.setElementSearchCriteria(elementSearchCriteria);299 findElementByIndexAndTapAction.setIndex(index);300 findElementByIndexAndTapAction.setPlatform(platform);301 findElementByIndexAndTapAction.execute();302 }303 public void findElementByIndexAndSendKey(String sessionId, Platform platform, ElementSearchCriteria elementSearchCriteria,304 Integer index, String keys, String webViewName) throws Exception {305 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);306 FindElementByIndexAndSendKeysAction findElementByIndexAndSendKeysAction = new FindElementByIndexAndSendKeysAction();307 findElementByIndexAndSendKeysAction.setDriver(remoteWebDriver);308 if (webViewName != null)309 findElementByIndexAndSendKeysAction.setWebViewName(webViewName);310 findElementByIndexAndSendKeysAction.setElementSearchCriteria(elementSearchCriteria);311 findElementByIndexAndSendKeysAction.setIndex(index);312 findElementByIndexAndSendKeysAction.setPlatform(platform);313 findElementByIndexAndSendKeysAction.setKeys(keys);314 findElementByIndexAndSendKeysAction.execute();315 }316 public void findElementByIndexAndClear(String sessionId, Platform platform, ElementSearchCriteria elementSearchCriteria,317 Integer index, String webViewName) throws Exception {318 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);319 FindElementByIndexAndClearAction findElementByIndexAndClearAction = new FindElementByIndexAndClearAction();320 findElementByIndexAndClearAction.setDriver(remoteWebDriver);321 if (webViewName != null)322 findElementByIndexAndClearAction.setWebViewName(webViewName);323 findElementByIndexAndClearAction.setElementSearchCriteria(elementSearchCriteria);324 findElementByIndexAndClearAction.setIndex(index);325 findElementByIndexAndClearAction.setPlatform(platform);326 findElementByIndexAndClearAction.execute();327 }328 public void changeOrientation(String sessionId) throws Exception {329 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);330 if (remoteWebDriver.getClass().equals(AndroidDriver.class)) {331 com.testsigma.automator.actions.mobile.android.generic.ChangeScreenOrientationAction changeScreenOrientationAction = new com.testsigma.automator.actions.mobile.android.generic.ChangeScreenOrientationAction();332 changeScreenOrientationAction.setDriver(remoteWebDriver);333 changeScreenOrientationAction.execute();334 } else {335 com.testsigma.automator.actions.mobile.ios.generic.ChangeScreenOrientationAction changeScreenOrientationAction = new com.testsigma.automator.actions.mobile.ios.generic.ChangeScreenOrientationAction();336 changeScreenOrientationAction.setDriver(remoteWebDriver);337 changeScreenOrientationAction.execute();338 }339 }340 public ScreenOrientation getOrientation(String sessionId) throws Exception {341 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);342 ScreenOrientation orientation;343 if (remoteWebDriver.getClass().equals(AndroidDriver.class)) {344 com.testsigma.automator.actions.mobile.android.generic.GetScreenOrientationAction getScreenOrientationAction = new com.testsigma.automator.actions.mobile.android.generic.GetScreenOrientationAction();345 getScreenOrientationAction.setDriver(remoteWebDriver);346 getScreenOrientationAction.execute();347 orientation = (ScreenOrientation) getScreenOrientationAction.getActualValue();348 } else {349 com.testsigma.automator.actions.mobile.ios.generic.GetScreenOrientationAction getScreenOrientationAction = new com.testsigma.automator.actions.mobile.ios.generic.GetScreenOrientationAction();350 getScreenOrientationAction.setDriver(remoteWebDriver);351 getScreenOrientationAction.execute();352 orientation = (ScreenOrientation) getScreenOrientationAction.getActualValue();353 }354 return orientation;355 }356 public String getUniqueXpath(String sessionId, Platform platform, MobileElement mobileElement) throws MobileAutomationServerCommandExecutionException {357 try {358 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);359 GetUniqueXpathAction getUniqueXpathSnippet = new GetUniqueXpathAction();360 getUniqueXpathSnippet.setDriver(remoteWebDriver);361 getUniqueXpathSnippet.setPlatform(platform);362 getUniqueXpathSnippet.setWebElement(mobileElement);363 ActionResult result = getUniqueXpathSnippet.run();364 if (result.equals(ActionResult.FAILED)) {365 log.error(getUniqueXpathSnippet.getErrorMessage());366 throw new Exception("Failed to get Unique Xpath" + " : " + getUniqueXpathSnippet.getErrorMessage());367 }368 return (String) getUniqueXpathSnippet.getActualValue();369 } catch (Exception e) {370 log.error(e.getMessage(), e);...
Source:PageElementsAction.java
...27public class PageElementsAction extends MobileDriverAction {28 private static final String SUCCESS_MESSAGE = "Successfully fetched page source for current page";29 @Getter30 @Setter31 MobileElement pageElement;32 @Getter33 @Setter34 Platform platform;35 @Override36 public void execute() throws Exception {37 MobileElement mobileElement;38 getDriver().context("NATIVE_APP");39 String pageSource = getDriver().getPageSource();40 log.debug("Page source fetched: " + pageSource);41 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();42 DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();43 Document document = documentBuilder.parse(new ByteArrayInputStream(pageSource.getBytes(StandardCharsets.UTF_8)));44 Match match = JOOX.$(document).xpath("//*");45 mobileElement = new MobileElement(match.get(0).cloneNode(true), 1, getPlatform());46 mobileElement.setParent(null);47 Set<String> contextNames = getDriver().getContextHandles();48 mobileElement.setContextNames(contextNames);49 List<MobileWebElement> webViewElements = new ArrayList<>();50 List<MobileElement> webViewElementReferences = new ArrayList<>();51 if (contextNames.size() > 1) {52 this.findWebViewNativeElementReferences(mobileElement, webViewElementReferences);53 log.info("webViewElementReferences size:" + webViewElementReferences.size());54 log.info("No of Contexts:" + contextNames.size());55 log.info("Contexts:" + contextNames);56 }57 if (webViewElementReferences.size() > 0) {58 int webViewIndex = 0;59 for (String name : contextNames) {60 if (name.equals("NATIVE_APP") || name.equals("WEBVIEW_chrome"))61 continue;62 if (webViewIndex >= webViewElementReferences.size()) {63 break;64 }65 MobileWebViewElementsAction webViewSnippet = new MobileWebViewElementsAction();66 webViewSnippet.setDriver(getDriver());67 webViewSnippet.setContext(name);68 webViewSnippet.setPlatform(platform);69 webViewSnippet.setNativeReference(webViewElementReferences.get(webViewIndex));70 ActionResult result = webViewSnippet.run();71 if (result.equals(ActionResult.FAILED)) {72 log.error(webViewSnippet.getErrorMessage());73 continue;74 //throw new Exception("Failed to fetch page elements " + " : " + webViewSnippet.getErrorMessage());75 }76 MobileWebElement webViewParentElement = (MobileWebElement) webViewSnippet.getActualValue();77 MobileElement nativeRef = webViewSnippet.getNativeReference();78 //webViewParentElement.setParent(nativeRef.getParent());79 List<MobileElement> children = nativeRef.getParent().getChildElements();80 if (children == null)81 children = new ArrayList<>();82 children.add(children.size() - 1, webViewParentElement);83 nativeRef.getParent().setChildElements(children);84 webViewElements.add(webViewParentElement);85 webViewIndex++;86 }87 }88 mobileElement.setWebViewElements(webViewElements);89 getDriver().context("NATIVE_APP");90 setActualValue(mobileElement);91 populateXpath(mobileElement);92 setSuccessMessage(SUCCESS_MESSAGE);93 }94 private void findWebViewNativeElementReferences(MobileElement mobileElement, List<MobileElement> elementRefs) {95 List<MobileElement> copedChildren = new ArrayList<>();96 if (mobileElement.getChildElements() != null)97 copedChildren.addAll(mobileElement.getChildElements());98 for (MobileElement element : copedChildren) {99 if (element.getType().contains("webkit.WebView")100 || element.getType().contains("XCUIElementTypeWebView")101 || element.getType().contains("XCUIElementTypeWindow")) {102 elementRefs.add(element);103 } else {104 findWebViewNativeElementReferences(element, elementRefs);105 }106 }107 }108 @Override109 protected void handleException(Exception e) {110 super.handleException(e);111 setErrorMessage(e.getMessage());112 setTimeoutException();113 setErrorCode(ErrorCodes.PAGE_ELEMENT_LOAD_TIMEOUT);114 }115 protected void populateXpath(MobileElement mobileElement) {116 mobileElement.populateXpath();117 if ((mobileElement.getChildElements() != null) && (mobileElement.getChildElements().size() > 0)) {118 for (MobileElement element : mobileElement.getChildElements()) {119 populateXpath(element);120 }121 }122 }123}...
Source:GetUniqueXpathAction.java
...13 @Setter14 Platform platform;15 @Getter16 @Setter17 MobileElement webElement;18 @Override19 protected void execute() throws Exception {20 AppiumDriver driver = getDriver();21 List<RemoteWebElement> webElements = new ArrayList<>();22 ElementSearchCriteria elementSearchCriteria = new ElementSearchCriteria(FindByType.XPATH, webElement.getXpath());23 if(webElement.getWebViewName() != null) {24 driver.context(webElement.getWebViewName());25 webElements = driver.findElements(elementSearchCriteria.getBy());26 driver.context("NATIVE_APP");27 } else {28 webElements = driver.findElements(elementSearchCriteria.getBy());29 }30 if(webElements.size() > 1){31 String absoluteXpath = this.optimizeXpathUsingAttributes(webElement);32 elementSearchCriteria.setByValue(absoluteXpath);33 if(driver.findElements(elementSearchCriteria.getBy()).size() != 1){34 String relativeXpath = this.optimizeXpathRelatively(webElement);35 elementSearchCriteria.setByValue(relativeXpath);36 if (driver.findElements(elementSearchCriteria.getBy()).size() != 1){37 setActualValue(null);38 }else39 setActualValue(relativeXpath);40 } else {41 setActualValue(absoluteXpath);42 }43 } else {44 setActualValue(null);45 }46 }47 String optimizeXpathRelatively(MobileElement mobileElement){48 mobileElement.optimiseXpath = true;49 mobileElement.setContentDesc("");50 mobileElement.setResourceId("");51 mobileElement.setName("");52 mobileElement.setLabel("");53 mobileElement.setText("");54 mobileElement.populateXpath();55 return mobileElement.getXpath();56 }57 String optimizeXpathUsingAttributes(MobileElement mobileElement){58 mobileElement.optimiseXpath = true;59 mobileElement.populateXpath();60 return mobileElement.getXpath();61 }62}...
MobileElement
Using AI Code Generation
1package com.testsigma.automator.test;2import com.testsigma.automator.actions.mobile.MobileElement;3import com.testsigma.automator.actions.mobile.MobileElementLocator;4import com.testsigma.automator.actions.mobile.MobileElementLocatorType;5import com.testsigma.automator.actions.mobile.MobileElementLocatorValue;6@MobileElementLocator(locatorType = MobileElementLocatorType.ID, locatorValue = "com.testsigma.automator.sample:id/element1")7public class 2 extends MobileElement {8}9package com.testsigma.automator.test;10import com.testsigma.automator.actions.mobile.MobileElement;11import com.testsigma.automator.actions.mobile.MobileElementLocator;12import com.testsigma.automator.actions.mobile.MobileElementLocatorType;13import com.testsigma.automator.actions.mobile.MobileElementLocatorValue;14@MobileElementLocator(locatorType = MobileElementLocatorType.ID, locatorValue = "com.testsigma.automator.sample:id/element1")15public class 3 extends MobileElement {16}17package com.testsigma.automator.test;18import com.testsigma.automator.actions.mobile.MobileElement;19import com.testsigma.automator.actions.mobile.MobileElementLocator;20import com.testsigma.automator.actions.mobile.MobileElementLocatorType;21import com.testsigma.automator.actions.mobile.MobileElementLocatorValue;22@MobileElementLocator(locatorType = MobileElementLocatorType.ID, locatorValue = "com.testsigma.automator.sample:id/element1")23public class 4 extends MobileElement {24}25package com.testsigma.automator.test;26import com.testsigma.automator.actions.mobile.MobileElement;27import com.testsigma.automator.actions.mobile.MobileElementLocator;28import com.testsigma.automator.actions.mobile.MobileElementLocatorType;29import com.testsigma.automator.actions.mobile.MobileElementLocatorValue;30@MobileElementLocator(locatorType = MobileElementLocatorType.ID, locatorValue = "com.testsigma.automator.sample:id/element1")31public class 5 extends MobileElement {32}
MobileElement
Using AI Code Generation
1package com.testsigma.automator.actions.mobile;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.remote.RemoteWebDriver;4public class MobileElement extends WebElement{5 public MobileElement(RemoteWebDriver driver, String locator) {6 super(driver, locator);7 }8}9package com.testsigma.automator.actions.mobile;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.remote.RemoteWebDriver;12public class MobileElement extends WebElement{13 public MobileElement(RemoteWebDriver driver, String locator) {14 super(driver, locator);15 }16}17package com.testsigma.automator.actions.mobile;18import org.openqa.selenium.WebElement;19import org.openqa.selenium.remote.RemoteWebDriver;20public class MobileElement extends WebElement{21 public MobileElement(RemoteWebDriver driver, String locator) {22 super(driver, locator);23 }24}25package com.testsigma.automator.actions.mobile;26import org.openqa.selenium.WebElement;27import org.openqa.selenium.remote.RemoteWebDriver;28public class MobileElement extends WebElement{29 public MobileElement(RemoteWebDriver driver, String locator) {30 super(driver, locator);31 }32}33package com.testsigma.automator.actions.mobile;34import org.openqa.selenium.WebElement;35import org.openqa.selenium.remote.RemoteWebDriver;36public class MobileElement extends WebElement{37 public MobileElement(RemoteWebDriver driver, String locator) {38 super(driver, locator);39 }40}41package com.testsigma.automator.actions.mobile;42import org.openqa.selenium.WebElement;43import org.openqa.selenium.remote.RemoteWebDriver;44public class MobileElement extends WebElement{45 public MobileElement(RemoteWebDriver driver, String locator) {46 super(driver, locator);47 }48}49package com.testsigma.automator.actions.mobile;50import org.openqa.selenium.WebElement;51import org.openqa.selenium.remote.RemoteWebDriver;52public class MobileElement extends WebElement{53 public MobileElement(RemoteWebDriver driver, String locator) {54 super(driver, locator);55 }56}57package com.testsigma.automator.actions.mobile;58import org.openqa.selenium.WebElement;59import org.openqa.selenium
MobileElement
Using AI Code Generation
1package com.testsigma.automator.actions.mobile;2import java.io.File;3import java.io.IOException;4import java.io.InputStream;5import java.io.OutputStream;6import java.io.PrintStream;7import java.net.URL;8import java.net.URLConnection;9import java.net.URLEncoder;10import java.nio.charset.StandardCharsets;11import java.util.*;12import java.util.concurrent.TimeUnit;13import java.util.function.Function;14import java.util.stream.Collectors;15import java.util.stream.Stream;16import org.apache.commons.io.FileUtils;17import org.apache.commons.io.IOUtils;18import org.apache.commons.lang3.StringUtils;19import org.openqa.selenium.*;20import org.openqa.selenium.interactions.Actions;21import org.openqa.selenium.remote.DesiredCapabilities;22import org.openqa.selenium.remote.RemoteWebDriver;23import org.openqa.selenium.remote.Response;24import org.openqa.selenium.support.ui.ExpectedConditions;25import org.openqa.selenium.support.ui.FluentWait;26import org.openqa.selenium.support.ui.WebDriverWait;27import org.slf4j.Logger;28import org.slf4j.LoggerFactory;29import com.testsigma.automator.util.AutomatorUtil;30import com.testsigma.automator.util.Constants;31import com.testsigma.automator.util.FileUtil;32import com.testsigma.automator.util.JsonUtil;33import com.testsigma.automator.util.LogUtil;34import com.testsigma.automator.util.StringUtil;35import com.testsigma.automator.util.SystemUtil;36import com.testsigma.automator.util.TestUtil;37import com.testsigma.automator.util.WebDriverUtil;38import com.testsigma.automator.util.ZipUtil;39import com.testsigma.automator.util.exception.AutomationException;40import com.testsigma.automator.util.exception.AutomationExceptionType;41import io.appium.java_client.AppiumDriver;42import io.appium.java_client.MobileElement;43import io.appium.java_client.android.AndroidDriver;44import io.appium.java_client.android.AndroidKeyCode;45import io.appium.java_client.android.AndroidTouchAction;46import io.appium.java_client.android.connection.ConnectionStateBuilder;47import io.appium.java_client.android.nativekey.AndroidKey;48import io.appium.java_client.android.nativekey.KeyEvent;49import io.appium.java_client.android.nativekey.PressesKey;50import io.appium.java_client.ios.IOSDriver;51import io.appium.java_client.ios.IOSTouchAction;52import io.appium.java_client.remote.MobileCapabilityType;53import io.appium.java_client.touch.TapOptions;54import io.appium.java_client.touch
MobileElement
Using AI Code Generation
1package com.testsigma.automator.samples;2import java.util.HashMap;3import java.util.Map;4import com.testsigma.automator.actions.mobile.MobileElement;5import com.testsigma.automator.actions.mobile.MobileElementLocator;6import com.testsigma.automator.actions.mobile.MobileLocatorType;7import com.testsigma.automator.actions.mobile.MobileSwipeDirection;8import com.testsigma.automator.actions.mobile.MobileSwipeElement;9import com.testsigma.automator.actions.mobile.MobileSwipeElementLocator;10import com.testsigma.automator.actions.mobile.MobileSwipeLocatorType;11import com.testsigma.automator.core.Automator;12import com.testsigma.automator.core.AutomatorFactory;13import com.testsigma.automator.core.AutomatorSettings;14import com.testsigma.automator.core.BrowserType;15public class MobileSwipe {16 public static void main(String[] args) throws Exception {17 AutomatorSettings settings = new AutomatorSettings();18 settings.setBrowserType(BrowserType.Android);19 settings.setAndroidAppPath("C:\\Users\\Downloads\\app-debug.apk");20 settings.setAndroidAppPackage("com.testsigma.automator.samples");21 Automator automator = AutomatorFactory.getAutomator(settings);22 automator.launchApp();23 MobileElementLocator mobileElementLocator = new MobileElementLocator();24 mobileElementLocator.setMobileLocatorType(MobileLocatorType.ID);25 mobileElementLocator.setMobileLocatorValue("com.testsigma.automator.samples:id/scrollview");26 MobileElement mobileElement = new MobileElement();27 mobileElement.setMobileElementLocator(mobileElementLocator);28 MobileSwipeElement mobileSwipeElement = new MobileSwipeElement();29 mobileSwipeElement.setMobileElement(mobileElement);30 MobileSwipeElementLocator mobileSwipeElementLocator = new MobileSwipeElementLocator();
MobileElement
Using AI Code Generation
1import com.testsigma.automator.actions.mobile.MobileElement;2import com.testsigma.automator.actions.mobile.MobileElementAction;3import com.testsigma.automator.actions.mobile.MobileElementActionFactory;4import com.testsigma.automator.actions.mobile.MobileElementActionFactory.MobileElementActionType;5public class TestSigmaMobileElement {6 public static void main(String[] args) {7 MobileElementActionFactory factory = new MobileElementActionFactory();8 MobileElementAction action = factory.getMobileElementAction(MobileElementActionType.TAP);9 MobileElement element = new MobileElement();10 element.setLocator("id=abc");11 element.setPlatform("android");12 element.setElementName("abc");13 action.perform(element);14 }15}16import com.testsigma.automator.actions.mobile.MobileElement;17import com.testsigma.automator.actions.mobile.MobileElementAction;18import com.testsigma.automator.actions.mobile.MobileElementActionFactory;19import com.testsigma.automator.actions.mobile.MobileElementActionFactory.MobileElementActionType;20public class TestSigmaMobileElement {21 public static void main(String[] args) {22 MobileElementActionFactory factory = new MobileElementActionFactory();23 MobileElementAction action = factory.getMobileElementAction(MobileElementActionType.TAP);24 MobileElement element = new MobileElement();25 element.setLocator("id=abc");26 element.setPlatform("ios");27 element.setElementName("abc");28 action.perform(element);29 }30}31import com.testsigma.automator.actions.mobile.MobileElement;32import com.testsigma.automator.actions.mobile.MobileElementAction;33import com.testsigma.automator.actions.mobile.MobileElementActionFactory;34import com.testsigma.automator.actions.mobile.MobileElementActionFactory.MobileElementActionType;35public class TestSigmaMobileElement {36 public static void main(String[] args) {37 MobileElementActionFactory factory = new MobileElementActionFactory();38 MobileElementAction action = factory.getMobileElementAction(MobileElementActionType.TAP);39 MobileElement element = new MobileElement();
MobileElement
Using AI Code Generation
1import com.testsigma.automator.actions.mobile.MobileElement;2public class 2 {3 public static void main(String[] args) {4 MobileElement element = new MobileElement();5 element.tap(100, 200);6 element.longPress(100, 200);7 element.swipe(100, 200, 300, 400);8 element.scroll(100, 200, 300, 400);9 element.pinch(100, 200, 300, 400);10 element.zoom(100, 200, 300, 400);11 element.dragAndDrop(100, 200, 300, 400);12 element.dragAndDropByOffset(100, 200, 300, 400);13 element.dragAndDropByOffsetAndTap(100, 200, 300, 400);14 }15}16import com.testsigma.automator.actions.mobile.MobileElement;17public class 3 {18 public static void main(String[] args) {19 MobileElement element = new MobileElement();20 element.pinch(100, 200, 300, 400);21 element.zoom(100, 200, 300, 400);22 element.dragAndDrop(100, 200, 300, 400);23 element.dragAndDropByOffset(100, 200, 300, 400);24 element.dragAndDropByOffsetAndTap(100, 200, 300, 400);25 }26}27import com.testsigma.automator.actions.mobile.MobileElement;28public class 4 {29 public static void main(String[] args) {
MobileElement
Using AI Code Generation
1MobileElement mobileElement = MobileElement.getMobileElement("elementName");2mobileElement.click();3mobileElement.sendKeys("text");4mobileElement.clear();5mobileElement.submit();6MobileElement mobileElement = MobileElement.getMobileElement("elementName");7mobileElement.click();8mobileElement.sendKeys("text");9mobileElement.clear();10mobileElement.submit();11MobileElement mobileElement = MobileElement.getMobileElement("elementName");12mobileElement.click();13mobileElement.sendKeys("text");14mobileElement.clear();15mobileElement.submit();16MobileElement mobileElement = MobileElement.getMobileElement("elementName");
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!!