How to test options menu using AndroidX fragment test? - robolectric

Setup
Robolectric: 4.2.1
AndroidX fragment-testing: 1.1.0-alpha05
Background
With AndroidX comes new ways of testing fragments:
Source:
https://developer.android.com/training/basics/fragments/testing
Robolectric is compatible with AndroidX and intends to deprecate functionality that mirrors AndroidX capabilities.
Source:
http://robolectric.org/androidx_test/
But in Robolectric you could test the behavior of the options menu, e.g. with something like this (I know it looks cluttered but the FragmentController doesn't work well in some cases):
#Test
public void OnPrepareOptionsMenu_WhenX_ShowsMenuActionsCorrectly() {
setupX();
final Bundle instanceState = new Bundle();
instanceState.putString(FooActivity.ARG_UUID, x.getUuid());
final FooActivity activity = Robolectric.buildActivity(FooActivity.class)
.create(instanceState).start().visible().get();
activity.getSupportFragmentManager().beginTransaction()
.add(R.id.container_x_fragment_details, fragment).commit();
final Context context = fragment.requireContext();
final Menu menu = new RoboMenu(context);
fragment.onCreateOptionsMenu(menu, new MenuInflater(context));
fragment.onPrepareOptionsMenu(menu);
assertThat(menu.findItem(R.id.action_y).isVisible(), is(true));
assertThat(menu.findItem(R.id.action_z).isVisible(), is(true));
}
What is the API to do something similar (without using espresso) in AndroidX?
The RoboMenu construct does not seem to play well with AndroidX and this doesn't work:
fragmentScenario.onFragment(fragment -> {
final Activity activity = fragment.requireActivity();
assertThat(activity.findViewById(R.id.y).getVisibility(), is(View.VISIBLE));
assertThat(activity.findViewById(R.id.z).getVisibility(), is(View.VISIBLE));
});

Related

Android 12 In/out-call notification and prominent chip

According to Android 12 documentation there is special in/out-call notification that will show that called 'prominent chip'.
It's looking like that:
I tried to use the code from Android example:
// Create a new call with the user as caller.
Person incoming_caller = new Person.Builder()
.setName("Jane Doe")
.setImportant(true)
.build();
Notification.Builder builder = Notification.Builder(context, CHANNEL_ID)
.setContentIntent(contentIntent)
.setSmallIcon(smallIcon)
.setStyle(
Notification.CallStyle.forIncomingCall(caller, declineIntent, answerIntent))
.addPerson(incoming_caller);
In my application im using NotificationCompat and NotificationCompat.Builder
but this line Notification.CallStyle.forIncomingCall is refer to non Compat versions so I can't use the logic of forIncomingCall to my existing notification.
The NotificationCompat class from AndroidX hasn't been updated to include this new style yet - you can search NotificationCompat on https://cs.android.com to check the latest version of the file, and then you'll have to wait for a new release of the androidx.core:core library.
In the meantime, you'll have to use the platform Notification type if you want to use the new call style:
if (Build.VERSION.SDK_INT >= 31) {
// Use Notification with Notification.CallStyle
} else {
// use NotificationCompat
}

Xamarin Forms (VS2019) + iOS Intents UI: How to access Assets from Extension (IntentsUI)

I used the Xamarin version of SoupChef for Siri Intents. I was able to access the Container's Assets from the SoupChefIntentsUI.IntentViewController by requesting the bundle by identifier (using the BundleIdentifier of the main App) and then I just loaded the image by passing the bundle
CGSize DisplayOrderConfirmation(Order order, OrderSoupIntent intent, OrderSoupIntentResponse response){
/* unrelated code */
//this line work in the SoupChef example but
//On Xamarin.Forms this returns null
var containerBundle = NSBundle.FromIdentifier("com.something.SoupChef");
//always returns null because it seems it looks into the IntentsUI.Assets
var iconNull = UIImage.FromBundle("AppIcon");
//it returns the icon from the SoupChef.Assets
var iconNotNull = UIImage.FromBundle("AppIcon", containerBundle, configuration: null);
/* unrelated code */
}
I was also able to retrieve the AppIcon by creating the NSBundle doing something like this (in case you didn't want to assume that the bundle identifier names don't follow the Apple standard where the Container and the extensions have the same bundle identifier with the exception of the last segment)
CGSize DisplayOrderConfirmation(Order order, OrderSoupIntent intent, OrderSoupIntentResponse response){
/* unrelated code */
Class GetClassForType (Type type)
{
IntPtr myClassHandle = Class.GetHandle (typeToLookup);
if (myClassHandle != IntPtr.Zero)
return new Class (myClassHandle);
else
return null;
}
//this returns the bundle identifier of the SoupChef app
//(not the SoupChefIntentUI) on the SoupChef example
//on Xamarin.Forms (my project) it returns the IntentsUI identifier
var containerBundle = NSBundle.FromClass(GetClassForType(typeof(SoupChef.OrderIntent)));
//the icon is returned
var icon = UIImage.FromBundle("AppIcon", containerBundle, configuration: null);
/* unrelated code */
}
My problem is that I want to do the same thing on a different project that is using Xamarin.Forms, and the two previous ways that worked for me on the SoupChef project don't work here.
Is there a way to access the Assets set on the App.iOS.Assets or do I have to move them to the shared project where I have the models and other things that both the App.iOS and its Extensions are using?
I noticed that the Bindings (the project where the OrderIntent is) in the SoupChef example has the same namespace as the Container App ("SoupChef"), so I assigned the same namespace in my project with Xamarin.Forms and still nothing.

Auto Fill Web Forms in .net-Core

I am new to .net core.
How can I auto fill forms and submit in dotnet core ?
Please find following sample URLs I want to try
https://mparivahan.in/uyt/?pur_cd=102
Value - 1 = "MH1R"
Value - 2 = "5656"
https://www.filegstrstnow.com/searchGSTTaxpayer
sample Value = "24AADCS0852Q1Z2"
With Regards
I guess you want to automate operations in browser. For this purpose you need a browser automation framework which can be used in you .NET Core 2.0 code. Something like Selenium WebDriver. In this case you code will look like this:
[Test]
public void TestWithFirefoxDriver()
{
using (var driver = new FirefoxDriver())
{
driver.Navigate().GoToUrl(#"https://parivahan.gov.in/rcdlstatus/?pur_cd=102");
driver.FindElement(By.Id("form_rcdl:tf_reg_no1")).Send("GJ01RR");
driver.FindElement(By.Id("form_rcdl:tf_reg_no2")).Send("5656");
driver.FindElement(By.Id("form_rcdl:j_idt36")).Click();
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
// Find element with the result to retrieve value, and so on..
}
}
Note: I didn't check the code above in runtime, it is just for demonstration purposes.
To run Selenium automation code without opening the browser you could use PhantomJS driver instead of drivers for real browsers like FirefoxDriver. Change this line:
using (var driver = new FirefoxDriver())
to:
using (var driver = new PhantomJSDriver())

The recalculated route can not show on map on Here android sdk 3.2 issue

I found an issue on Here Android SDK 3.2, when recalculation happened during navigation, the new route can not be seen on map, only white turn arrow on map. The previous SDK version don't has such issue.
It is a new Issue?
You can workaround this regression using NavigationManager.RerouteListener
private NavigationManager.RerouteListener rerouteHandler = new NavigationManager.RerouteListener() {
#Override
public void onRerouteEnd(Route route) {
super.onRerouteEnd(route);
map.addMapObject(new MapRoute(route);
}
...
};
...
NavigationManager.getInstance().addRerouteListener(new WeakReference<>(rerouteHandler));

Problem with Flex DataVisualization Charting components Rendering Labels on Build Server

I'm having a problem with labels disappearing on Flex's datavisualization.swc charts that are built on our build server via ANT and the Flex 3.3 SDK. I've made sure that our license is applied properly on the build server (hence no water marks), and I've made sure the exact same datavisualization.swc was copied from my dev machine into the Flex3.3SDK/frameworks/libs directory.
Any ideas? Could it be a font problem? (Though we're really only using default fonts.)
Here's the problem, missing axis labels on the build server
alt text http://img687.imageshack.us/img687/5038/chartwithmissingaxislab.png
Here's how it's supposed to look with labels (taken on my local development machine)
alt text http://img683.imageshack.us/img683/1504/chartwithaxislabels.png
I got it working using the helpful information I found at the Flex Coders archive.
Basically, in an initalize event handler, I added the following code:
var ccClassFactory:ContextualClassFactory = new ContextualClassFactory(ChartAxisTextLabel);
ccClassFactory.moduleFactory=this.moduleFactory;
var hAxisRenderer:AxisRenderer = new AxisRenderer();
hAxisRenderer.axis = hAxis;
hAxisRenderer.labelRenderer=ccClassFactory;
var vAxisRenderer:AxisRenderer = new AxisRenderer();
vAxisRenderer.axis = vertAxis;
vAxisRenderer.labelRenderer=ccClassFactory;
lineChart.horizontalAxis=hAxis;
lineChart.verticalAxis=vertAxis;
lineChart.horizontalAxisRenderers = [ hAxisRenderer ];
lineChart.verticalAxisRenderers = [ vAxisRenderer ];
Also, I had to create the class:
public class ChartAxisTextLabel extends Label
{
public function ChartAxisTextLabel()
{
super();
}
override public function set data(value:Object):void
{
super.data = value;
text = value.text;
}
}

Resources