How to automate a Toast message in Appium without taking screen shot? - appium

I want to test a Toast message without taking screen shot. Is there any other way to automate the Toast message?

You can get toast message and define Success/Fail operation:
By toastContainer = By.xpath("//div[#id='toast-container']//*");
By toastMessageDA = By.xpath("//div[#class='toast-message']");
public String toastUtility() throws Exception {
toast_container_flag = false;
try {
if (driver.findElement(toastContainer).isEnabled()) {
toast_container_flag = true;
List<WebElement> findData = driver.findElements(toastContainer);
for (WebElement element : findData) {
if (element.getAttribute("class").toString().contains("toast toast")) {
toast_success_fail = element.getAttribute("class").toString();
}
}
validationMessage = "Toast: " + driver.findElement(toastMessageDA).getText();
js.executeScript("arguments[0].click();", driver.findElement(toastMessageDA));
if (toastr_success_fail.equals("toast toast-success")) {
System.out.println("Success Message");
} else if (toastr_success_fail.equals("toast toast-error")) {
System.out.println("Fail Message");
} else {
System.out.println("Other Message");
}
System.out.println(validationMessage);
testResult = validationMessage;
}
} catch (Exception e2) {
testResult = "Toast message is not generated.";
testlog.info(testResult);
System.out.println(testResult);
}
return testResult;
}

Retrieval of toast messages is already supported for Android. Please look at the below release notes for Android.
https://github.com/appium/appium/releases/tag/v1.6.3
You need to use UIAutomator2 to work with toast messages in Android.
Hope this helps.

This works excellent for me in python.
control = False
xmlFormat = self.driver.page_source
if xmlFormat.find("your toast message") != -1:
control = True
self.assertEqual(True,control)

Related

Xamarin iOS - Text Changed event not showing results

Xamarin iOS is testing me lately. I have a form which has as Entry value for searching. This entry control has a text changed event. All works great , event executes and values passed as expected however the results dont appear on screen.
If i rotate the device, in this case and ipad, the results show. Everything in Android works as expected. Frustrating
CancellationTokenSource _cts;
private void Search_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
_cts?.Cancel(); // cancel previous search
}
catch { } // in case previous search completed
ShowResults((Entry)sender);
}
private async void ShowResults(Entry entry)
{
using (_cts = new CancellationTokenSource())
{
try
{
await Task.Delay(TimeSpan.FromSeconds(1), _cts.Token); // buffer
using (UserDialogs.Instance.Loading("Loading. . ."))
{
ObservableCollection<TMDB_Movie> itemSourceCollection = new ObservableCollection<TMDB_Movie>();
MovieSearchVM context = (MovieSearchVM)BindingContext;
try
{
if (!IsPublicCollection)
{
var results = PrivateCollection.Where(x => x.Title.Contains(entry.Text));
foreach (TMDB_Movie movie in results)
{
movie.PublicCollection = true;
movie.Type = "Digital";
itemSourceCollection.Add(movie);
}
}
else
{
if (PhysicalDevice.HasInternetConnection())
{
TMDB_Request request = new TMDB_Request();
TMDB_Movies movies = await request.ByMovieName(entry.Text, CustomSettings.GetSettings().Language);
int i = 0;
foreach (var movie in movies.Results)
{
if (i < 10)
{
FanartTv tv = new FanartTv();
movie.Movieposter = await tv.GetSingleMoviePoster(movie.Id);
if (movie.Release_date != null)
{
char[] Separator = new char[] { '-' };
string[] year = movie.Release_date.Split(Separator, StringSplitOptions.None);
movie.Release_year = year[0];
}
movie.PublicCollection = true;
itemSourceCollection.Add(movie);
i++;
}
else
{
break;
}
}
}
}
context.MovieCollection = itemSourceCollection;
}
catch { }
}
}
catch { }
}
}
View Model
private ObservableCollection<TMDB_Movie> _MovieCollection = new ObservableCollection<TMDB_Movie>();
public ObservableCollection<TMDB_Movie> MovieCollection
{
get { return _MovieCollection; }
set
{
_MovieCollection = value;
RaisePropertyChanged("MovieCollection");
}
}
XAML
<Grid Style="{StaticResource StyleBaseGrid}" Grid.Row="2" HorizontalOptions="FillAndExpand" >
<SfListView:SfListView x:Name="GridMovieCollection"
ItemsSource="{Binding MovieCollection}"
ItemTemplate="{StaticResource StandardPosterTemplate}"
Margin="-5,0,0,0"
ItemSize="125"
ItemSpacing="0,0,0,0"
AutoFitMode="None"
SelectionBackgroundColor="Transparent"
ItemHolding="GridMovieCollection_ItemHolding"
ItemTapped="GridMovieCollection_ItemTapped" >
</SfListView:SfListView>
</Grid>
I have no clue why rotation solves this but i guess it updates the controls width and height properties and refreshes the screen.
Any ideas how i can force refresh the screen or if there is anything wrong with my code?
Android look

Xamarin-IOS BTLE WroteCharacteristicValue not fired

