I'm working with espresso for testing. I'm following Espresso Intents
and problem happened when I try to work like this site. First is validateIntentSentToPackage method:
public void validateIntentSentToPackage() {
user.clickOnView(system.getView(R.id.callButton));
intended(toPackage("com.android.phone"));}
Android Studio display error at "user" and "system". I don't understand this error what does this mean.
Second is activityResult_IsHandledProperly method:
public void activityResult_IsHandledProperly() {
Intent resultData = new Intent();
String phoneNumber = "123-345-6789";
resultData.putExtra("phone", phoneNumber);
ActivityResult result = new ActivityResult(Activity.RESULT_OK, resultData);
intending(toPackage("com.example.unittestdemo")).respondWith(result));
onView(withId(R.id.pickButton)).perform(click());
onView(withId(R.id.phoneNumber).check(matches(withText(phoneNumber)));}
Android Studio display error java.lang.NullPointerException and in line intending(toPackage("com.example.unittestdemo")).respondWith(result);
Please help!!!
Android Studio display error at "user" and "system". I don't understand this error what does this mean.
I guess, you don't have previously declared these variables.
I don't see any logs or whole code of this testing class, so I can only recommend you to check this example
Here you would find all methods which you're looking for in one file.
Also please visit Google Samples - Espresso Testing repository
Related
I've been trying to print with Brother Print SDK 3.5.1 on Android 8.1.0. I keep getting ERROR_WRONG_LABEL.
This is the code I use
void printPdf() {
// Specify printer
final Printer printer = new Printer();
PrinterInfo settings = printer.getPrinterInfo();
settings.printerModel = PrinterInfo.Model.QL_810W;
settings.port = PrinterInfo.Port.NET;
settings.ipAddress = "192.168.1.73";
settings.workPath = "storage/emulated/0/Download/";
// Print Settings
settings.labelNameIndex = LabelInfo.QL700.W62RB.ordinal();
settings.printMode = PrinterInfo.PrintMode.FIT_TO_PAGE;
settings.orientation = PrinterInfo.Orientation.PORTRAIT;
settings.isAutoCut = true;
printer.setPrinterInfo(settings);
// Connect, then print
new Thread(new Runnable() {
#Override
public void run() {
if (printer.startCommunication()) {
PrinterStatus result = printer.printPdfFile("/storage/emulated/0/Download/hello world red.pdf", 1);
if (result.errorCode != PrinterInfo.ErrorCode.ERROR_NONE) {
Log.d("TAG", "ERROR - " + result.errorCode);
}
printer.endCommunication();
}
}
}).start();
}
My printer model is QL-810W and I use the black and red W62 roll.
I've tried the Sample Application, where setting W62RB in labelNameIndex prints fine.
Changing the roll for different one with different width didn't help.
I've also tried iterating over numbers 0 to 50 and using them as labelNameIndex.
Based on this thread, I thought that the issue may be in specifying the workPath attribute. Setting workPath to getContext().getCacheDir().getPath() results in ERROR_OUT_OF_MEMORY instead of ERROR_WRONG_LABEL. Not specifying workPath and adding <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> to AndroidManifest.xml results in ERROR_WRONG_LABEL
EDIT
I've modified the Brother Sample app and uploaded it to GitHub. The app now launches Activity_PrintPdf.java by default where I inserted my printing code with hardcoded values at the beginning of onCreate method - this works fine and prints the PDF file as expected.
Then I created a new Empty Activity project in Android Studio, copy pasted the library, added the imports to build.gradle and copy pasted the permissions into AndroidManifest.xml. Then I copy pasted the printing code at the beginning of onCreate method in MainActivity.java. Running the app results in ERROR_WRONG_LABEL.
This is the modified working example app and this is the one that results in the error. I want to use the code as native module that I call from my React Native app, so it's important that I manage to set up the printing code from scratch rather than modifying the existing example app.
EDIT 2
I've inspected the library with a debugger: when executing printer.setPrinterInfo(mPrinterInfo) the library internally calls private boolean createWorkPath(String dirPath) of Printer object. On return from this method, the debugger shows Source code doesn't match the bytecode and seems to forget the created directory. This also internally sets mResult.errorCode = ErrorCode.ERROR_WORKPATH_NOT_SET. However, instead of rising any error here the code just silently proceeds, which later results in ERROR_WRONG_LABEL when trying to print. Running the same code snipper in the modified Sample app works fine.
I'd be grateful if you could help or suggest what to try next.
Thank you!
I've now fixed the issue, which was that the Brother library silently failed to create a temporarily folder and instead of reporting an error, it continued and failed later to read the label information. Based on this thread, it is now required to specify runtime file read and write permissions as opposed to the compile-time ones in AndroidManifest.xml.
Adding
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
at the beginning of onCreate before the printing code fixed the issue.
I am doing the dagger tutorial for android in java, and they told me to create this class:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
CommandRouterFactory commandRouterFactory =
DaggerCommandRouterFactory.create();
CommandRouter commandRouter = commandRouterFactory.router();
while (scanner.hasNextLine()) {
commandRouter.route(scanner.nextLine());
}
}
}
I wrote my own code to try to see what the scanner is pulling from, but nothing shows up. I am just wondering, if System.in is some sort of command line input, and if so, how would I see that show up? I tried typing in the terminal built into android, but that doesn't produce any output either.
Finally, where do you even get a class like this to run in android? I'm only used to having code run at least from the starting point of a main activity.
Here's the link to the tutorial - it doesn't help much with setting up
https://dagger.dev/tutorial/02-initial-dagger
I'm trying to add a BackdoorMethod to a Xamarin.Forms application to bypass the login (IDP - opened in chrome browser) step. I have the feeling that the method is not getting triggered, but not sure, and I don't know how could I make sure about it.
I've read the documentation here: https://learn.microsoft.com/en-us/appcenter/test-cloud/uitest/working-with-backdoors
Check this thread: https://forums.xamarin.com/discussion/85821/xamarin-uitest-backdoor-on-droid-with-splash-screen-how-do-i-access-my-mainactivity
Checked this example: https://github.com/brminnick/UITestSampleApp/tree/master/Src
In the MainActivity.cs file I've defined the BackdoorMethod:
[Preserve, Export(nameof(BypassLoginScreen))]
public string BypassLoginScreen()
{
// some additional code here. the code is working, when I called it
// directly from OnCreate it was executed without any error
return "called";
}
From the test case i'm trying to invoke it like:
public constructorMethod(Platform platform)
{
this.platform = platform;
app = AppInitializer.StartApp(platform);
var result = app.Invoke("BypassLoginScreen"); // result == "<VOID>"
}
I'm not getting any error message, the method simply not called, or not returns anything. (or i don't know what's happening there with it, because breakpoint also not working as the app started from the device)
This should be already working. I have similar code and it works for me.
you can add inside your function
Android.Util.Log.WriteLine(Android.Util.LogPriority.Info, "BypassLoginScreen", $"Some text as info");
And observe the result in Device Logs, Filter by BypassLoginScreen to see if there is any log created with the tag BypassLoginScreen
I googled some explanations but I don't understand them without exact example.
I would like to run the following code from Libgdx touchdown() thread.
public void goToTheMarket() {
Intent goToMarket = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("market://details?id=com.myapp"));
startActivity(goToMarket);
}
The code has not compilation errors only in
my "class MyActivity extends AndroidApplication".
It is visible as MyActivity.GoToTheMarket in Libgdx thread only as static.
But I got error that it is impossible to run static from non-static
If I create a class and run it as
GoToTheMarket goToTheMarket=new GoToTheMarket()
then I got looper.prepare run time error.
Please write the full code how to run my code.
Many thanks!!!
You can take at IntegratingAndroidNativeUiElements3TierProjectSetup
It's a great guide to help integrate android native ui and libgdx.
try below code.
context.startActivity();
I am trying to integrate kiip in my android app . I have downloaded the latest sdk and sample example from https://kiip.me/ developers site . Also ,I have created a new app in kiip.me site.
Everything is fine but the problem is , I am getting KPResource null so showing No Promo .
Here is the listner that I am using in onStart() method:
public void onStart() {
super.onStart();
// The Activity context has been created by now, so start a new session.
KPManager.getInstance().startSession(mStartSessionListener);
}
private KPRequestListener<KPResource> mStartSessionListener = new KPRequestListener<KPResource>() {
public void onFinished(KPManager manager, KPResource response) {
if (response != null) {
toast("Start Session Finished w/ Promo");
} else {
toast("Start Session Finished No Promo");
}
manager.showResource(response);
// Start retrieving user's location
new LocationHelper(ExampleApplication.this).requestLocationUpdates(mLocationListener);
}
Here the response is always null , so getting the message : Start Session Finished No Promo . If anyone has got similar problem then please share your views.
Thanks in advance.
Have you enabled promos for test devices in the dashboard on https://kiip.me?
It sounds like it could be a settings issue on the server side. Try logging in and switching promo frequency and adding your test device.
Finally, the issue has been resolved. I think the problem was with my device , when I tested it next day with some other device, It worked for me.