input text and check button - actionscript

hai guys...
My project is to get a input text from user and user can check their answer by simply click on the button check, if their answer is true a message "good job" will be display. but,my code have an error..can u help to check this code 4 me? your help i really appreciate...
ans1_box.restrict = "0123456789";
var setUpProblem:Function = function():Void
{
// Clear the ans1_box and the message_box1 and place focus on message_box1
ans1_box.text = "";
message_box1.text = "";
Selection.setFocus("ans1_box");
}
//When the "CHECK" button is pressed, check the user's answer.
check_buton.onRelease = function():Void
{
if (eval (ans1_box.text) == "22")
{
message_box1.text = "Good job!!";
}
else
{
message_box1.text = "Try again.";
//Selection.setFocus("ans1_box");
}
}

Get rid of the eval()
if (ans1_box.text == "22"){
message_box1.text = "Good job!!";
}else {
message_box1.text = "Try again.";
}

Related

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

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)

Difficulty updating InkPresenter visual after removing strokes?

I am creating an inkcanvas (CustomInkCanvas) that receives Gestures. At different times during its use, I am placing additional panels over different parts of the inkcanvas. All is well, and the part of the CustomInkCanvas that is not covered by another panel responds appropriately to ink and gestures.
However, occasionally a Gesture is not recognized, so in the default code of the gesture handler, I am trying to remove the ink from the CustomInkCanvas--even when it is not the uppermost panel.
How is this done?
Note: I have tried everything I can think of, including:
Dispatcher with Background update as:
cink.InkPresenter.Dispatcher.Invoke(DispatcherPriority.Background, EmptyDelegate);
Clearing the strokes with:
Strokes.Clear();
cink.InkPresenter.Strokes.Clear();
Invalidating the visual with:
cink.InkPresenter.InvalidateVisual();
cink.InavlidateVisual();
And even
foreach (Stroke s in Strokes)
{
cink.InkPresenter.Strokes.Remove(s);
}
Here is the full code...
void inkCanvas_Gesture(object sender, InkCanvasGestureEventArgs e)
{
CustomInkCanvas cink = sender as CustomInkCanvas;
ReadOnlyCollection<GestureRecognitionResult> gestureResults = e.GetGestureRecognitionResults();
StylusPointCollection styluspoints = e.Strokes[0].StylusPoints;
TextBlock tb; // instance of the textBlock being used by the InkCanvas.
Point editpoint; // user point to use for the start of editing.
TextPointer at; // textpointer that corresponds to the lowestpoint of the gesture.
Run parentrun; // the selected run containing the lowest point.
// return if there is no textBlock.
tb = GetVisualChild<TextBlock>(cink);
if (tb == null) return;
// Check the first recognition result for a gesture.
isWriting = false;
if (gestureResults[0].RecognitionConfidence == RecognitionConfidence.Strong)
{
switch (gestureResults[0].ApplicationGesture)
{
#region [Writing]
default:
bool AllowInking;
editpoint = GetEditorPoint(styluspoints, EditorPoints.Writing);
at = tb.GetPositionFromPoint(editpoint, true);
parentrun = tb.InputHitTest(editpoint) as Run;
if (parentrun == null)
{
AllowInking = true;
TextPointer At = tb.ContentEnd;
Here = (Run)At.GetAdjacentElement(LogicalDirection.Backward);
}
else
{
Here = parentrun;
AllowInking = String.IsNullOrWhiteSpace(parentrun.Text);
}
*** THIS FAILS TO REMOVE THE INK FROM THE DISPLAY ???? *********
if (AllowInking == false)
{
foreach (Stroke s in Strokes)
{
cink.InkPresenter.Strokes.Remove(s);
}
// remove ink from display
// Strokes.Clear();
// cink.InkPresenter.Strokes.Clear();
cink.InkPresenter.InvalidateVisual();
cink.InkPresenter.Dispatcher.Invoke(DispatcherPriority.Background, EmptyDelegate);
return;
}
// stop the InkCanvas from recognizing gestures
EditingMode = InkCanvasEditingMode.Ink;
isWriting = true;
break;
#endregion
}
}
}
private static Action EmptyDelegate = delegate() { };
Thanks in advance for any help.
It would be nice to get a guru response to this, but for anybody else getting here, apparently the strokes that go into creating the gesture have not yet been added to the InkCanvas, so there is nothing to remove or clear from the inkcanvas from within the gesture handler. Strokes are only added to the InkCanvas AFTER the gesture handler. The solution this newbie ended up with was to set a flag when ink was not allowed, and then act on it in the StrokesChanged handler like:
if (AllowInking == false)
{
ClearStrokes = true;
return;
}
void Strokes_StrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
{
if (ClearStrokes == true)
{
ClearStrokes = false;
Strokes.Clear();
return;
}
All works now. Is there a better way?

Facebook Share Dialog/Feed Dialog on iOS - how to know if share button or cancel button is tapped

I was trying to implement a Facebook share dialog in my iOS app. I tried both the Share Dialog
https://developers.facebook.com/ios/share-dialog/
and Feed dialog
https://developers.facebook.com/docs/howtos/feed-dialog-using-ios-sdk/
In both the cases I was able to actually share my content, but my problem is I cannot track whether the user actually "Shared" or "Cancel"ed out.
The links above show handlers (even comments are there) which gets fired if the user actually shares the content. But when the code is actually run, it always returns positive or in other words I'm not being able to distinguish if the cancel button was hit or the share button.
Please point me out if I'm missing out anything, or if anyone else has faced the same issue.
Thanks,
Updating just in case this helps anyone, the following link finally worked for me:
https://developers.facebook.com/docs/howtos/ios-6/#nativepostcontroller
Though it had it's limitations (doesn't run on iOS < 6), but it successfully returns me when the user cancels out the dialog. Here's the code I used:
BOOL displayedNativeDialog = [FBDialogs presentOSIntegratedShareDialogModallyFrom:self
initialText:[NSString stringWithFormat:#"%#", url]
image:nil
url:url
handler:^(FBOSIntegratedShareDialogResult result, NSError *error) {
if(result == 0)
{
//Fire our callback
}
else{
NSLog(#"USER CANCELLED");
}
}];
Here's how to get the explicit result on your console.
FBDialogs.PresentShareDialog(myAction,"altimeterthree:share","flight",(call, results, error) => {
if(call != null)show("Call = " + call.ToString());
if(results != null)Console.WriteLine("Results = "+results.ToString());
if(error != null)Console.WriteLine("Error = "+FBErrorUtility.UserMessage(error));
});
Here's what the console output looks like. Notice that the result is also in the call info.
2014-05-11 10:09:26.067 AltimeterThree[18988:60b] Call = <FBAppCall: 0x19e02350, ID: 4589F102-3D11-40D5-BC95-1A1852B341AC
dialogData: <FBDialogsData: 0x19e04e20, method: ogshare
arguments: {
action = {
flight = {
data = {
};
description = "my description";
"fbsdk:create_object" = 1;
id = 1413672752238899;
image = (
{
url = "<UIImage: 0x147f9180>";
"user_generated" = true;
}
);
title = "Flight 23";
type = "altimeterthree:flight";
url = "http://http://samples.ogp.me/1413756595563848";
};
};
actionType = "altimeterthree:share";
previewPropertyName = flight;
}
results: {
completionGesture = cancel;
didComplete = 1;
}>
>
2014-05-11 10:09:26.070 AltimeterThree[18988:60b] Results = {
completionGesture = cancel;
didComplete = 1;
}

XNA Controls Settings

I have a huge problem with editing controls for my game.. I have an ingame button and when you click it. The "Choose your key.." text appears, but I don't know how to actually set it up..
I have made a "waiting for input" bool.. THIS IS NOT THE REAL CODE IT'S HOW I IMAGINE IT TO BE
if (buttonIsClicked) waitinForInput = true;
while(waitingForInput)
{
kbState = Keyboard.GetState();
somehow convert it to Keys.(STH);
if (Keys.STH != defaultKeys)
{
defaultKeys = Keys.STH;
waitingForInput = false;
}
}
Is there a way to do this.. Simpliest as I can? And sorry for my bad english.. Made this in a hurry and not my native language..
Thanks for any help.. :-)
Something like this:
KeyboardState currentKeyboardState = new KeyBoardState();
KeyboardState previousKeyboardState = new KeyBoardState();
Keys jumpKey = Keys.Space;
public void handleInput()
{
lastKeyboardState = currentKeyboardState;
currentKeyboardState = Keyboard.GetState(PlayerIndex.One);
bool waitingForKey = false;
if(currentKeyboardState.IsKeyDown(Keys.A) && waitingForKey == false)
{
waitingForKey = true;
}
if(waitingForKey == true)
{
//currentKeyboardState.GetPressedKeys() returns a list of pressed keys,
//So, currentKeyboardState.GetPressedKeys()[0] returns the first pressed key
if(currentKeyboardState.GetPressedKeys().Count() > 0)
{
jumpKey = currentKeyboardState.GetPressedKeys()[0];
waitingForKey = false;
}
}
}

Cannot capture TouchEvent.UP in Blackberry

I am working on a Scrollable Image field.I am handling TouchEvent.DOWN mTouchEvent.MOVE,TouchEvent.UP.
Somehow control never goes to TouchEvent.UP section.How to capture the UP event.
I have to findout the start and end points of the drag.
My Code looks like this..
if (event == TouchEvent.DOWN && touchEvent.isValid())
{
_xTouch = touchEvent.getX(1);
_yTouch = touchEvent.getY(1);
}
else if(event == TouchEvent.UP && touchEvent.isValid())
{
int x = touchEvent.getX(1);
int y = touchEvent.getY(1);
}
else if (event == TouchEvent.MOVE && touchEvent.isValid())
{
boolean result = scrollImage((touchEvent.getX(1) - _xTouch), (touchEvent.getY(1) - _yTouch));
_xTouch = touchEvent.getX(1);
_yTouch = touchEvent.getY(1);
//If scrolling occurred, consume the touch event.
if (result)
{
return true;
}
else
{
return false;
}
}
Thanks in advance.
:)
it was a misunderstanding.I was handling the touch event in multiple layers..like Field level,layout manager level and screen level.
So in particular case..it was being cosumed by manager.And i need the event to be cosumed by field.
It was a mistake in return value.

Resources