Best Cerberus-source code snippet using org.cerberus.engine.entity.MessageEvent.resolveDescription
Source:IOSAppiumService.java
...75 KeyCode keyToPress;76 try {77 keyToPress = KeyCode.valueOf(keyName);78 } catch (IllegalArgumentException e) {79 return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NOT_AVAILABLE).resolveDescription("KEY", keyName);80 }81 // Then do the key press82 try {83 session.getAppiumDriver().getKeyboard().pressKey(keyToPress.getCode());84 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT).resolveDescription("KEY", keyName);85 } catch (Exception e) {86 LOG.warn("Unable to key press due to " + e.getMessage());87 return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_OTHER)88 .resolveDescription("KEY", keyName)89 .resolveDescription("REASON", e.getMessage());90 }91 }92 /**93 * Due to94 * https://discuss.appium.io/t/appium-ios-guide-hiding-the-keyboard-on-real-devices/8221,95 * IOS keyboard can be only hidden by taping on a keyboard key. As same as96 * the tutorial, the {@link Keys#RETURN} (so the {@link KeyCode#RETURN} in97 * Cerberus language) is used to hide keyboard.98 *99 * @param session100 * @return101 */102 @Override103 public MessageEvent hideKeyboard(Session session) {104 MessageEvent keyPressResult = keyPress(session, KeyCode.RETURN.name());105 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT.equals(keyPressResult.getSource())106 ? MessageEventEnum.ACTION_SUCCESS_HIDEKEYBOARD107 : MessageEventEnum.ACTION_FAILED_HIDEKEYBOARD);108 }109 /**110 * The only valid IOS key codes to be able to be pressed111 * <p>112 * See https://github.com/appium/java-client/issues/402 for more information113 */114 private enum KeyCode {115 RETURN(Keys.RETURN.toString()),116 ENTER(Keys.ENTER.toString()),117 SEARCH(Keys.ENTER.toString()),118 BACKSPACE(Keys.BACK_SPACE.toString());119 private String code;120 KeyCode(String code) {121 this.code = code;122 }123 public String getCode() {124 return code;125 }126 }127 @Override128 public MessageEvent swipe(Session session, SwipeAction action) {129 try {130 Direction direction = this.getDirectionForSwipe(session, action);131 // Get the parametrized swipe duration132 Integer myduration = parameters.getParameterIntegerByKey(CERBERUS_APPIUM_SWIPE_DURATION_PARAMETER, "", DEFAULT_CERBERUS_APPIUM_SWIPE_DURATION);133 // Do the swipe thanks to the Appium driver134 TouchAction dragNDrop135 = new TouchAction(session.getAppiumDriver()).press(direction.getX1(), direction.getY1()).waitAction(Duration.ofMillis(myduration))136 .moveTo(direction.getX2(), direction.getY2()).release();137 dragNDrop.perform();138// JavascriptExecutor js = (JavascriptExecutor) session.getAppiumDriver();139// HashMap<String, Integer> swipeObject = new HashMap<String, Integer>();140// swipeObject.put("startX", direction.getX1());141// swipeObject.put("startY", direction.getY1());142// swipeObject.put("endX", direction.getX2());143// swipeObject.put("endY", direction.getY2());144// swipeObject.put("duration", myduration);145// js.executeScript("mobile: swipe", swipeObject);146 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWIPE).resolveDescription("DIRECTION", action.getActionType().name());147 } catch (IllegalArgumentException e) {148 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE)149 .resolveDescription("DIRECTION", action.getActionType().name())150 .resolveDescription("REASON", "Unknown direction");151 } catch (Exception e) {152 LOG.warn("Unable to swipe screen due to " + e.getMessage(), e);153 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE)154 .resolveDescription("DIRECTION", action.getActionType().name())155 .resolveDescription("REASON", e.getMessage());156 }157 }158}...
Source:AndroidAppiumService.java
...69 KeyCode keyToPress;70 try {71 keyToPress = KeyCode.valueOf(keyName);72 } catch (IllegalArgumentException e) {73 return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NOT_AVAILABLE).resolveDescription("KEY", keyName);74 }75 // Then press the key76 try {77 ((AndroidDriver) session.getAppiumDriver()).pressKeyCode(keyToPress.getCode());78 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT).resolveDescription("KEY", keyName);79 } catch (Exception e) {80 LOG.warn("Unable to key press due to " + e.getMessage(), e);81 return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_OTHER)82 .resolveDescription("KEY", keyName)83 .resolveDescription("REASON", e.getMessage());84 }85 }86 @Override87 public MessageEvent hideKeyboard(Session session) {88 try {89 session.getAppiumDriver().hideKeyboard();90 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_HIDEKEYBOARD);91 } catch (Exception e) {92 // Instead of http://stackoverflow.com/questions/35030794/soft-keyboard-not-present-cannot-hide-keyboard-appium-android?answertab=votes#tab-top93 // and testing if keyboard is already hidden by executing an ADB command,94 // we prefer to parse error message to know if it's just due to keyboard which is already hidden.95 // This way, we are more portable because it is not necessary to connect to the Appium server and send the ADB command.96 if (IS_KEYBOARD_ABSENT_ERROR_PATTERN.matcher(e.getMessage()).find()) {97 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_HIDEKEYBOARD_ALREADYHIDDEN);98 }99 LOG.warn("Unable to hide keyboard due to " + e.getMessage(), e);100 return new MessageEvent(MessageEventEnum.ACTION_FAILED_HIDEKEYBOARD);101 }102 }103 /**104 * Translator between Cerberus key names and Android key codes105 */106 private enum KeyCode {107 RETURN(AndroidKeyCode.ENTER),108 ENTER(AndroidKeyCode.ENTER),109 SEARCH(AndroidKeyCode.KEYCODE_SEARCH),110 BACKSPACE(AndroidKeyCode.BACKSPACE),111 BACK(AndroidKeyCode.BACK); 112 private int code;113 KeyCode(int code) {114 this.code = code;115 }116 public int getCode() {117 return code;118 }119 }120 121 @Override122 public MessageEvent swipe(Session session, SwipeAction action) {123 try {124 SwipeAction.Direction direction = this.getDirectionForSwipe(session, action);125 // Get the parametrized swipe duration126 Parameter duration = parameters.findParameterByKey(CERBERUS_APPIUM_SWIPE_DURATION_PARAMETER, "");127 // Do the swipe thanks to the Appium driver128 TouchAction dragNDrop129 = new TouchAction(session.getAppiumDriver()).press(direction.getX1(), direction.getY1()).waitAction(Duration.ofMillis(duration == null ? DEFAULT_CERBERUS_APPIUM_SWIPE_DURATION : Integer.parseInt(duration.getValue())))130 .moveTo(direction.getX2(), direction.getY2()).release();131 dragNDrop.perform();132 133 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWIPE).resolveDescription("DIRECTION", action.getActionType().name());134 } catch (IllegalArgumentException e) {135 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE)136 .resolveDescription("DIRECTION", action.getActionType().name())137 .resolveDescription("REASON", "Unknown direction");138 } catch (Exception e) {139 LOG.warn("Unable to swipe screen due to " + e.getMessage(), e);140 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE)141 .resolveDescription("DIRECTION", action.getActionType().name())142 .resolveDescription("REASON", e.getMessage());143 }144 }145}...
resolveDescription
Using AI Code Generation
1import org.cerberus.engine.entity.MessageEvent;2import org.cerberus.engine.entity.MessageGeneral;3import java.util.Locale;4public class ResolveDescriptionTest {5 public static void main(String[] args) {6 Locale locale = new Locale("en");7 MessageEvent messageEvent = new MessageEvent(MessageGeneral.EXECUTION_FA);8 System.out.println(messageEvent.resolveDescription(locale));9 }10}
resolveDescription
Using AI Code Generation
1package org.cerberus.engine.entity;2import java.util.Locale;3public class TestMessageEvent {4 public static void main(String[] args) {5 MessageEvent me = new MessageEvent(MessageGeneralEnum.EXECUTION_FA);6 me.setDescription("Execution Failed");7 me = me.resolveDescription("en");8 System.out.println(me.getDescription());9 }10}11package org.cerberus.engine.entity;12import java.util.Locale;13public class TestMessageEvent {14 public static void main(String[] args) {15 MessageEvent me = new MessageEvent(MessageGeneralEnum.EXECUTION_FA);16 me.setDescription("Execution Failed");17 me = me.resolveDescription(Locale.ENGLISH);18 System.out.println(me.getDescription());19 }20}21package org.cerberus.engine.entity;22import java.util.Locale;23public class TestMessageEvent {24 public static void main(String[] args) {25 MessageEvent me = new MessageEvent(MessageGeneralEnum.EXECUTION_FA);26 me.setDescription("Execution Failed");27 me = me.resolveDescription(Locale.ENGLISH, "en");28 System.out.println(me.getDescription());29 }30}31package org.cerberus.engine.entity;32import java.util.Locale;33public class TestMessageEvent {34 public static void main(String[] args) {35 MessageEvent me = new MessageEvent(MessageGeneralEnum.EXECUTION_FA);36 me.setDescription("Execution Failed");37 me = me.resolveDescription(Locale.ENGLISH, "en", "Execution Failed");38 System.out.println(me.getDescription());39 }40}41package org.cerberus.engine.entity;42import java.util.Locale;43public class TestMessageEvent {44 public static void main(String[] args) {45 MessageEvent me = new MessageEvent(MessageGeneralEnum.EXECUTION_FA);46 me.setDescription("Execution Failed");47 me = me.resolveDescription(Locale.ENGLISH, "en", "Execution Failed", "Execution Failed");48 System.out.println(me.getDescription());49 }50}
resolveDescription
Using AI Code Generation
1package org.cerberus.engine.entity;2public class MessageEvent {3 public static void main(String[] args) {4 MessageEvent messageEvent = new MessageEvent();5 messageEvent.resolveDescription("Test", "Test");6 }7}8package org.cerberus.engine.entity;9public class MessageEvent {10 public static void main(String[] args) {11 MessageEvent messageEvent = new MessageEvent();12 messageEvent.resolveDescription("Test", "Test");13 }14}15package org.cerberus.engine.entity;16public class MessageEvent {17 public static void main(String[] args) {18 MessageEvent messageEvent = new MessageEvent();19 messageEvent.resolveDescription("Test", "Test");20 }21}22package org.cerberus.engine.entity;23public class MessageEvent {24 public static void main(String[] args) {25 MessageEvent messageEvent = new MessageEvent();26 messageEvent.resolveDescription("Test", "Test");27 }28}29package org.cerberus.engine.entity;30public class MessageEvent {31 public static void main(String[] args) {32 MessageEvent messageEvent = new MessageEvent();33 messageEvent.resolveDescription("Test", "Test");34 }35}36package org.cerberus.engine.entity;37public class MessageEvent {38 public static void main(String[] args) {39 MessageEvent messageEvent = new MessageEvent();40 messageEvent.resolveDescription("Test", "Test");41 }42}43package org.cerberus.engine.entity;44public class MessageEvent {45 public static void main(String[] args) {46 MessageEvent messageEvent = new MessageEvent();47 messageEvent.resolveDescription("Test", "Test");48 }49}
resolveDescription
Using AI Code Generation
1import org.cerberus.engine.entity.MessageEvent;2import org.cerberus.engine.entity.MessageEventEnum;3import org.cerberus.engine.entity.MessageGeneral;4public class 3 {5 public static void main(String[] args) {6 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);7 MessageGeneral msgg = new MessageGeneral(msg);8 System.out.println(msgg.resolveDescription("EN", "fr"));9 }10}
resolveDescription
Using AI Code Generation
1public class 3 {2 public static void main(String[] args) {3 String description = "The test was executed with success.";4 MessageEvent result = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);5 result.setDescription(description);6 System.out.println(result.resolveDescription("TEST", "TEST"));7 }8}9public class 4 {10 public static void main(String[] args) {11 String description = "The test was executed with success.";12 MessageEvent result = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);13 result.setDescription(description);14 System.out.println(result.resolveDescription("TEST", "TEST", "TEST"));15 }16}17public class 5 {18 public static void main(String[] args) {19 String description = "The test was executed with success.";20 MessageEvent result = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);21 result.setDescription(description);22 System.out.println(result.resolveDescription("TEST", "TEST", "TEST", "TEST"));23 }24}25public class 6 {26 public static void main(String[] args) {27 String description = "The test was executed with success.";28 MessageEvent result = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);29 result.setDescription(description);30 System.out.println(result.resolveDescription("TEST", "TEST", "TEST", "TEST", "TEST"));31 }32}33public class 7 {34 public static void main(String[] args) {35 String description = "The test was executed with success.";36 MessageEvent result = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);37 result.setDescription(description);38 System.out.println(result.resolveDescription("TEST", "TEST", "TEST", "TEST", "TEST", "TEST"));39 }40}
resolveDescription
Using AI Code Generation
1package com.cerberus.engine.entity;2import java.io.*;3import java.util.*;4public class ResolveDescription {5 public static void main(String[] args) throws Exception {6 MessageEvent me = new MessageEvent();7 me.setEvent(1);8 me.setSubEvent(1);9 me.setParam1("param1");10 me.setParam2("param2");11 me.setParam3("param3");12 me.setParam4("param4");13 me.setParam5("param5");14 me.setParam6("param6");15 me.setParam7("param7");16 me.setParam8("param8");17 me.setParam9("param9");18 me.setParam10("param10");19 me.setParam11("param11");20 me.setParam12("param12");21 me.setParam13("param13");22 me.setParam14("param14");23 me.setParam15("param15");24 me.setParam16("param16");25 me.setParam17("param17");26 me.setParam18("param18");27 me.setParam19("param19");28 me.setParam20("param20");29 me.setParam21("param21");30 me.setParam22("param22");31 me.setParam23("param23");32 me.setParam24("param24");33 me.setParam25("param25");34 me.setParam26("param26");35 me.setParam27("param27");36 me.setParam28("param28");37 me.setParam29("param29");38 me.setParam30("param30");39 me.setParam31("param31");40 me.setParam32("param32");41 me.setParam33("param33");42 me.setParam34("param34");43 me.setParam35("param35");44 me.setParam36("param36");45 me.setParam37("param37");46 me.setParam38("param38");47 me.setParam39("param39");48 me.setParam40("param40");49 me.setParam41("param41");50 me.setParam42("param42");51 me.setParam43("param43");52 me.setParam44("param44");53 me.setParam45("param45");54 me.setParam46("param46");55 me.setParam47("param47
resolveDescription
Using AI Code Generation
1package org.cerberus.engine.entity;2import java.sql.Timestamp;3public class MessageEvent {4 private String description;5 private String type;6 private Timestamp timestamp;7 private String category;8 private String property;9 public MessageEvent() {10 this.description = "";11 this.type = "";12 this.timestamp = new Timestamp(0);13 this.category = "";14 this.property = "";15 }16 public MessageEvent(String description, String type, Timestamp timestamp, String category, String property) {17 this.description = description;18 this.type = type;19 this.timestamp = timestamp;20 this.category = category;21 this.property = property;22 }23 public String getDescription() {24 return description;25 }26 public void setDescription(String description) {27 this.description = description;28 }29 public String getType() {30 return type;31 }32 public void setType(String type) {33 this.type = type;34 }35 public Timestamp getTimestamp() {36 return timestamp;37 }38 public void setTimestamp(Timestamp timestamp) {39 this.timestamp = timestamp;40 }41 public String getCategory() {42 return category;43 }44 public void setCategory(String category) {45 this.category = category;46 }47 public String getProperty() {48 return property;49 }50 public void setProperty(String property) {51 this.property = property;52 }53 public MessageEvent resolveDescription(String description) {54 return new MessageEvent(description, this.type, this.timestamp, this.category, this.property);55 }56 public MessageEvent resolveType(String type) {57 return new MessageEvent(this.description, type, this.timestamp, this.category, this.property);58 }59 public MessageEvent resolveTimestamp(Timestamp timestamp) {60 return new MessageEvent(this.description, this.type, timestamp, this.category, this.property);61 }62 public MessageEvent resolveCategory(String category) {63 return new MessageEvent(this.description, this.type, this.timestamp, category, this.property);64 }65 public MessageEvent resolveProperty(String property) {66 return new MessageEvent(this.description, this.type, this.timestamp, this
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!!