When I am running, appium basic test ,then error message showing

The same issue again showing!

I am getting errors in configuration method running?

For Mac how we add usingDriverExecutable line

When i run the appium inspector,that time showing error message in appium server showing error messgae

–> POST /session
[HTTP] {“capabilities”:{“alwaysMatch”:{“appium:app”:"//Users//vk14//git//UserApplication//src/test//java//resources//user_app_staging.apk",“appium:deviceName”:“QAAndroid”,“platformName”:“android”,“appium:automationName”:“UIAutomator2”,“appium:ensureWebviewsHavePages”:true,“appium:nativeWebScreenshot”:true,“appium:newCommandTimeout”:3600,“appium:connectHardwareKeyboard”:true},“firstMatch”:[{}]},“desiredCapabilities”:{“appium:app”:"//Users//vk14//git//UserApplication//src/test//java//resources//user_app_staging.apk",“appium:deviceName”:“QAAndroid”,“platformName”:“android”,“appium:automationName”:“UIAutomator2”,“appium:ensureWebviewsHavePages”:true,“appium:nativeWebScreenshot”:true,“appium:newCommandTimeout”:3600,“appium:connectHardwareKeyboard”:true}}
[debug] [AppiumDriver@f34e] Calling AppiumDriver.createSession() with args: [{“appium:app”:"//Users//vk14//git//UserApplication//src/test//java//resources//user_app_staging.apk",“appium:deviceName”:“QAAndroid”,“platformName”:“android”,“appium:automationName”:“UIAutomator2”,“appium:ensureWebviewsHavePages”:true,“appium:nativeWebScreenshot”:true,“appium:newCommandTimeout”:3600,“appium:connectHardwareKeyboard”:true},null,{“alwaysMatch”:{“appium:app”:"//Users//vk14//git//UserApplication//src/test//java//resources//user_app_staging.apk",“appium:deviceName”:“QAAndroid”,“platformName”:“android”,“appium:automationName”:“UIAutomator2”,“appium:ensureWebviewsHavePages”:true,“appium:nativeWebScreenshot”:true,“appium:newCommandTimeout”:3600,“appium:connectHardwareKeyboard”:true},“firstMatch”:[{}]}]
[debug] [AppiumDriver@f34e] Event ‘newSessionRequested’ logged at 1694589407569 (12:46:47 GMT+0530 (India Standard Time))
[Appium] Attempting to find matching driver for automationName ‘UIAutomator2’ and platformName ‘android’
[Appium] The ‘uiautomator2’ driver was installed and matched caps.
[Appium] Will require it at /Users/vk14/.appium/node_modules/appium-uiautomator2-driver
[debug] [Appium] Requiring driver at /Users/vk14/.appium/node_modules/appium-uiautomator2-driver
[AppiumDriver@f34e] Appium v2.0.1 creating new AndroidUiautomator2Driver (v2.29.7) session
[AppiumDriver@f34e] Checking BaseDriver versions for Appium and AndroidUiautomator2Driver
[AppiumDriver@f34e] Appium’s BaseDriver version is 9.3.20
[AppiumDriver@f34e] AndroidUiautomator2Driver’s BaseDriver version is 9.3.20
[debug] [AndroidUiautomator2Driver@7e64] Creating session with W3C capabilities: {
[debug] [AndroidUiautomator2Driver@7e64] “alwaysMatch”: {
[debug] [AndroidUiautomator2Driver@7e64] “platformName”: “android”,
[debug] [AndroidUiautomator2Driver@7e64] “appium:app”: “//Users//vk14//git//UserApplication//src/test//java//resources//user_app_staging.apk”,
[debug] [AndroidUiautomator2Driver@7e64] “appium:deviceName”: “QAAndroid”,
[debug] [AndroidUiautomator2Driver@7e64] “appium:automationName”: “UIAutomator2”,
[debug] [AndroidUiautomator2Driver@7e64] “appium:ensureWebviewsHavePages”: true,
[debug] [AndroidUiautomator2Driver@7e64] “appium:nativeWebScreenshot”: true,
[debug] [AndroidUiautomator2Driver@7e64] “appium:newCommandTimeout”: 3600,
[debug] [AndroidUiautomator2Driver@7e64] “appium:connectHardwareKeyboard”: true
[debug] [AndroidUiautomator2Driver@7e64] },
[debug] [AndroidUiautomator2Driver@7e64] “firstMatch”: [
[debug] [AndroidUiautomator2Driver@7e64] {}
[debug] [AndroidUiautomator2Driver@7e64] ]
[debug] [AndroidUiautomator2Driver@7e64] }
[AndroidUiautomator2Driver@7e64] The following capabilities were provided, but are not recognized by Appium:
[AndroidUiautomator2Driver@7e64] deviceName
[AndroidUiautomator2Driver@7e64] connectHardwareKeyboard
[AndroidUiautomator2Driver@7e64 (17b1d1ed)] Session created with session id: 17b1d1ed-0794-4e5f-9afd-0af630b56d73
[BaseDriver] Using local app ‘//Users//vk14//git//UserApplication//src/test//java//resources//user_app_staging.apk’
[debug] [AndroidUiautomator2Driver@7e64 (17b1d1ed)] Checking whether app is actually present
[debug] [AndroidUiautomator2Driver@7e64 (17b1d1ed)] Deleting UiAutomator2 session
[debug] [AppiumDriver@f34e] Event ‘newSessionStarted’ logged at 1694589407682 (12:46:47 GMT+0530 (India Standard Time))
[debug] [AppiumDriver@f34e] Encountered internal error running command: Error: Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. Read https://developer.android.com/studio/command-line/variables for more details
[debug] [AppiumDriver@f34e] at requireSdkRoot (/Users/vk14/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-adb/lib/helpers.js:82:11)
[debug] [AppiumDriver@f34e] at Function.createADB (/Users/vk14/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-adb/lib/adb.ts:71:39)
[debug] [AppiumDriver@f34e] at Object.createBaseADB (/Users/vk14/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/android-helpers.js:133:20)
[debug] [AppiumDriver@f34e] at Object.getDeviceInfoFromCaps (/Users/vk14/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/android-helpers.js:224:29)
[debug] [AppiumDriver@f34e] at AndroidUiautomator2Driver.startUiAutomator2Session (/Users/vk14/.appium/node_modules/appium-uiautomator2-driver/lib/driver.js:352:40)
[debug] [AppiumDriver@f34e] at AndroidUiautomator2Driver.createSession (/Users/vk14/.appium/node_modules/appium-uiautomator2-driver/lib/driver.js:241:18)
[debug] [AppiumDriver@f34e] at AppiumDriver.createSession (/usr/local/lib/node_modules/appium/lib/appium.js:352:35)
[HTTP] <-- POST /session 500 144 ms - 816
[HTTP]

