Best Testsigma code snippet using com.testsigma.automator.actions.mobile.PageElementsAction.execute
Source:DriverSessionCommand.java
...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());...
Source:MobileWebViewElementsAction.java
...35 @Getter36 @Setter37 Platform platform;38 @Override39 public void execute() throws Exception {40 MobileWebElement mobileWebElement;41 getDriver().context(this.context);42 elementsDimensions();43 String webViewPageSource = getDriver().getPageSource();44 log.debug("Page source ::[" + context + "] fetched: " + webViewPageSource);45 webViewPageSource = webViewPageSource.replaceAll(" ", " ");46 org.jsoup.nodes.Document webViewDocument = Jsoup.parse(webViewPageSource);47 webViewDocument.outputSettings().syntax(org.jsoup.nodes.Document.OutputSettings.Syntax.xml);48 webViewDocument.html().getBytes(StandardCharsets.UTF_8);49 org.jsoup.nodes.Document webViewDocumentNew = Jsoup.parse(webViewDocument.html());50 W3CDom w3cDom = new W3CDom();51 org.w3c.dom.Document w3cDoc = w3cDom.fromJsoup(webViewDocumentNew);52 Match webViewMatch = JOOX.$(w3cDoc).xpath("//body/*[not(self::script)]");53 Document docnew = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();54 Element body = docnew.createElement("body");55 for (Node childNode : webViewMatch.get()) {56 Node imported_node = docnew.importNode(childNode, true);57 Element eElement = (Element) imported_node;58 body.insertBefore(eElement, null);59 }60 mobileWebElement = new MobileWebElement(body.cloneNode(true), 1, getPlatform(), this.context);61 mobileWebElement.setWebViewName(this.context);62 getDriver().context("NATIVE_APP");63 setActualValue(mobileWebElement);64 populateXpath(mobileWebElement);65 setSuccessMessage(String.format(SUCCESS_MESSAGE, context));66 }67 private void elementsDimensions() {68 Integer width = nativeReference.getWidth();69 if (width == null)70 width = nativeReference.getX2() - nativeReference.getX1();71 Integer height = nativeReference.getHeight();72 if (height == null)73 height = nativeReference.getY2() - nativeReference.getY1();74 if (platform.equals(Platform.Android))75 getDriver().executeScript("return (function r(s, r, w, h){bodyRect = document.body.getBoundingClientRect(); hr = bodyRect.height/h; wr = bodyRect.width/w; o=document.body.getElementsByTagName('*'),i=window.devicePixelRatio;Array.from(o).forEach(t=>{const e=t.getBoundingClientRect(); t.setAttribute('data-testsigma-inspector-width',Math.round(Math.round(e.width*i))),t.setAttribute('data-testsigma-inspector-height',Math.round(Math.round(e.height*i))),t.setAttribute('data-testsigma-inspector-x',Math.round(s+e.left*i)),t.setAttribute('data-testsigma-inspector-y',Math.round(r+e.top*i))})}).apply(null, arguments)", this.nativeReference.getX1(), this.nativeReference.getY1(), width, height);76 else {77 try {78 Object statusBarHeight = getDriver().executeScript("return (function e(r){i=1,a=56,d=window.screen.height-window.innerHeight-r;return r+(d>=0&&d-a<0?d:a)*i}).apply(null, arguments)", 48);79 log.debug("statusBarHeight ::" + statusBarHeight);80 getDriver().executeScript("return (function r(r){o=document.body.getElementsByTagName('*'),i=1;Array.from(o).forEach(t=>{const e=t.getBoundingClientRect();t.setAttribute('data-testsigma-inspector-width',Math.round(e.width*i)),t.setAttribute('data-testsigma-inspector-height',Math.round(e.height*i)),t.setAttribute('data-testsigma-inspector-x',Math.round(e.left*i)),t.setAttribute('data-testsigma-inspector-y',Math.round(r+e.top*i))})}).apply(null, arguments)", statusBarHeight);81 } catch (Exception e) {82 log.error(e, e);83 }84 }85 }86}...
execute
Using AI Code Generation
1package com.testsigma.automator.sample;2import com.testsigma.automator.actions.mobile.PageElementsAction;3import com.testsigma.automator.core.TestContext;4import com.testsigma.automator.core.TestData;5import com.testsigma.automator.core.TestDataFactory;6import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException;7import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.ExceptionType;8import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.Reason;9import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.Severity;10import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.Type;11import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction;12import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType;13import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.Action;14import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.ActionTypeValue;15import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.ActionTypeValue.Value;16import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.ActionTypeValue.ValueType;17import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.ActionTypeValue.ValueType.ValueTypeValue;18import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.ActionTypeValue.ValueType.ValueTypeValue.ValueTypeValueValue;19import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.ActionTypeValue.ValueType.ValueTypeValue.ValueTypeValueValue.ValueTypeValueValueValue;20import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.ActionTypeValue.ValueType.ValueTypeValue.ValueTypeValueValue.ValueTypeValueValueValue.ValueTypeValueValueValueValue;21import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.ActionTypeValue.ValueType.ValueTypeValue.ValueTypeValueValue.ValueTypeValueValueValue.ValueTypeValueValueValueValue.ValueTypeValueValueValueValueValue;22import com.testsigma.automator.core.TestDataFactory.TestDataFactoryException.UserAction.ActionType.ActionTypeValue.ValueType.ValueType
execute
Using AI Code Generation
1package com.testsigma.automator.actions.mobile;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.remote.RemoteWebDriver;6import org.openqa.selenium.remote.RemoteWebElement;7import com.testsigma.automator.actions.Action;8import com.testsigma.automator.actions.ActionContext;9import com.testsigma.automator.actions.ActionException;10import com.testsigma.automator.actions.ActionInfo;11import com.testsigma.automator.actions.ActionResult;12import com.testsigma.automator.actions.mobile.PageElementsAction;13import com.testsigma.automator.actions.mobile.PageElementsAction.ElementAction;14import com.testsigma.automator.actions.mobile.PageElementsAction.ElementActionType;15import com.testsigma.automator.utils.StringUtil;16@ActionInfo(name = "GetText", description = "Gets the text of an element", category = "mobile", supportedDevices = {17 "mobile" })18public class GetText extends PageElementsAction {19 private static final String ELEMENT_NAME = "elementName";20 private static final String ELEMENT_LOCATOR = "elementLocator";21 private static final String ELEMENT_LOCATOR_TYPE = "elementLocatorType";22 private static final String ELEMENT_LOCATOR_TYPE_VALUE = "elementLocatorTypeValue";23 private static final String ELEMENT_LOCATOR_VALUE = "elementLocatorValue";24 private static final String ELEMENT_PATH = "elementPath";25 private static final String ELEMENT_PATH_TYPE = "elementPathType";26 private static final String ELEMENT_PATH_TYPE_VALUE = "elementPathTypeValue";27 private static final String ELEMENT_PATH_VALUE = "elementPathValue";28 private static final String ELEMENT_PATH_INDEX = "elementPathIndex";29 public GetText() {30 super(ElementActionType.GET_TEXT);31 }32 public ActionResult execute(ActionContext actionContext) throws ActionException {33 RemoteWebDriver driver = actionContext.getDriver();34 String elementName = actionContext.getParams().get(ELEMENT_NAME);35 String elementLocator = actionContext.getParams().get(ELEMENT_LOCATOR);36 String elementLocatorType = actionContext.getParams().get(ELEMENT_LOCATOR_TYPE);37 String elementLocatorTypeValue = actionContext.getParams().get(ELEMENT_LOCATOR_TYPE_VALUE);38 String elementLocatorValue = actionContext.getParams().get(ELEMENT_LOCATOR_VALUE);39 String elementPath = actionContext.getParams().get(ELEMENT_PATH);40 String elementPathType = actionContext.getParams().get(ELEMENT_PATH_TYPE);
execute
Using AI Code Generation
1PageElementsAction pageElementsAction = new PageElementsAction();2pageElementsAction.execute("swipe", "up");3PageElementsAction pageElementsAction = new PageElementsAction();4pageElementsAction.execute("swipe", "up");5PageElementsAction pageElementsAction = new PageElementsAction();6pageElementsAction.execute("swipe", "up");7PageElementsAction pageElementsAction = new PageElementsAction();8pageElementsAction.execute("swipe", "up");9PageElementsAction pageElementsAction = new PageElementsAction();10pageElementsAction.execute("swipe", "up");11PageElementsAction pageElementsAction = new PageElementsAction();12pageElementsAction.execute("swipe", "up");13PageElementsAction pageElementsAction = new PageElementsAction();14pageElementsAction.execute("swipe", "up");15PageElementsAction pageElementsAction = new PageElementsAction();16pageElementsAction.execute("swipe", "up");17PageElementsAction pageElementsAction = new PageElementsAction();18pageElementsAction.execute("swipe", "up");19PageElementsAction pageElementsAction = new PageElementsAction();20pageElementsAction.execute("swipe", "up");
execute
Using AI Code Generation
1PageElementsAction pageElementsAction = new PageElementsAction();2pageElementsAction.execute(driver, "SWIPE", "0.5,0.5,0.5,0.8,1000");3PageElementsAction pageElementsAction = new PageElementsAction();4pageElementsAction.execute(driver, "SWIPE", "0.5,0.5,0.5,0.8,1000");5PageElementsAction pageElementsAction = new PageElementsAction();6pageElementsAction.execute(driver, "SWIPE", "0.5,0.5,0.5,0.8,1000");7PageElementsAction pageElementsAction = new PageElementsAction();8pageElementsAction.execute(driver, "SWIPE", "0.5,0.5,0.5,0.8,1000");9PageElementsAction pageElementsAction = new PageElementsAction();10pageElementsAction.execute(driver, "SWIPE", "0.5,0.5,0.5,0.8,1000");11PageElementsAction pageElementsAction = new PageElementsAction();12pageElementsAction.execute(driver, "SWIPE", "0.5,0.5,0.5,0.8,1000");13PageElementsAction pageElementsAction = new PageElementsAction();14pageElementsAction.execute(driver, "SWIPE", "0.5,0.5,0.5,0.8,1000");15PageElementsAction pageElementsAction = new PageElementsAction();16pageElementsAction.execute(driver, "SWIPE", "0.5,0.5,0.5,0.8,1000");
execute
Using AI Code Generation
1PageElementsAction.clickOnElement("id=elementId");2PageElementsAction.clickOnElement("xpath=elementXpath");3PageElementsAction.clickOnElement("name=elementName");4PageElementsAction.clickOnElement("class=elementClass");5PageElementsAction.clickOnElement("tag=elementTag");6PageElementsAction.clickOnElement("link=elementLink");7PageElementsAction.clickOnElement("partialLink=elementPartialLink");8PageElementsAction.clickOnElement("css=elementCss");9PageElementsAction.clickOnElement("androidUIAutomator=elementAndroidUIAutomator");10PageElementsAction.clickOnElement("iosUIAutomation=elementIosUIAutomation");11PageElementsAction.clickOnElement("accessibilityId=elementAccessibilityId");12PageElementsAction.clickOnElement("image=elementImage");
execute
Using AI Code Generation
1public void test() {2 PageElementsAction action = new PageElementsAction();3 Map<String, String> params = new HashMap<>();4 params.put("action", "click");5 action.execute(params);6}7public void test() {8 PageElementsAction action = new PageElementsAction();9 Map<String, String> params = new HashMap<>();10 params.put("action", "click");11 action.execute(params);12}13public void test() {14 PageElementsAction action = new PageElementsAction();15 Map<String, String> params = new HashMap<>();16 params.put("action", "click");17 action.execute(params);18}19public void test() {20 PageElementsAction action = new PageElementsAction();21 Map<String, String> params = new HashMap<>();22 params.put("action", "click");23 action.execute(params);24}25public void test() {26 PageElementsAction action = new PageElementsAction();27 Map<String, String> params = new HashMap<>();28 params.put("action", "click");29 action.execute(params);30}31public void test() {32 PageElementsAction action = new PageElementsAction();33 Map<String, String> params = new HashMap<>();34 params.put("action", "click");35 action.execute(params);36}
execute
Using AI Code Generation
1package com.testsigma.automator;2import java.util.HashMap;3import java.util.Map;4import com.testsigma.automator.actions.mobile.PageElementsAction;5public class 2 {6 public static void main(String[] args) {7 Map<String, String> params = new HashMap<String, String>();8 params.put("value", "");9 PageElementsAction.execute("getText", params);10 }11}12package com.testsigma.automator;13import java.util.HashMap;14import java.util.Map;15import com.testsigma.automator.actions.mobile.PageElementsAction;16public class 3 {17 public static void main(String[] args) {18 Map<String, String> params = new HashMap<String, String>();19 params.put("value", "");20 PageElementsAction.execute("getText", params);21 }22}23package com.testsigma.automator;24import java.util.HashMap;25import java.util.Map;26import com.testsigma.automator.actions.mobile.PageElementsAction;27public class 4 {28 public static void main(String[] args) {29 Map<String, String> params = new HashMap<String, String>();30 params.put("value", "");
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!!