Appium issues - Android Emulator cold-start  command solves test failures

Appium issues - Android Emulator cold-start command solves test failures

I have been working on Appium Automation framework using Java, The main requirement was to invoke simultaneous applications on IOS (11 & 12 and Android Galaxy, Nexus, One plus 8 etc)Devices .

IOS execution went fine but when we are switching from Andriod devices. The test intermittently with error "There was an error in the forked process " and the null pointer being thrown.

I have struggled with this error and tried.

  1. installing Android updates.
  2. Updating Maven Surefire plugin version.
  3. Downgrading Android updates to latest stable version.

But nothing was working. But doing device coldstart before starting the test really saves my day and resolves all the issues when framework is switching the execution from IOS to Android.

Sharing below code snippet for before test activity which I am doing.

  1. command line for cold start with example
emulator -avd <<name Of your Emulator>> -no-snapshot-load

2. We can write java method like below to invoke this command. Note: you need to save the command in file and pass the path of the command mentioned below.

/**
 * to start the emulator programmatically
 * @throws InterruptedException
 */
	public static  void startEmulator() throws InterruptedException {
		try {
			// This code will run the cold-start command when emulator is launched
			Runtime.getRuntime().exec(System.getProperty("user.dir") +"\\src\\main\\resources\\startEmulator.bat");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Thread.sleep(8000);
	}

3. Call above method in your base class before setting the device type to search.

 if(device.equalsIgnoreCase("emulator")) {
			  startEmulator();
			  Thread.sleep(2000);
			  Cap.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
		  }
		  else if(device.equalsIgnoreCase("real")) {
			  Cap.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
		  }
		// 

Note: Cold start takes some additional time make sure to adjust the timeout setting as per your machine.

If you learn something by reading this article. Show the support by endorsing my skillsets..

Thanks!!

要查看或添加评论,请登录

Hemant Varhekar的更多文章

社区洞察

其他会员也浏览了