21 Metodi Appium: Guida all'uso (con codice!)

Discuteremo come usare Metodi Appium in questo Tutorial Appium. Appium è un involucro sopra Selenio webDriver. Tutti i metodi Selenio sono già presenti in Appium. Oltre a questo, Appium offre un buon numero di modi per interagire con le applicazioni native.

Come utilizzare il codice pressKey utilizzando i metodi Appium?

 public void pressKeyCode (codice AndroidKey) { androidDriver.pressKey (nuovo KeyEvent (codice)); } Qui puoi passare keyEvent come AndroidKey.ENTER per entrare o AndroidKey.BACK per toccare il pulsante Indietro Allo stesso modo, gli utenti possono usarlo per pressioni prolungate di tasti come: public void longPressKeyCode (codice AndroidKey) { androidDriver.longPressKey (new KeyEvent (codice) ); }

Come ottenere l'attività corrente utilizzando i comandi Appium?

Per ottenere l'attività corrente, possiamo utilizzare il metodo dell'attività corrente. Ad esempio: public String currentActivity() { return androidDriver.currentActivity(); }

Come a controllare se l'app è installata o no?

Per verificare se l'app è installata o meno possiamo usare: public boolean isAppInstalled(String bundleId) { return androidDriver .isAppInstalled(bundleId); }

Come iniziare l'attività su Android utilizzando i metodi Appium?

Si prega di seguire il metodo seguente per avviare l'attività: public void startActivity(String packageName, String activity) { try { androidDriver.startActivity(new Activity(packageName, activity)); } cattura (Eccezione e) { e.printStackTrace(); }

Come scorrere fino a un testo particolare utilizzando i metodi Appium?

public MobileElement scrollTo(String text) { MobileElement textFinder = androidDriver .findElementByAndroidUIAutomator ("new UiScrollable(new UiSelector()" + ".resourceId(\"android:id/list\")) .scrollIntoView(" + "new UiSelector() .text(\"" + testo + "\"));"); restituisce il cercatore di testo; }

Come nascondere la tastiera usando i metodi Appium?

public void hideKeyboard() { prova { androidDriver.hideKeyboard(); } catch (Eccezione e) { LoggerUtils.error("Eccezione nella tastiera nascosta" + e.getMessage()); }

Come ottenere la finestra di dialogo di avanzamento utilizzando i metodi Appium?

public MobileElement getProgressDialog() { return androidDriver .findElementById ("android:id/progress"); }

Come scorrere verso sinistra usando i metodi Appium ??

public void swipeLeft(By by) { MobileElement element = (MobileElement) androidDriver.findElement(by); int offset = 1; Punto p = elemento.getCenter(); Posizione del punto = element.getLocation(); Dimensione dimensione = element.getSize(); int startX=location.getX() + size.getWidth() - offset; int inizioY=p.getY(); int endX=posizione.getX() + offset; new TouchAction(androidDriver) .press(PointOption.point(startX, startY)) .waitAction(WaitOptions. waitOptions(java.time .Duration.ofMillis(1000))) .moveTo(PointOption.point(endX, startY)) .release () .eseguire(); }

Come scorrere verso destra usando i metodi Appium?

public void swipeRight(By by) { MobileElement element = (MobileElement) androidDriver.findElement(by); int offset = 1; Punto p = elemento.getCenter(); Posizione del punto = element.getLocation(); Dimensione dimensione = element.getSize(); int startX=location.getX() + offset + 20; int inizioY=p.getY(); int endX=location.getX() + size.getWidth() - offset; new TouchAction(androidDriver) .press(PointOption.point(startX, startY)) .waitAction(WaitOptions. waitOptions(java.time .Duration.ofMillis(1000))) .moveTo(PointOption.point(endX, startY)) .release () .eseguire(); }

Come scorrere verso l'alto utilizzando i metodi Appium?

Elemento MobileElement = (MobileElement) androidDriver.findElement(by); Dimensione dimensione = element.getSize(); int endX = (int) (size.height * 0.70); int startY = (int) (size.height * 0.30); int startX = (dimensione.larghezza / 2); new TouchAction(androidDriver) .press(PointOption.point(startX, startY)) .waitAction(WaitOptions. waitOptions(java.time .Duration.ofMillis(1000))) .moveTo(PointOption.point(endX, startY)) .release () .eseguire(); }

Come scorrere verso il basso utilizzando i metodi Appium?