sorry it’s a question?

My question is when I run a test file then shows an error message,

java.lang.NullPointerException
at java.base/java.io.FileOutputStream.(FileOutputStream.java:226)
at java.base/java.io.FileOutputStream.(FileOutputStream.java:184)
at org.openqa.selenium.remote.service.DriverService$Builder.getLogOutput(DriverService.java:448)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:495)
at globalfiles.GlobalData.configuration(GlobalData.java:40)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:390)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:325)
at org.testng.internal.invokers.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:180)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:122)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:848)
at org.testng.TestRunner.run(TestRunner.java:621)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:443)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:437)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:397)
at org.testng.SuiteRunner.run(SuiteRunner.java:336)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1280)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1200)
at org.testng.TestNG.runSuites(TestNG.java:1114)
at org.testng.TestNG.run(TestNG.java:1082)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

the code is ,

public void configuration() throws MalformedURLException {

	service = new AppiumServiceBuilder()
			.withAppiumJS(new File(
					"//usr//local//lib//node_modules//appium//build//lib//main.js"))
			.withIPAddress("127.0.0.1").usingPort(4723).build();
	//service.start();

	UiAutomator2Options options = new UiAutomator2Options();
	options.setDeviceName("QAAndroid");
	options.setApp("//Users//vk14//git//UserApplication//src/test//java//resources//user_app_staging.apk");
	driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), options);
	driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(40));

}

Hi have resolved the issue ?

