It doesn't always scroll to the same place, Appium Android - appium

I am using the following method while scrolling android. but It doesn't always scroll to the same place, even though it's on the same page. what would be the reason.
public void ScrollToCampaignNotice(){
try {
getDriver().findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).flingToEnd(35)"));
} catch (InvalidSelectorException e) {
// ignore
}
}
At the same time, I tried the following method differently, it has the same problem.

You could scroll to exact element instead of flinging 35 times.
Here is an example how to scroll to specific text that is visible:
new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("<include your text>").instance(0))
You can also scroll to an element that has specific id like this:
new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId("<insert element ID here>").instance(0))

Related

Swiping to a element not present in dom in appium ios

I have an app where a particular parent that has n elements lets say 10 elements (tiles) and only 5 are present in the dom and visible in the current screen. The next 5 would appear in dom/screen on swiping up. How do I swipe to a particular element say 7th element?
I'm not able to get find the element by id/name as the element is not in dom so I'm not able to use swipe until visibility of an element. also, the number of such elements varies based on how the backend system is configured so I cannot make a fixed number of swipes. Also since I do not know the last element in the parent I'm at risk of running into an infinite loop if the particular element is not present in the app (due to a bug).
Please help on how to solve this.
You can use following methods to scroll down until expected element. To avoid the infinite loop you can keep count of while loop.
public void scrollDown()
{
TouchAction action = new TouchAction((AppiumDriver)driver);
action.press(new PointOption().point(300, 701)).waitAction(newWaitOptions().waitOptions(Duration.ofSeconds(2))).moveTo(new PointOption().point(300, 441)).release();
action.perform();
}
public void scrollTillElement(By element)
{
int countofLoop = 0;
List<WebElement> elements = driver.findElements(element);
while (elements.size()==0)
{
countofLoop++;
scrollDown();
elements = driver.findElements(element);
if(countofLoop==20)
{
break;
}
}
}

Flutter: How to prevent banner ad from showing if view is already disposed

I am currently experimenting with banner ads from the firebase_admob plugin. The process to show and dispose them is pretty straightforward, I do it in initState() and dispose().
The code to create and display the add looks like this:
_bannerAd = createBannerAd();
_bannerAd
..load().then((loaded) {
if (loaded) {
_bannerAd..show();
}
});
However, as I am calling show() asynchronously, it is possible that the view was already closed when the ad is being shown (i.e. by clicking back button really fast). In that case, the dispose() method will never be called and the ad will be "stuck" on the bottom of the screen.
How can I solve this problem? Am I using the banner ad wrong or is it possible to detect if the view was already changed? I tried using the "mounted" property of the state but it didn't seem to work.
Just check "this.mounted" property of state class before showing the add.
_bannerAd = createBannerAd();
_bannerAd
..load().then((loaded) {
if (loaded && this.mounted) {
_bannerAd..show();
}
});
From https://github.com/flutter/flutter/issues/21474#issuecomment-535188820, that's a little hack but it works for me.
You can add a little delay in your dispose method like this:
static void hideBannerAd() {
Future.delayed(Duration(milliseconds: 500), () {
if (_bannerAd != null) _bannerAd.dispose();
_bannerAd = null;
});
}
500 milliseconds is enough.

ICommand not always firing when tab selected