public void swipeDown(By by){ MobileElement element = (MobileElement) androidDriver.findElement(by); Dimensione dimensione = element.getSize(); int startY = (int) (size.height * 0.70); int endY = (int) (size.height * 0.30); int startX = (dimensione.larghezza / 2); new TouchAction(androidDriver) .press(PointOption.point(startX, startY)) .waitAction(WaitOptions. waitOptions(java.time .Duration.ofMillis(1000))) .moveTo(PointOption.point(startX, endY)) .release () .eseguire(); }

Come fare doppio clic su Appium usando i comandi Appium?

public void doubleClick(elemento WebElement) { azione TouchActions = new TouchActions(androidDriver); action.doubleClick(elemento); action.perform(); }

Come disattivare il GPS su Android?

public static void swicthOffGPSConnection(String androidSdkToolPath, String deviceId) { try { Runtime.getRuntime(). exec(androidSdkToolPath + "/adb -s" + deviceId + " impostazioni della shell mettono secure location_providers_allowed ' '"); } cattura (Eccezione e) { e.printStackTrace(); }

Come attivare il GPS su Android?

public static void swicthONGPSConnection(String androidSdkToolPath, String deviceId) { try { Runtime.getRuntime() .exec(androidSdkToolPath + "/adb -s" + deviceId + " impostazioni shell mettono secure location_providers_allowed gps "); } cattura (Eccezione e) { e.printStackTrace(); } }

Come disattivare il Wifi su Android?

public void switchOFFWifiConnection(String androidSdkToolPath,String deviceId) { try { Runtime.getRuntime() .exec(androidSdkToolPath+ "/adb -s"+deviceId +" shell am start -n io.appium.settings/.Settings -e wifi off" ); } cattura (IOException e) { e.printStackTrace(); } }

Come attivare il Wifi su Android?

public void switchONWifiConnection(String androidSdkToolPath,String deviceId) { try { Runtime.getRuntime() .exec(androidSdkToolPath + "/adb -s"+deviceId+" shell am start -n io.appium.settings/.Settings -e wifi on" ); } cattura (IOException e) { e.printStackTrace(); } }

Come disattivare i dati su Android?

public void switchOFFDataConnection(String androidSdkToolPath,String deviceId) { try { Runtime.getRuntime() .exec(androidSdkToolPath + "/adb -s"+deviceId+" shell am start -n io.appium.settings/.Settings -e data off" ); System.out.println("************** Wi-Fi spento *******"); } catch (IOException e) { // TODO Blocco catch generato automaticamente e.printStackTrace(); } }

Come attivare i dati su Android?

public void switchONDataConnection(String androidSdkToolPath,String deviceId) { try { Runtime.getRuntime() .exec(androidSdkToolPath + "/adb -s"+deviceId+" shell am start -n io.appium.settings/.Settings -e data on" ); } catch (IOException e) { // TODO Blocco catch generato automaticamente e.printStackTrace(); } }

Come disinstallare l'app su Android?

public void uninstallTheApp(String androidSdkToolPath, String deviceId, String pkg) { try { Runtime.getRuntime() .exec(androidSdkToolPath + "/adb -s" + deviceId + " uninstall " + pkg); } cattura (Eccezione e) { System.out.println(e); } }

Come attivare la modalità di volo in iOS?

public void toggleFlightMode() { Dimension window = iosDriver. manage().window().getSize(); try { int startX = window.width / 2; int startY = altezza.finestra; int endY = altezza.finestra / 10; new TouchAction(iosDriver) .press(PointOption.point(startX, startY)) .waitAction(WaitOptions .waitOptions(java.time .Duration.ofMillis(1000))) .moveTo(PointOption .point(startX, endY)).release ().eseguire(); } catch (Eccezione e) { System.out.println("\nImpossibile scorrere verso l'alto.\n"); e.printStackTrace(); } Volo MobileElement = nullo; if ((flight = iosDriver .findElement(By .name("Airplane Mode"))).isDisplayed()) { flight.click(); new TouchAction(iosDriver) .tap(TapOptions .tapOptions() .withPosition(PointOption .point(window.width / 2, 10))).perform(); } else { throw new RuntimeException("Pulsante modalità aereo non trovato."); } }

Conclusione

Fino ad ora, abbiamo discusso del top 20 più utilizzati Appium metodi. Nel prossimo argomento, scriveremo su l' Ispettore Appium per Android e iOS. Per maggiori dettagli su questa sezione, fare riferimento a questo collegamento.

Lascia un tuo commento

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati con *

Scorrere fino a Top