When I try to run Appium server automatically by using Java getting some issue!


#1

TypeError: Cannot read property ‘app’ of undefined

Code which i’m using:

String host = “http://127.0.0.1”;
int port = 4723;

DriverService service = new AppiumServiceBuilder()
.usingDriverExecutable(new File(“C:/Program Files/nodejs/node.exe”))
.withAppiumJS(new File(“C:/Users/M1040308/AppData/Local/Programs/Appium/resources/app/main.js”))
.withIPAddress(host.split("//")[1])
.usingPort(port)
.withLogFile(new File(“D:/web_selenium”))
.build();
service.start();


#2

@Satheesh_Kumar try below approach, for me works perfectly.

public static void startServer(){

	log.info("Building and starting the server:");
	builder = new AppiumServiceBuilder();
	builder.usingPort(APPIUM_PORT);
	builder.withCapabilities(capabilities);
	builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
	builder.withArgument(GeneralServerFlag.LOG_LEVEL, "error");
	service = AppiumDriverLocalService.buildService(builder);
	service.start();
	log.info("Server started on Port - " + APPIUM_PORT);
}

public static void stopServer() {
	try {
		log.info("Trying to stop the server...");
		service.stop();
		log.info("Success, Server stopped.");
	} catch (Exception e) {
		log.info("Appium server could not be stopped.");
	}
}

#3

Thanks Zuzeac… Let me to try!!!


#4

Hi,
Getting the below issue
Invalid server instance exception has occured: There is no installed nodes! Please install node via NPM (https://www.npmjs.com/package/appium#using-node-js) or download and install Appium app (http://appium.io/downloads.html)

is there any version problem, Since I’m using

Appium V1.6.2
NPM 5.3.0


#5

Make sure you have the paths set correctly. Seems that the path to node is missing.


#6

public static void startServer(){

log.info("Building and starting the server:");
builder = new AppiumServiceBuilder();
builder.usingPort(APPIUM_PORT);
builder.withCapabilities(capabilities);
builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
builder.withArgument(GeneralServerFlag.LOG_LEVEL, "error");
service = AppiumDriverLocalService.buildService(builder);
service.start();
log.info("Server started on Port - " + APPIUM_PORT);

}

In this where you have mentioned the path for Node.js and Appium.js path pls,advice me, below is the my previous code for your refernce,

DriverService service = new AppiumServiceBuilder()
.usingDriverExecutable(new File(“D:/nodejs/node.exe”))
.withAppiumJS(new File(“C:/Program Files (x86)/nodejs/node.exe”))
.withIPAddress(host.split("//")[1])
.usingPort(port)
.withLogFile(new File(“D:/web_selenium”))
.build();
service.start();


#7

Check here : Appium configuration

Your machine is not configured correctly. Code is OK should work with any correctly configure machine.

Can you start appium in CMD/ terminal with comand : appium ?


#8

Yes I ran with same code in terminal including Admin mode, getting the same error what arising in eclipse.

my doubt is , where you are pointing your node and appium js locations,

log.info(“Building and starting the server:”);
builder = new AppiumServiceBuilder();
builder.usingPort(APPIUM_PORT);
builder.withCapabilities(capabilities);
builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
builder.withArgument(GeneralServerFlag.LOG_LEVEL, “error”);
service = AppiumDriverLocalService.buildService(builder);
service.start();
log.info("Server started on Port - " + APPIUM_PORT);


#9

As I said, I’m pretty sure you didn’t configured your PC correctly.
Make sure you configured it correctly.


#10

Hi Zuzeac First of all thanks for your continuous support from your end…I have completed my appium automation work which means i set configuration and all in the starting stage itself also my script i working till nw…the only thing i’m trying to include here is, the server should be opened automatically by using script…

So the application is work as i expect if starts Appium server by manually.

my doubt is ,

builder = new AppiumServiceBuilder();
builder.usingPort(APPIUM_PORT);
builder.withCapabilities(capabilities);
builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
builder.withArgument(GeneralServerFlag.LOG_LEVEL, “error”);
service = AppiumDriverLocalService.buildService(builder);
service.start();

where you are using node and appium js path and all.


#11

Hi,
Basically the AppiumServiceBuilder and AppiumDriverLocalService do the job for you.
Do you have appium desktop or you install it from cmd with this command: npm install -g appium ?

Try a different approach from here:


#12

Yep Zuzeac, I have Appium desktop app, But not installed through npm so that we get that error as you stated (Which means not configured properly), Let me to uninstall the appium and reinstall the same using npm.


#13

That’s the problem, give feedback after you install Appium through npm command.
You can also keep the appium desktop version


#14

Great Zuzeac!!! Its working for me…Thanks a lot for your effort!!! Let me know if any clarification needed in this!!


#15

Hi ZuZeac,
Appium server getting struck in in a certain page while running automation , even-though used implicit wait (200 sec)…its waiting…then show its web element exception. Any idea in this, also tried with driver.openNotifications() too00…


#16

@Satheesh_Kumar, what version of Appium do you have? and java client? I recommend you to update to the latest versions.
Implicit wait is not recommended, you should set the implicit wait to a minimum of 2-3 sec and wherever you need to wait for an element or for a page to load use explicit wait .
Oh, and the server gets stuck always in the same page?


#17

Yes server get struck at the certain screen it self
Twice or thrice out of 10 times…sorry used before explicit wait 200 secs…wrongly mentioned as implicit wait