java.lang.NullPointerException
at java.base/java.io.FileOutputStream.(FileOutputStream.java:226)
at java.base/java.io.FileOutputStream.(FileOutputStream.java:184)
at org.openqa.selenium.remote.service.DriverService$Builder.getLogOutput(DriverService.java:448)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:495)
at com.ivalue.satsure.utils.Browser.startAppiumServer(Browser.java:45)
at com.ivalue.satsure.TestUtils.BaseClass.setup(BaseClass.java:47)

i am having this issue

can you show you configuration?

public static AppiumDriverLocalService startAppiumServer(String ipAddress, int port) {
service = new AppiumServiceBuilder()
.withAppiumJS(
new File(“C:\Users\labhe\AppData\Roaming\npm\node_modules\appium\build\lib\main.js”))
.withIPAddress(ipAddress).usingPort(port).build();
service.start();
return service;
}

@BeforeMethod
public void setup() throws MalformedURLException, InterruptedException {
service = startAppiumServer(ipAddress,Integer.parseInt(port));
UiAutomator2Options options = new UiAutomator2Options();
options.setDeviceName(AndroidDeviceName);
options.setApp(
System.getProperty(“user.dir”)+"\src\main\java\com\ivalue\satsure\resources\ivalue.apk");
driver = new AndroidDriver(service.getUrl(), options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

}

this is mine:

public AppiumDriverLocalService startAppiumServer(String ipAddress, int port) {
service = new AppiumServiceBuilder().withAppiumJS(new File("/Users/maria/.nvm/versions/node/v16.20.0/lib/node_modules/appium/build/lib/main.js"))
.withIPAddress(ipAddress).usingPort(port)
.usingDriverExecutable(new File("/Users/maria/.nvm/versions/node/v16.20.0/bin/node")).build();
service.start();
return service;
}

1 Like
public void ConfigureAppium() throws IOException {
                 Properties prop = new Properties();	
		     java.net.URL url=ClassLoader.getSystemResource("package/resources/data.properties");

		        try  {
		            prop.load(url.openStream());
		        } catch (FileNotFoundException fie) {
		            fie.printStackTrace();
		        }
				
				String ipAddress= prop.getProperty("ipAddress");
				String port = prop.getProperty("port");
		               service = startAppiumServer(ipAddress,Integer.parseInt(port));
                         UiAutomator2Options options = new UiAutomator2Options();
				options.setDeviceName(prop.getProperty("AndroidDeviceName"));
				options.setAutomationName("UiAutomator2");
                            options.setAppActivity("....");
			        options.setAppPackage("......")
                            driver = new AndroidDriver(service.getUrl(), options);
				driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
1 Like

public static AppiumDriverLocalService startAppiumServer(String ipAddress, int port) {
HashMap<String, String> environment = new HashMap();

	environment.put("PATH", "/usr/local/bin:" + System.getenv("PATH"));

	AppiumServiceBuilder builder = new AppiumServiceBuilder();

	builder

			.withAppiumJS(
					new File("C:\\Users\\labhe\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js"))

			.usingDriverExecutable(new File("C:\\Program Files\\nodejs\\node.exe")).withIPAddress(ipAddress)

			.usingPort(port)

			.withEnvironment(environment)

			.withArgument(GeneralServerFlag.LOCAL_TIMEZONE)

			.withLogFile(new File("AppiumLog.txt"));

	server = AppiumDriverLocalService.buildService(builder);

	System.out.println("Server started at :" + server.getUrl());

	server.start();

	System.out.println("Server is Started.");
	return server;
}

Tried This One Now able to Launch the server

Thanks you , but i never had problem to launch server

1 Like

@Vishnudas_K see the solution of @labhesh_pawar

@Giuma and @labhesh_pawar give what changes need in my configuration method

public void configuration() throws MalformedURLException {

	service = new AppiumServiceBuilder()
			.withAppiumJS(new File(
					"//usr//local//lib//node_modules//appium//build//lib//main.js"))
			.withIPAddress("127.0.0.1").usingPort(4723).build();
	service.start();

	UiAutomator2Options options = new UiAutomator2Options();
	options.setDeviceName("QAAndroid");
	options.setApp("//Users//vk14//git//UserApplication//src/test//java//resources//user_app_staging.apk");
	driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), options);
	driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(40));

}

In this above code

environment.put(“PATH”, “/usr/local/bin:” + System.getenv(“PATH”));

what is this line meaned