How to force webdriver to install app before launching it - javascript

I recently bumped on a problem regarding installing / updating app on the device before running tests.
driver.init(desired)
It seems that when you initialize a new session, if the app is not installed, it will install it. However when an older version of the app is already installed, it won't update it.
it('initialise appium session', function(){
return actionsManager.startSession(desired);
});
it('installs app', function(){
return actionsManager.installApp(context.desired.app);
});
I've tried the above code but it launches the app first, and then it doesn't seem to install the app (I can see logs on appium side and it replies immediately a status 200).
Ideally the test would first clean current app, install new one and finally launch it. Could someone give me a clue on how to do that ? Thanks !
ps: I'm using mocha as a test runner, and javascript bindings on the webdriver side. Appium server is running on a mac and I'm launching the script from a PC.

The problem was that appium server had been launched with "--no-reset" argument.
Appium's default behavior is to update the app at each new session. The "--no-reset" flag was preventing it to do so. I originally used it on my dev machine so that I could reduce the waiting time for each test.
So in the end there is nothing specific to do in the code, it's just a matter of appium server configuration.
Note: it appears that this flag will be deprecated on appium 1.5, see documentation.
It will still be possible to setup this behavior by using a new "–default-capabilities" flag.

Related

React native App fails to launch after buid

guys, I'm totally new here and I'm hoping I really get the help I need 🙏🏼
I built an apk package with eas build -p android --profile test, the build was successful. App installed successfully on mobile but it fails to open. once clicked, it just opens then immediately closes back.
I’m all new to expo and development in general.
I saw a documentation to run the app via npx expo start --no-dev --minify ; as this mimics production mode in local server. I did that and It returns a “uncaught error: java.lan.exception:failed to load all assests” I reloaded like 4 times and app opens fine after that. And does not bring the error again when I rebundle app.
However I have observed it brings the error (java.lang.exception:failed to load all assests) once everytime I stop and restart the expo server.
But app doesn't launch at all when I build to standalone.
Please help here, how do I fix this? 🙏🏼
This is the way I solved it
Follow the steps.
1.) Turn on USB Tethering & USB Debugging Mode in your mobile.
2.) Connect your mobile to your laptop through USB.
3.) Verify the connection options on your device, I just added WIFI bridge / I assume i the same as wifi debugging and then, restarted the device and run expo and it worked.
Above solution is worked for me.

Published Expo app can't make network calls

I am trying to publish an update to my app after upgrading the SDK from 27 to 32. The app works fine when I do expo start and run it on the emulator. But, when I do expo publish the finished app can't make network calls. Then, I realized you couldn't do expo publish if you update SDK (it still push the update somehow though), so I built the APK for Android. Thing is, the APK file nor the expo publish update work. It can't make network calls to pull user info for instance, but it works just fine with expo start.
Any ideas on what this could be or how can I troubleshoot it? I went back to the commit with SDK 27, built it and still, the app can't make network calls. It is also the first time I build this app from this computer.
Did you check if you are using the __DEV__ constant somewhere?
Both the APK and the APK in the market are now on __DEV__ == false.
Are you sure that the app is not making calls?
Are you sure that they don't reach the server?
Are you sure that is not the server that is rejecting?
Did you try to make the calls outside of the app using a program like Postman?

Error calling Appregistry.runApplication in react-native

