Launching android emulator using specflow - android

I'm trying to use specflow to create automated testing for a Xamarin project in Visual Studio 2017. I've created a project which uses Nunit and specflow and created a feature file. I've seen it's possible to start a iPhone and do some automated testing, but I'm having problems on how to do this with android. I've read this BDD Test with xamarin where, as I understand, I should add this:
public static IApp StartApp(Platform platform, string simulator)
{
if (platform == Platform.Android)
{
return ConfigureApp
.Android
.StartApp();
}
return ConfigureApp
.iOS
.StartApp();
}
However I cannot figure out how this will help me launch the simulator, and what I should pass as the string to start an android simulator.

Related

Xamarin iOS Crash on Android

We are use Xamarin forms local notifications on our app. with the below line in the code it causes the app the crash
UNUserNotificationCenter.Current.RemovePendingNotificationRequests(requests);
even tho the line should only be run on iOS devices. this is done with the following;
`
if (Device.RuntimePlatform == "Android")
{
}
else
{
UNUserNotificationCenter.Current.RemovePendingNotificationRequests(requests);
}
`
the below error is given with the UNUserNotificationsCenter in the code
System.IO.FileNotFoundException: Could not load file or assembly 'Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' or one of its dependencies.
anyone any ideas??
We have tried completely reimplementing the local notifications, clean and clearing bin/obj. updated both machine and vs to the latest version, updated frameworks.
built on VS Mac 2022 17.3.6
android framework 13.0.0.0

App crashes on Launch when made as system application

I developed an application that uses DJI SDK. When installed as an system application it crashes on Launch because its not able to load the libraries. It works fine when installed as normal application.
Steps followed to make system application
1)Rooted the device
2)Copied the .apk file to system/app directory
3)Rebooted the device
4)App was installed as default application but crashed on Launch
After commenting out the following line related to DJI SDK and followed the same steps as above. It worked fine as system app.
Helper.install(context);
The implementation of Helper class which is in DJI SDK is as below:
public static void install(Application app) {
Object var1 = null;
try {
System.loadLibrary("DexHelper_sdk");
if (PPATH != null) {
System.load(PPATH);
}
} catch (Error var3) {
;
}
String app_dataDir = app.getApplicationInfo().dataDir;
DexInstall.install(app, new File(app_dataDir + "/.cache_sdk/sdkclasses.jar"));
}
As far as my understanding the crash is because the system is failing to load the libraries.
My gradle looks similar as in the following link:
https://github.com/dji-sdk/Mobile-SDK-Android/blob/master/Sample%20Code/app/build.gradle
this issue has been fixed since 4.6 version of Android MSDK, pls try to update to the later version, right now the 4.7.1 has been released.

SetUp : System.Exception : ApkFile or InstalledApp has not been configured

i'm Working on xamarin forms simple app (CreditCardValidator) i downloaded the app from [https://developer.xamarin.com/samples/test-cloud/Quickstarts/CreditCardValidator.Droid/]
Now is it possible to start Running Test Method without providing path to (.apk File) ... if not i want to know how to start VS emulator just after Running Test method ( running test method to automatically launch VS emulator ) ?
public class Tests
{
AndroidApp app;
[SetUp]
public void BeforeEachTest()
{
app = ConfigureApp.Android.StartApp();
}
[Test]
public void CreditCardNumber_TooShort_DisplayErrorMessage()
{
app.WaitForElement(c => c.Marked("action_bar_title").Text("Enter Credit Card Number"));
app.EnterText(c=>c.Marked("creditCardNumberText"), new string('9', 15));
app.Tap(c => c.Marked("validateButton"));
app.WaitForElement(c => c.Marked("errorMessagesText").Text("Credit card number is too short."));
}
}
If there is only one device attached to the computer, and no running simulators, then UITest will automatically run the tests on the device.
This would also apply to an emulator in the sense that it would have to be already up and running.
Source: https://developer.xamarin.com/guides/testcloud/uitest/working-with/testing-on-devices/android/#Programmatically_Declaring_the_Device
However since you might need to boot an emulator up, you can do the following:
There is a tool called emulatorcmd.exe that you can use. It is found in the following directory on Windows:
C:\Program Files (x86)\Microsoft Emulator Manager\1.0
You can use emulatorcmd.exe list /sku:Android /type:device /state:installed to get a list of available emulators that are installed.
You can then use emulatorcmd.exe launch /sku:Android /id:<id> which will launch that specific emulator.
https://blogs.msdn.microsoft.com/visualstudioalm/2014/11/12/introducing-visual-studios-emulator-for-android/

How to run Xamarin UI tests on Android emulator