I have a simple ActionBar with 3 tabs attached. When a tab is clicked, the fragment is inflated and the view shows. The tab being click event is fired using an event. Initially, the first fragment is inflated, but the others respond and inflate if clicked.
If I change the event being fired to an ICommand, only the last fragment is inflated and then if I click on the first tab, that and the last are inflated. Never the second.
My code is this
ICommand TabClicked
{
get
{
return new RelayCommand(() =>
{
tab.TabSelected += (object sender, ActionBar.TabEventArgs e) => TabOnTabSelected(sender, e);
});
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
fragments.Add(new TODFragment());
fragments.Add(new ConditionsFragment());
fragments.Add(new ResultsFragment());
AddTabToActionBar("Time", Resource.Drawable.crucifix_colour);
AddTabToActionBar("Conditions", Resource.Drawable.weather_colour);
AddTabToActionBar("Results", Resource.Drawable.tod_colour);
}
void AddTabToActionBar(string text, int iconResourceId)
{
tab = ActionBar.NewTab().SetTag(text).SetText(text).SetIcon(iconResourceId);
/* uncomment and comment out one of the two below to see the difference in operation */
tab.TabSelected += TabOnTabSelected;
//tab.SetCommand<ActionBar.TabEventArgs>("TabSelected", TabClicked);
ActionBar.AddTab(tab);
}
void TabOnTabSelected(object sender, ActionBar.TabEventArgs tabEventArgs)
{
var tabNo = sender as ActionBar.Tab;
var frag = fragments[tabNo.Position];
tabEventArgs.FragmentTransaction.Replace(Resource.Id.frameLayout1, frag);
}
Am I missing something fundamental here in the difference between ICommands and Events or is it something else?
I'm using Xam.Android and MVVMLight
I found the answer. When I create the partial class I define the UI objects like this (or something like this at least)
EditText myEditText;
EditText MyEditText = myEditText ?? (view.FindViewById<EditText>(Resources.Id.myEdit);
This is fine, but it does mean that once defined, it doesn't get redefined.
Not a problem if the UI is not really going to change, but every time an action tab is pressed, the fragment is refreshed. Only problem is the Id isn't changing as myEditText is not null.
The answer is add a method in the UI definition code that nulls the objects then in the main code, when the UI disappears, call the nulling method. Everything works then

UIAutomation: Check if element exists before tapping

We have a iPad app which includes a two-column news reader. The left view contains the list of news of which some link directly to a news and some push another view controller with another list of news. This will also cause a UIButton to be set as the leftBarButtonItem of the navigation bar. If we are on first level, a simple image that cannot be tapped will be the leftBarButtonItem.
My goal is now to have a test that taps every news on the first level. If a news leads to a second level list, it should tap the UIButton in the navigation bar.
How can I check, if the leftBarButtonItem is "tappable"? Since it can be either an image or a button, just calling navigationBar().leftButton().tap() will lead to an error if it's an image.
I'm also using the tuneup library if that's any help.
Almost all elements in UIAutomation could be tapped. It does not matter if it is an Image, View or a Button. You will get an error in case an object you are trying to tap is invalid.
How to check:
if ( navigationBar().leftButton().checkIsValid() )
{
navigationBar().leftButton().tap();
}
else
{
//do what you need.
}
or you can check if an object you are trying to tap is a button, for example (not the best way but it works):
if ( navigationBar().leftButton().toString() == "[object UIAButton]" )
{
navigationBar().leftButton().tap();
}
else
{
//do what you need.
}
checkIsValid() is available for all UI elements. It will return true if an object exists.
toString() will return [object UIAElementNil] if element is invalid or will return [object UIAButton] or [object UIAImage].
Also try to use Apple documentation:
http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Reference/UIAElementClassReference/UIAElement/UIAElement.html
You can simply use
if (navigationBar().leftButton().exists)
{
navigationBar().leftButton().tap();
}
else
{
//do what you need.
}

Blackberry Button not working in HorizontalFieldManager

My workFlow is like this ... I have taken Three HoriZontalManager one for holding theBackgroundImage of the button and two HoriZontalManager to hold the CustomButton and i am adding the main hfm which hold the button and the background image at top and then i have added the list in a VerticalfieldManager but i dont get the button Working the focus always remains on the list Field. Now when I click on the Button the focus always resides on the First row of the list Field so it always show me the picker which is actually i have implemented on the first row of listfield. How can i Solve it ..
Thanks in Advanced..
Please help.
I have solved This issue ... I had to check that if the focus is on the button then do my work else the list field will be invoked and it solved the issue. And it works for touchScreen simulator as well as trackpad devices.
protected boolean navigationClick(int status, int time) {
// if the row select do something with it
// for first row which is time
if(backCustomButton.isFocus()) {
UiApplication.getUiApplication().pushScreen(new saveScreen());
}else if (saveCustomButton.isFocus()) {
Dialog.inform("Save Button on focus");
}else
if (_list.getSelectedIndex() == 0){
// Do the ListSpecific things
}

Resources