I am trying to run a react-native app on android emulator, but I am getting an error like
Error calling Appregistry.runApplication
AVD: 'Nexus_5X_API_23(AVD) - 6.0
OS:Windows 10
Please help on this?
I had almost the same problem you currently have a few days ago. For me it was a real device.
From all my research, the solution that worked for me is the following :
When you launch your app by typing react-native run-android, the error appears.
So, reach your directory containing "adb.exe" ( for me it was C:\Users\username\AppData\Local\Android\Sdk\platform-tools\ )
open a terminal from here. And type adb reverse tcp:8081 tcp:8081
Then, by reloading the app on the phone, it should work.
I hope this will help you !! ( if not, shame on me )
Cheers ;)
EDIT :
I've find a more convenient solution to solve this problem.
When you launch your "react-native run-android" you might have a comment saying "adb is not recognized as internal or external command..."
Well, instead of manually using the adb command, you can add an environment variable leading to the adb.exe.
Just get to the "Control Panel" > "System and Security" > "System" > "Advanced System Settings".
From here, click on "Environment Variables". Search for the "Path" variable in the "System Variables" section. Click on it and press the "Edit" button.
There you can add a new path to this variable. Just click the "New" button and write the adb.exe path. For exemple C:\Users\username\AppData\Local\Android\Sdk\platform-tools\
(For the oldest versions of Windows, you'll have to add ";C:\Users\username\AppData\Local\Android\Sdk\platform-tools\" to the content.)
This is it, now the adb reverse tcp:8081 tcp:8081 command will be ran automatically upon building.
Hope this will even more helps you !
I had the same issue, my fix was to run
$ react-native start
in the background then run
$ react-native run-android
According to me this error comes when:
1) You did not run the packager at the right place i.e, you hit the wrong folder to run react-native packager so just navigate to your project's directory and run react-native start.
2) when you code something wrong with respect to Appregistry module.
3) Shutdown everything Xcode, packager, simulator etc and restart it again.
4) From the error one thing strikes in my mind is the name of the module
AppRegistry.registerComponent('AppName', () => componentName)
matches with the #"AppName" on your AppDelegate.m on the call for
[[RCTRootView alloc] initWithBundleUrl:...
moduleName:#"AppName"
launchOptions:...
5) As we are using react's component so we need to give the first character of our class name with caps on.
6) Let's see what's wrong in index.android.js and index.ios.js
Cheers :)
Finally, I got it working.I created a new AVD
Nexus6 API 23
.Earlier I was trying with Nexus5x API 23.Thanks all
I had same problem. It occurs that McAffee was on port 8081 and block packager.
My solution:
react-native start --port your_port
In android emulator, Command + M show dev menu, click on "Dev Settings" and then click on "Debug server host and port" and set it to your_ip:your_port.
Then
react-native run-android
In my case (after, of course, going through everything I could find here and elsewhere), I realized I had turned my WiFi off on my phone...doesn't work like that! Hope it helps someone
I had the same issue and was able to resolve it by setting my local computer as the debug server in the android emulator. Open the android emulator, Command + M to bring up a menu, then click on "Dev Settings" and then click on "Debug server host and port" and set it to 127.0.0.1:8081. Then from within you project directory run react-native run-android. I hope this helps.
Make sure that port 8081 is available. In my case One of my services is running on Port 8081(tomcat webserver).
I was having the exact same issue (because this is a very generic message) but the problem was different. In my case it was a newly created project, the emulator wasn't working but a real device did work.
My problem was the limit of watchers inotify can handle on Linux by default, which is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes back to applications and it's widely used, including android studio and react native; by the time I was trying to execute react-native run-android all of the watchers were allocated on my system, causing the process to fail on this same message.
To change the max amount of watchers inotify can handle, you need to edit the file sysctl.conf, which will be usually located at /etc/sysctl.conf or /etc/sysctl.d/custom_name.conf and add the following line:
fs.inotify.max_user_watches = 5242881
After writing the file you need to execute sysctl -p filename.conf where 'filename.conf' is the path and name wherever you saved the .conf file for sysctl. Once changes are applied everything should work as expected.
I too had the same problem. I solved the problem to run on real device.
As told by Mr Jedi, McAffee blocked the port 8081. So I have modified Project-Folder>\node_modules\react-native\local-cli\runAndroid\runAndroid.js file's function from
function tryRunAdbReverse(device) {
try {
const adbPath = getAdbPath();
const adbArgs = ['reverse', 'tcp:8081', 'tcp:8081'];
to
function tryRunAdbReverse(device) {
try {
const adbPath = getAdbPath();
const adbArgs = ['reverse', 'tcp:8081', 'tcp:3040'];
and started the application on
react-native start --port 3040
For me I just needed to add the platform tools to my Path environment variable so that react-native can start the adb server.
I was getting:
'adb' is not recognized as an internal tool or program
To fix this I added the following to my Path environment variable.
C:\Users\<Username>\AppData\Local\Adnroid\sdk\platform-tools
Then running react-native run-android worked!
I know this question has been given so many answers but, I think it's worth it adding my solution, hope this helps someone out there.
In my case the problem was from my virtual machine, although I didn't investigate but by creating a new virtual device the app ran smoothly with no problem.
So just create a new virtual device. :)
I searched for a solution for my registry error for a week and tried all these solutions, and all that was missing was I needed to add in my app.json file under expo:
"platforms": [
"ios",
"android",
"web"
],
So, if all else fails, try to add this into your expo.

how to run tests with karma in another host's browser?

My general problem is how to run unit tests with karma in IE or other browser installed on a Windows machine, while karma is run on a Linux machine, though in the question below I might ask more specific question based on what I've already tried.
Also it may be worth to mention, that I have Windows installed on a Virtual box machine.
I started karma from a terminal, then opened in IE this url: http://10.0.2.2:9876 and saw the karma page in the browser window (though I spotted some quick blink with a red background, I suppose it is related to an error I'll mention further).
After that I tried to run tests with the command: node_modules/karma/bin/karma run config.js in another terminal tab. When I did this I got this error (I get it even when I use Chrome on my Linux host-machine instead IE on the Virtual box guest, so I suppose the error has nothing to do with networking):
You need to include some adapter that implements __karma__.start method!
I googled for this error and found another question: Error: You need to include some adapter that implements __karma__.start method
Supposing that I need to run tests from the same place I started karma-server I tried to redirect the output to another tab:
$node_modules/karma/bin/karma start &> /dev/pts/17 &
$node_modules/karma/bin/karma run config.js
But this did not help. If I try to start server and run tests in a single command, then I do not have time to register IE.
So could anyone please answer any of the next questions:
how to run unit tests with karma in a browser on other machine?
how to get rid of this error You need to include some adapter that implements __karma__.start method!, if the karma server was started in one terminal tab and the run command was issued in another?
how to start the karma server and run tests in separate steps, i.e. issue the karma start and karma run config.js commands instead of karma start config.js?
My regards and sincerest appreciation in advance for any help.
Currently I've found a workaround for this. I start karma with the config file:
karma start config.js
in the config I have singleRun: false.
Then I manually connect my IE instance, and after this I run the tests from another terminal tab. Why this happens I have no idea. The only inconvenience is that I always have browsers' windows open.

How to debug node.js application with Visual Studio 2013 and Node Tools NTVS

I have moved an existing node.js + express project to VS because I prefer the IDE over JetBrains for now (used VS for years, only peeked into Webstorm).
I used NTVS new project->from existing sources and all files were imported successfully.
Afterwards, I opened the project settings of my project and set the node.exe arguments to bin\www, startup file for express.
When I press F5 (debug) I get the console.log messages I have put into the www and app.js files in the opening command prompt, and it looks like the server is running (cannot confirm, I want to debug if everything is working), but the VS debugger directly exits again, it also does not open any page in the browser I selected for debugging.
My node app actually is a REST webservice, so I want to test different URLs with different parameters.
Also, I cannot access the app on the port I specified, though when I directly start it from node.exe I can, even though the command prompt is still open.
(I have NTVS and WebEssentials installed - some operations take a long long time, but I attribute this to NTVS being still an early version.)
Question: how does the Visual Studio debugger stay connected to the node.js application so I can use breakpoints and use any browser then to connect and test different URLs? (Even a breakpoint put on the console.log that gets printed during startup is not being triggered.)
For everyone who asks receives, and the one who searches finds....
(and yes, I did spend a long time searching and trying before posting here..)
Kind of nice to debug node.js server with VS..
hope this helps someone
Edit: The arguments to node.exe can be hard to read in the image. It must be
--debug=<portno>
that is with two dashes (and not just one) to specify the debug port.
Not so much knowledge on expressjs but with a recent release of NTVS 1.0 Alpha, I did find it supports remote debugging which can be also used to debug nodejs app running locally - anyway haven't tried if it works with nodejs app + expressjs but it should.
I followed the step in this video https://youtu.be/-ir9ZB8lUg4 which is
Run your nodejs with node.exe RemoteDebug.js <your_javascript_file>.
RemoteDebug.js has come when you install NTVS.
In Visual Studio, select Debug > Attach to Process
Select Node.js remote debugging for Transport
Enter localhost:5859 for Qualifier
Click Attach
This will put Visual Studio in debugging mode which you can set a breakpoint, do step-in/step-out, very same experience when you use VS to debug .NET app.
Its pretty straight forward with NTVS, you can download required version for your windows from github here
Once you install NTVS, NodeJS project templates will be added
Now, Goto File->New project -> Basic NodeJS Express 3 application (it will be available in javascript project templates)
Now just goto debug and select Start Debugging, add breakpoints where ever required and you can start debugging

Categories

Resources