How to run Xamarin UI tests on Android emulator?
Always I run my test on real devices, but for CI I need tests on emulator, but I don't know how and google didn't give me a specific answer
public class AppInitializer
{
private const string ApkPath = #"..\..\..\mob\mob.Droid\bin\Release\myApp.apk";
private const string AppPath = "mob.iOS.app";
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
return ConfigureApp
.Android
.EnableLocalScreenshots()
.ApkFile(ApkPath)
.StartApp();
}
return ConfigureApp
.iOS
.EnableLocalScreenshots()
.StartApp();
}
}
In the documentation and as #tequilaslammer mentions briefly:
Unlike testing on iOS, Xamarin.UITest will not automatically start the Android Emulator. It is necessary to have an Android emulator running or an Android device already connected. If there is more than one device or emulator connected, it will be necessary to provide the serial ID of the device/emulator that should be used to run the test.
Source: https://developer.xamarin.com/guides/testcloud/uitest/intro-to-uitest/#Initializing_AndroidApp
I highly recommend that you read through the complete documentation on this topic as there are a few "gotchas" that will need to be considered for your situation:
https://developer.xamarin.com/guides/testcloud/uitest/intro-to-uitest/

Xamarin.UITests Android Device Not Detected or Not Working

I can't run Xamarin.UITests on any Android simulator/emulator. Any suggestions? I get the following errors when I try:
Google Emulator:
SetUp: System.Exception: Unable to run on a physical device without activation.
The full version is available for Xamarin Test Cloud customers, for more information contact sales#xamarin.com
If you are already a Xamarin Test Cloud customer, you can provide your api in one of the following ways:
* Adding it ConfigureApp using the ApiKey method
* Setting the XTC_API_KEY environment variable
* Adding the following attribute to your Properties/AssemblyInfo.cs file: [assembly: Xamarin.UITest.TestCloudApiKey(YOUR_API_KEY)]
* Place an xtc_api-key file containing your api key in an upstream directory from the test assembly
Xamarin Android Player:
SetUp: System.Exception: No devices connected
GenyMotion:
SetUp : System.Exception : Failed to execute: /users/erikandersen/Library/Developer/Xamarin/android-sdk-macosx/platform-tools/adb devices - exit code: 1
cannot bind 'tcp:5037'
ADB server didn't ACK
* failed to start daemon *
error:
adb server is out of date. Killing…
After updated GenyMotion to 2.3.1, I now get the following error:
SetUp: System.Exception: App Installation failed with output: 12050 KB/s (11199602 bytes in 0.907s)
pkg: /data/local/tmp/final-xxxxxx.apk
Failure [INSTALL_FAILED_CPU_ABI_INCOMPATIBLE]
NUnit Code
AndroidApp _app;
public string PathToAPK { get; set; }
[TestFixtureSetUp]
public void BeforeAll ()
{
var path = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
var info = new FileInfo(path);
var directory = info.Directory.Parent.Parent.Parent.FullName;
PathToAPK = Path.Combine(directory, "Android", "bin", "Debug", "Demo.Android.apk");
}
[SetUp]
public void BeforeEach ()
{
_app = ConfigureApp.Android.ApkFile (PathToAPK).StartApp ();
}
[Test]
public void TestInvalidEmail ()
{
_app.EnterText (c => c.Class ("UITextField"), "");
}
TestInvalidEmail() is never called because NUnit fails on
_app = ConfigureApp.Android.ApkFile (PathToAPK).StartApp ();
Background:
I'm using Xamarin.UITests for an iOS/Android application I'm developing and we're having issues with the Android side of things. iOS works fine. I've written each test twice, once in C# and once in Ruby using calabash, in order to isolate the issue. Calabash works fine, but any C# NUnit Test Project fails to connect to any emulator I try launching.
What I've tried:
Making sure an emulator is already running before I run the tests
Making sure only 1 emulator is running
Restarting the adb server
Trying multiple types of emulators (i.e. Xamarin Android Player, Gennymotion, and the Google Emulator)
So, after several hours of working on this, this fixed it:
Upgrade GennyMotion to 2.3.1
Delete my old GenyMotion Simulator (Nexus 4) and create a new one
Add support for all ABIs in my Android Build settings
Android Project > Options > Android Build > Advanced Tab > Supported ABIs > Check "armeabi, armeabi-v7a, x86" > OK
Generate a new .apk file via the terminal (while inside the Android project directory)
/usr/bin/xbuild /t:Package /p:Configuration=Release .csproj
Resigned the .apk via calabash-android
calabash-android resign ./bin/Release/.apk
In Xamarin Studio, set my Startup Project as the my UITest project
Launch GenyMotion simulator
Ran the tests under the Debug configuration with only the GenyMotion simulator active
And it worked! I still can't run UI tests with the Google Emulator or the Xamarin Android Player. Funny thing is, I also can't debug my Android project using GenyMotion. It's only good for UITests. SO here's my current setup:
Xamarin Android Player - Normal debug
GenyMotion - UITests
I had the same problem and fixed by setting the ApiKey when setting ConfigureApp.
[SetUp]
public void SetUp()
{
_app = ConfigureApp.iOS.AppBundle(PathToIPA).ApiKey("YOUR_API_KEY_HERE").StartApp();
}
As in here. Just put your ApiKey there.
Note: I didn't have this problem with Xamarin Android Player. I didn't have this problem with AVD running an Android 5.0 emulator. I only had this problem with AVD running an Android 4.0.3 emulator.

Categories

Resources