Screen Orientation In Appium Android App Automation Testing

You occasionally needs to rotate shroud orientation from portrait to landscape and landscape to portrait during android software application testing to cheque everything display as well as working fine In both orientation. Same affair y'all accept to verify during appium android software exam automation. For shroud orientation of android software app shroud during appium exam automation, We tin forcefulness out use rotate() method of appium. Let's await at uncomplicated example of how to perform screen orientation In appium android app software test automation.

App To Use And Aim To Achieve
We are going to purpose API Demos app(download from HERE) In android shroud orientation test. Our aim Is to larn electrical flow shroud orientation as well as switch android mobile shroud orientation from landscape to portrait and portrait to landscape.
  • We volition use getOrientation() method of appium to larn electrical flow shroud orientation.
  • We volition purpose rotate() method of appium to change orientation from landscape to portrait and portrait to landscape.
  • driver.rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE) volition rotate shroud orientation from portrait to landscape.
  • driver.rotate(org.openqa.selenium.ScreenOrientation.PORTRAIT) will rotate shroud orientation from landscape to portrait.
Let's Implement It practically.

Create And Run Test
Create new ScreenOrientation.java file Under Android parcel of your parcel In house bellow given software exam code In It.

Note : In this test, We accept Implemented logic to outset as well as halt appium server programmatically In appiumStart() and appiumStop() methods. So It volition outset automatically as well as y'all create non demand to outset as well as halt appium server manually. If appiumStart() and appiumStop() methods non plant for y'all as well as then take away It as well as outset appium server manually.

ScreenOrientation.java
package Android;  import io.appium.java_client.android.AndroidDriver;  import java.io.IOException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecuteResultHandler; import org.apache.commons.exec.DefaultExecutor; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  world shape ScreenOrientation {  static AndroidDriver driver;  // Set path of your node.exe file. Set your path.  // Progra ,1 represents Program Files folder.  String nodePath = "C:/Progra ,1/Appium/node.exe";  // Set path of your appium.js file. Set your path.  String appiumJSPath = "C:/Progra ,1/Appium/node_modules/appium/bin/appium.js";   // This method Is responsible for starting appium server.  world void appiumStart() throws IOException, InterruptedException {   // Created object of apache CommandLine class.   // It volition outset ascendance prompt In background.   CommandLine ascendance = novel CommandLine("cmd");   // Add dissimilar arguments In ascendance business which requires to outset appium server.   command.addArgument("/c");   command.addArgument(nodePath);   command.addArgument(appiumJSPath);   // Set Server address   command.addArgument("--address");   command.addArgument("127.0.0.1");   // Set Port   command.addArgument("--port");   command.addArgument("4723");   command.addArgument("--no-reset");   command.addArgument("--log");   // Set path to shop appium server log file.   command.addArgument("D://appiumLogs.txt");   // Execute ascendance business arguments to outset appium server.   DefaultExecuteResultHandler resultHandler = novel DefaultExecuteResultHandler();   DefaultExecutor executor = novel DefaultExecutor();   executor.setExitValue(1);   executor.execute(command, resultHandler);   // Wait for xv minutes hence that appium server tin forcefulness out outset properly earlier going for exam execution.   // Increase this fourth dimension If confront whatever error.   Thread.sleep(15000);  }   // This method Is responsible for stopping appium server.  world static void appiumStop() throws IOException {   // Add dissimilar arguments In ascendance business which requires to halt appium server.   CommandLine ascendance = novel CommandLine("cmd");   command.addArgument("/c");   command.addArgument("taskkill");   command.addArgument("/F");   command.addArgument("/IM");   command.addArgument("node.exe");   // Execute ascendance business arguments to halt appium server.   DefaultExecuteResultHandler resultHandler = novel DefaultExecuteResultHandler();   DefaultExecutor executor = novel DefaultExecutor();   executor.setExitValue(1);   executor.execute(command, resultHandler);  }   @BeforeTest  world void setUp() throws Exception {   // Start appium server.   appiumStart();   DesiredCapabilities capabilities = novel DesiredCapabilities();   capabilities.setCapability("deviceName", "ZX1B32FFXF");   capabilities.setCapability("browserName", "Android");   capabilities.setCapability("platformVersion", "4.4.2");   capabilities.setCapability("platformName", "Android");   capabilities.setCapability("appPackage", "io.appium.android.apis");   capabilities.setCapability("appActivity", "io.appium.android.apis.ApiDemos");   driver = novel AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  }   @Test  world void performOrientation() throws InterruptedException {   //Get as well as impress electrical flow shroud orientation.   System.out.println("*--*--*-- Current shroud orientation Is : " + driver.getOrientation());   System.out.println("*--*--*-- Changing shroud Orientation to LANDSCAPE.");   //Changing shroud Orientation to LANDSCAPE.   driver.rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE);   //Get as well as impress shroud orientation afterwards changing It.   System.out.println("*--*--*-- Now shroud orientation Is : "+ driver.getOrientation());   Thread.sleep(5000);   // Scroll till chemical ingredient which contains "Views" text If It Is non visible on screen.   driver.scrollTo("Views");   // Click on Views.   driver.findElement(By.name("Views")).click();     System.out.println("*--*--*-- Changing shroud Orientation to PORTRAIT.");   //Changing shroud Orientation to PORTRAIT.   driver.rotate(org.openqa.selenium.ScreenOrientation.PORTRAIT);   //Get as well as impress shroud orientation afterwards changing It.   System.out.println("*--*--*-- Now shroud orientation Is : "+ driver.getOrientation());   Thread.sleep(5000);  }   @AfterTest  world void End() throws IOException {   driver.quit();   // Stop appium server when exam Is ended.   appiumStop();  } }

Test Description
In higher upward test, Main affair y'all demand to empathise Is how to larn electrical flow shroud orientation as well as how to alter It from landscape to portrait and portrait to landscape. Everything Is described inside script hence no demand to a greater extent than annunciation here.

This Is the agency to alter shroud orientation of android mobile shroud when y'all run android software automation exam using appium.


More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post