I have the following code for my IOS implementation, the problem is that the WroteCharacteristicValue event is never fired. Is is being fired on the android side when I connect to the same module. Any ideas what to do?
public void StartUpdates ()
{
// TODO: should be bool RequestValue? compare iOS API for commonality
bool successful = false;
if(CanRead) {
Console.WriteLine ("** Characteristic.RequestValue, PropertyType = Read, requesting read");
_parentDevice.UpdatedCharacterteristicValue += UpdatedRead;
_parentDevice.ReadValue (_nativeCharacteristic);
successful = true;
}
if (CanUpdate) {
Console.WriteLine ("** Characteristic.RequestValue, PropertyType = Notify, requesting updates");
_parentDevice.UpdatedCharacterteristicValue += UpdatedNotify;
_parentDevice.WroteCharacteristicValue += Wrote; // -DP here??
_parentDevice.SetNotifyValue (true, _nativeCharacteristic);
successful = true;
}
Console.WriteLine ("** RequestValue, Succesful: " + successful.ToString());
}
void Wrote(object sender, CBCharacteristicEventArgs e) {
System.Diagnostics.Debug.WriteLine("Characteristic Write Complete!");
this.WriteComplete (this, new CharacteristicReadEventArgs () {
Characteristic = new Characteristic(e.Characteristic, _parentDevice)
});
}
The WroteCharacteristic will only fire if the characteristic writes with response.
You can check it with:
var prop = _nativeCharacteristic.Properties;
if(prop.HasFlag(CBCharacteristicProperties.Write))
{
// Event can be used
}
else if(prop.HasFlag(CBCharacteristicProperties.WriteWithoutResponse))
{
// Event will not fire if WriteWithoutResponse
}
Btw: we provide a plugin for BLE, so you don't have to care about platform sepcific stuff ;) http://smstuebe.de/2016/05/13/blev1.0/

Not able to retrieve messages from topic using EMS.NET API

I am trying to write a simple application to send messages to a topic from use input and show messages published on topic.
There are two command line executables - one for publisher and another for subscriber.
When I publish messages on a topic, I can see the messages getting submitted to the topic.
The following command shows that there are messages on the topic (see F1.gif):-
show stat EMS.Test.Topic
The following command shows that the messages are getting consumed by the subscribers (see F2.gif)
show stat consumers topic=EMS.Test.Topic
However, I am not able to retrieve messages the EMS .NET API. It gets stuck on Message msg = subscriber.Receive();. I made sure the connection details and authentication details are correct because they are used when publishing the messages.
public string ReceiveMessagesFromTopic(string topicName)
{
TopicConnection connection = null;
string messageFromPublisher = string.Empty;
try
{
var factory = new TIBCO.EMS.TopicConnectionFactory(serverUrl);
connection = factory.CreateTopicConnection(userName, password);
TopicSession session = connection.CreateTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.CreateTopic(topicName);
TopicSubscriber subscriber = session.CreateSubscriber(topic);
connection.Start();
while (true)
{
Message msg = subscriber.Receive();
if (msg == null)
{
break;
}
if (msg is TextMessage)
{
TextMessage tm = (TextMessage) msg;
messageFromPublisher = tm.Text;
}
}
connection.Close();
}
catch (EMSException e)
{
if (connection!=null)
{
connection.Close();
}
throw;
}
return messageFromPublisher;
}
There was a silly mistake in my .NET code. the following while loop never returns so there is no return. I need to break the while loop when I get a message. Duh!!!!
while (true)
{
Message msg = subscriber.Receive();
if (msg == null)
{
break;
}
if (msg is TextMessage)
{
TextMessage tm = (TextMessage) msg;
messageFromPublisher = tm.Text;
break;
}
}

Coding4Fun MessagePrompt not displayed when app is on the splash screen

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

How can you create a simple dialog box in Dynamics AX?

How can you create a simple dialog box in Dynamics ax?
static void DialogSampleCode(Args _args)
{
Dialog dialog;
DialogField field;
;
dialog = new Dialog("My Dialog");
dialog.addText("Select your favorite customer:");
field = dialog.addField(typeid(CustAccount));
dialog.run();
if (dialog.closedOk())
{
info(field.value());
}
}
for really simple dialog boxes, use the Box Class:
Box::info("your message");
or
Box::warning("your message");
or
if (Box::okCancel("continue?", DialogButton::Cancel) == DialogButton::Ok)
{
// pressed OK
...
or one of the other static methods (infoOnce, yesNo, yesNoCancel, yesAllNoAllCancel, ...)
DAX 2012 does not have "typeid" as a method. But you can use extendedTypeStr and then pass in either a known EDT or use the built in string length versions:
str getStringFromUser(str _prompt, str _title)
{
str userResponse = "";
Dialog dlg = new Dialog(_title);
DialogField dlgUserResponse = dlg.addField(extendedTypeStr(String15), _prompt);
// This prompts the dialog
if (dlg.run())
{
try
{
userResponse = dlgUserResponse.value();
}
catch(Exception::Error)
{
error("An error occurred. Please try again.");
}
}
return userResponse;
}

Resources