Environment:
AutomationName : UIAutomator2
Appium: 1.22.3
Appium Java-client : 8.2.0
Scenario:
Registration screen, once all the data provided and submit -> loader displayed.
If everything is proper, then next screen displayed else stays on registration screen.
Registration.java
public void enterRegistrationCardDetails(String strCreditCardNumber, String strExpDate, String strDateOfBirth) {
enterCreditCardNumberToRegister(strCreditCardNumber);
selectRegistrationCardExpiryDate(strExpDate);
selectRegistrationDateOfBirth(strDateOfBirth);
clickOnBtnRegisterForRegistration();
new Loader().waitForLoaderToComplete(); // Case 1: When an incorrect data provided, then screen remain on registration screen, This case is working perfectly.
// Case 2: When correct data provided, navigated to next screen, but here keeps waiting for 60 seconds for invisible.
}
Loader.java
public boolean isLoaderDisplayed() {
try {
_mobileElementsProgressBar.isDisplayed();
return true;
} catch (NoSuchElementException | StaleElementReferenceException e) {
return false;
}
}
public void waitForLoaderToComplete() {
if (isLoaderDisplayed()) {
System.out.println("LOADING DISPLAYED");
boolean isLoaderBarDisappear = new WebDriverWait(getBaseMobileDriver(), Duration.ofSeconds(60)).until(ExpectedConditions.invisibilityOf(_mobileElementsProgressBar));
System.out.println("LOADING COMPLETED " + isLoaderBarDisappear);
}
}
Related
I'm new to Mobile Development
I am currently developing a Telephone Directory app from Xamarin Android, in this app, I have 4 Fragment(HomeFragment, AboutFragment, DirectoryFragment, and SyncFragment).
HomeFragment is the first fragment that shows from the app. When I click the item About in the side bar then pressed the back button, it works well because i used AddToBackStack(null) before commit() in the main activity.
But the problem is, let's say I open the app then it shows the HomeFragment fist by default, when i navigate to the AboutFragment, it shows the AboutPage, then if I navigate to the DirectoryFragment next and click the back button, i keep on going back to the AboutPage/AboutFragment, which is what i want to achieve is, it should go back to the HomePage/HomeFragment
In short, what i want to achieve is like the Navigation behavior of the Gmail App.
Anyway this is my code in Main Activity
switch (e.MenuItem.ItemId)
{
case (Resource.Id.nav_home):
FragmentTransaction ft = FragmentManager.BeginTransaction();
HomeFragment home = new HomeFragment();
ft.Replace(Resource.Id.HomeFrameLayout, home);
HideSoftKeyboard();
mDrawerLayout.AddDrawerListener(mDrawerToggle);
ft.AddToBackStack(null);
ft.Commit();
break;
case (Resource.Id.nav_about):
FragmentTransaction ft1 = FragmentManager.BeginTransaction();
AboutFragment about = new AboutFragment();
ft1.Replace(Resource.Id.HomeFrameLayout, about);
HideSoftKeyboard();
ft1.AddToBackStack(null);
ft1.Commit();
break;
case (Resource.Id.nav_etel):
FragmentTransaction ft2 = FragmentManager.BeginTransaction();
GHQFragment ghq = new DirectoryFragment();
ft2.Replace(Resource.Id.HomeFrameLayout, ghq);
HideSoftKeyboard();
ft2.AddToBackStack(null);
ft2.Commit();
break;
case (Resource.Id.nav_refresh):
if (CrossConnectivity.Current.IsConnected)
{
FragmentTransaction ft3 = FragmentManager.BeginTransaction();
SyncFragment sync = new SyncFragment();
ft3.Replace(Resource.Id.HomeFrameLayout, sync);
HideSoftKeyboard();
ft3.AddToBackStack(null);
ft3.Commit();
}
else
{
Toast.MakeText(this, "Please connect to the internet to sync records.", ToastLength.Long).Show();
}
break;
You can override the OnKeyDown method like following code.
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode.Back)
{
FragmentManager fragmentManager = this.FragmentManager;
int count = fragmentManager.BackStackEntryCount;
for (int i = 0; i < count; ++i)
{
fragmentManager.PopBackStack();
}
// your code
return false;
}
return base.OnKeyDown(keyCode, e);
}
I switch three fragment, when I click the back button. it switch to the first fragment.
Update
Do you want to achieve the result that you click back button then back to the desktop when you in the HomePage?
Here is code.
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode.Back)
{
FragmentManager fragmentManager = this.FragmentManager;
int count = fragmentManager.BackStackEntryCount;
if(count>0){
for (int i = 0; i < count; ++i)
{
fragmentManager.PopBackStack();
}
return false;
}
}
return base.OnKeyDown(keyCode, e);
}
I'm working on a fitness app (using Xamarin) and would like it to continue running in the background if the user switches to another app or pushes the side button to blank out the screen. I have looked at multiple tutorials, include this one https://robgibbens.com/backgrounding-with-xamarin-forms/, which seemed very promising. However, when running my app and switching to another application or blanking the screen, my app simply suspends. Hers is the iOS specific code that starts the background task:
public class IOSPlayWorkoutTask
{
nint _taskID;
CancellationTokenSource _cts;
Workout _workout;
public async Task Start()
{
_cts = new CancellationTokenSource();
_taskID = UIApplication.SharedApplication.BeginBackgroundTask("IOSPlayWorkoutTask", OnExpiration);
try
{
WorkoutPlayer.Shared.Workout = _workout;
await WorkoutPlayer.Shared.PlayWorkout(_cts.Token);
}
catch (OperationCanceledException)
{
}
finally
{
if (_cts.IsCancellationRequested)
{
//Device.BeginInvokeOnMainThread(
// () => MessagingCenter.Send(new CancelPlayingWorkoutMessage(), CancelPlayingWorkoutMessage.MessageText));
}
}
UIApplication.SharedApplication.EndBackgroundTask(_taskID);
}
public void Pause()
{
WorkoutPlayer.Shared.RequestPause();
_cts.Cancel();
Device.BeginInvokeOnMainThread(
() => MessagingCenter.Send(new PausedWorkoutMessage(), PausedWorkoutMessage.MessageText));
}
public void Stop()
{
_cts.Cancel();
Device.BeginInvokeOnMainThread(
() => MessagingCenter.Send(new FinishedWorkoutMessage(), FinishedWorkoutMessage.MessageText));
}
void OnExpiration()
{
_cts.Cancel();
}
public IOSPlayWorkoutTask(Workout w)
{
_workout = w;
}
}
The iOS app delegate registers to receive messages, one of which starts the task above. I know I must be missing something very basic. Any help would be greatly appreciated. I know this has to be possible based on my experience using other fitness apps like Couch to 5k.
Thanks #sushihangover and #Paulw11 for your input. Looks like the secret is adding a handler to BeginBackgroundTask that calls EndBackgroundTask. Not sure I understand fully at this point, but apparently this give iOS the impression that you are a "good citizen", but continues processing your task. Here is my code that works:
public async Task Start()
{
_cts = new CancellationTokenSource();
//_taskID = UIApplication.SharedApplication.BeginBackgroundTask("IOSPlayWorkoutTask", OnExpiration);
_taskID = UIApplication.SharedApplication.BeginBackgroundTask(() =>
{
Console.WriteLine("Guess my time is up");
UIApplication.SharedApplication.EndBackgroundTask(_taskID);
});
try
{
WorkoutPlayer.Shared.Workout = _workout;
await WorkoutPlayer.Shared.PlayWorkout(_cts.Token);
//finished = true;
}
catch (OperationCanceledException)
{
Console.WriteLine("OperationCanceledException");
//finished = true;
}
finally
{
if (_cts.IsCancellationRequested)
{
//Device.BeginInvokeOnMainThread(
// () => MessagingCenter.Send(new CancelPlayingWorkoutMessage(), CancelPlayingWorkoutMessage.MessageText));
}
}
UIApplication.SharedApplication.EndBackgroundTask(_taskID);
}
Everything works perfect on android but when I try to get the profile picture on iOS devices. The image returns null. I checked the Facebook documentation for iOS 9 I have exactly the same plist as shown in documentation. When I run the app in console I see "FB is log in" message but the profile pic has not shown. Can anyone help?
void Awake()
{
instance = this;
FB.Init(SetInıt, OnHideUnity);
}
public void FbLogin()
{
// This is an event trigger when the button pressed.
List<string> permissions = new List<string>();
permissions.Add("public_profile");
FB.LogInWithReadPermissions(permissions, AuthcallBack);
}
void DealWithFbMenus(bool isLoggedIn)
{
// This function is called in SetInit func in Awake.
if(isLoggedIn)
{
fbButton.SetActive(false);
profilePicture.gameObject.SetActive(true);
loggedInPlayer = true;
//FB.API("/me?fields=first_name", HttpMethod.GET, DisplayUserName);
FB.API("/me/picture?type=square&height=128&width=128", HttpMethod.GET, DisplayProfilePic);
}
else
fbButton.SetActive(true);
}
void DisplayProfilePic(IGraphResult result)
{
if(result.Texture != null)
{
profilePicture.sprite = Sprite.Create(result.Texture, new Rect(0,0, 128, 128), new Vector2());
}
}
It is a bug on Unity 5.2. It fixed on new version of Unity 5.3
i would like to ask your help, this is my code :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==REQUEST_CODE_INPUT){
switch (resultCode){
case RESULT_CODE_PASS:
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
WifiManager wifiManager= (WifiManager) getSystemService(Context.WIFI_SERVICE);
pass=data.getStringExtra("passWord");
nameWifi=data.getStringExtra("nameWifi");
WifiConfiguration conf=new WifiConfiguration();
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
List<ScanResult> networkList=wifiManager.getScanResults();
if(networkList !=null){
for(ScanResult network : networkList){
if(network.SSID.startsWith("\"")){
network.SSID=network.SSID.substring(1, network.SSID.length() - 1);
}
if(nameWifi.equals(network.SSID)){
String Capabilities=network.capabilities;
if(Capabilities.contains("WPA2")){
conf.preSharedKey="\""+pass+"\"";
}else if(Capabilities.contains("WEP")){
conf.wepKeys[0]="\""+pass+"\"";
conf.wepTxKeyIndex=0;
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
}
break;
}
}
}
wifiManager.addNetwork(conf);
List<WifiConfiguration> list=wifiManager.getConfiguredNetworks();
for(WifiConfiguration i: list){
if(i.SSID!=null && i.SSID.equals("\""+nameWifi+"\"")){
wifiManager.disconnect();
showWaiting();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
if(networkInfo.isConnected()){
dismissWaiting();
}else{
AlertDialog.Builder alert=new AlertDialog.Builder(MainActivity.this);
alert.setTitle("Wrong Password")
.setMessage("Please try again")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.create().show();
}
}
}
break;
}
}
}
i have 2 Activities (MainActivity and ShareWifi), i create Sharewifi with purpose: users input wifi SSID and password then press Enter, both of them will send to MainActivity--> disable current wifi and reconnect with new password but it still uses old password to reconnect. I write this code follow this link : How do I connect to a specific Wi-Fi network in Android programmatically?
Please help me to resolve this problem. Thank you very much.
Resolved: add saveConfiguration and it works
wifiManager.addNetwork(conf);
wifiManager.saveConfiguration();
I am using coding4fun message prompt in my app to display message box with customized buttons to the user. It works fine when the app is in the foreground and there is a message to be displayed. But, When I exit the app and re-launch it there are a set of things happening when after app's splash screen is displayed and before the main screen of the app is shown. During this process the app checks if any upgrade is available, if there are upgrades then on the splash screen the message box must be displayed to the user. When i was previously using xna framework message box this worked well, but due to marketplace submission process I replaced xna framework message box with coding4fun message prompt and the message prompt doesn't show when splash screen is displayed. Is this how Coding4Fun message prompt works or am i doing something wrong?
here is how i have implemented the message prompt in my code..
public MainPage()
{
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
{
DataManager.getInstance().setUIListener(this);
if (checkUpgradeStatus())
{
return;
}
});
}
private bool checkUpgradeStatus()
{
try
{
string flag = "1";
if (!Utils.isNullString(flag))
{
DataManager.getInstance().CheckForUpgrade();
if (flag.Equals(CacheManager.MAJOR_UPGRADE))
{
customizedMessageBox(Utils.APP_UPGRADE_CONFIRM, CustomizedMessageBox.APP_UPGRADE_CONFIRM_TITLE, AppResources.APP_UPGRADE_CONFIRM);
DataManager.getInstance().UpdateBadge(true);
return true;
}
else if (flag.Equals(CacheManager.MINOR_UPGRADE))
{
CacheManager.getInstance().writeDataToConfigFile(CacheManager.APP_UPGRADE_STATUS, "0");
customizedMessageBox(Utils.APP_MINOR_UPGRADE_CONFIRM, CustomizedMessageBox.APP_MINOR_UPGRADE_CONFIRM_TITLE, AppResources.APP_UPGRADE_MINOR_CONFIRM);
DataManager.getInstance().UpdateBadge(true);
return false;
}
}
CacheManager.getInstance().writeDataToConfigFile(CacheManager.APP_UPGRADE_STATUS, "0");
return false;
}
catch (Exception ex)
{
Logger.log(TAG, ":checkUpgradeStatus():" + ex.Message);
return false;
}
}
public void customizedMessageBox(int messageboxtype, string title, string text)
{
try
{
switch (messageboxtype)
{
Case 6:
messageBox = new MessagePrompt();
Button btnMinorUpgrade = new Button();
btnMinorUpgrade.Content = "Upgrade";
messageBox.ActionPopUpButtons.Add(btnMinorUpgrade);
btnMinorUpgrade.Click += new RoutedEventHandler(btnMinorUpgrade_Click);
Button btnMinorUpgradeCancel = new Button();
btnMinorUpgradeCancel.Content = "Cancel";
messageBox.ActionPopUpButtons.Add(btnMinorUpgradeCancel);
btnMinorUpgradeCancel.Click += new RoutedEventHandler(btnMinorUpgradeCancel_Click);
messageBox.Show();
break;
}
}
catch (Exception ex)
{
Logger.log(TAG, ":customizedMessageBox():" + ex.Message);
}
}
NOTE*:- For testing purpose I have hard-coded flag's value to "1".
All the answers and suggestions appreciated.
Thank you