I am working on alerts in UIAutomation. When I encounter an alert, I am supposed to ensure that the alert title and message are the same as expected. I have done this to get access for alert title.
var AlertTitle = target.frontMostApp().alert().name();
UIALogger.logMessage(AlertTitle);
In the similar way, is there any way to retrieve the message in alert ? I have tried using
target.frontMostApp().alert().value();
but it did not work. I have logged the element tree and got this.
UIAAlert
|
UIAImage
UIAStaticField name: Abc value: ABc
UIAStaticField name: XYZ value: XYZ
UIAButton
I need to retrieve the value of second UIAStaticField in this alert and compare with expected value. How do I do that ?
I tried doing this but it didn't work.
target.frontMostApp().alert().staticTexts[1]().value();
In iOS 7, it appears they wrap the staticTexts in a scrollView, so you'll need to alter Jonathan's answer to be:
target.frontMostApp().alert().scrollViews()[0].staticTexts()[1].value();
You're so close! You've got the parentheses and brackets backward in your line. Do it this way:
target.frontMostApp().alert().staticTexts()[1].value();
That way, you are calling the staticTexts() method on the alert to get the element array and then using the bracket syntax to get the second element.
Related
Please see the script below:
void OnStart()
{
Alert(IsTradeAllowed()); //alert 1
Alert(IsTradeAllowed(NULL, TimeGMT())); //alert 2
Alert(IsTradeAllowed(Symbol(), TimeGMT())); //alert 3
Alert(IsTradeAllowed("GBPUSD", TimeGMT())); //alert 4
}
This returns:
true //for alert 1
true //for alert 2
false //for alert 3
false //for alert 4
As alert 2 returns: true, then I would expect alert 3 and alert 4 to return true.
I have tried running the code at multiple times of the day on weekdays. The code returns the same result at weekends. I have also tried putting the code in a script and an EA. Every time I get the same result. Is there an explanation for this? I have tried what is suggested here: https://www.mql5.com/en/docs/runtime/tradepermission
Symbol() returns: "GBPUSD". Each alert should return true in my mind, however this does not appear to be the case here. Incidentally I have notices that Symbol() returns the symbol at the top of the demo account watchlist if the script is run inside MetaEditor, however it returns the symbol displayed on the chart if run inside the demo account.
The broker is Oanda.
Update 04/03/21 at 19:55
I have now discovered that if I right click on the Market Watch and select: show all, then more symbols appear. I can then see that some symbols are greyed out and some symbols are not. The symbols that are not greyed out e.g. USDGBP-g return what I would expect when running the program above i.e. alert 1-alert 4 =true. The symbols that are greyed out e.g. USDGBP returns true; true; false; false in the program above. I now have two questions:
Why does: IsTradeAllowed(NULL, TimeGMT()); //alert 2 return true for symbols that are greyed out?
What does -g mean in GBPUSD-g?
IsTradeAllowed checks if the Expert Advisor is allowed to trade and trading context is not busy.
The version of the function without any arguments will check if the EA has been applied with the correct permissions ("Allow live trading" ticked and "AutoTrading" enabled).
The second form of the function:
bool IsTradeAllowed(const string symbol, datetime tested_time);
checks if the EA would be allowed to trade according to the specifications for the chart selected (to view this, from the Market Watch window right click a symbol, from the menu that pops up select "Specification").
For example
IsTradeAllowed(Symbol(), D'2021.03.06 12:00');
would check if the current symbol can be traded this coming Saturday (which should be false).
If you are getting undesirable results you should check that your broker has set the "Specifications" correctly.
EDIT
I've tested the command in OANDA which is the broker you are using and the command functions as expected.
NULL is not valid for a Symbol and its use makes the command function in its first form (ie timedate is ignored).
I would suggest rather than use Alerts to examine output, try the following.
string cmnt;
cmnt=StringConcatenate("Alert 1: ",IsTradeAllowed());
cmnt=StringConcatenate(cmnt+"\r\n","Alert 2: ",IsTradeAllowed(NULL, TimeGMT()));
cmnt=StringConcatenate(cmnt+"\r\n","Alert 3: ",IsTradeAllowed(Symbol(), TimeGMT()));
cmnt=StringConcatenate(cmnt+"\r\n","Alert 4: ",IsTradeAllowed("GBPUSD", TimeGMT()));
Comment(cmnt);
I tried your script in my ICMarkets version of MetaTrader4. With disabled auto trading i get result:
When I set auto trading to enable using Ctrl+E shortcut, in all cases script return true.
I recommend you to try this script on another account or different broker. If this will help, you should communicate with your broker about this issue. The last option is a reinstall MetaTrader to make sure, that all config files are correct.
I am a litte new in iOS UITest so apologises if something does not make sense.
I am trying to assert if a staticText is visible but it always returns false despite being shown.
The Screen looks like this:
The test function code looks like this:
func verifyBlockedAccountsEmptyState() {
print(profileListScreen.app.navigationBars["Blocked Accounts"].waitForExistence(timeout: 5))
print(profileListScreen.app.staticTexts.element.label)
print(profileListScreen.app.staticTexts["No blocked accounts"].waitForExistence(timeout: 5))
var elementLabels = [String]()
for i in 0..<profileListScreen.app.staticTexts.count {
elementLabels.append (profileListScreen.app.staticTexts.element(boundBy: i).label)
}
print("staticTexts -> ", elementLabels)
}
And the output:
true
12:25 PM
false
staticTexts -> ["12:25 PM"]
Any idea?
Thank you
EDIT
If I try to record the XCUIElement I get the following error:
Timestamped Event Matching Error: Failed to find matching element
A problem may be caused by using the wrong element type.
You probably should add a breakpoint and inspect this screen with lldb.
Type po print(app.debugDescription) to print the whole hierarchy of elements and their actual types.
It sounds like you should be assigning an AccessiblityId to part of the view you are interested in. You can see what's available in a given view by getting the container XCUIElement's debugDescription.
I am trying to replace some characters in a text block. All of the replacements are working except the one at the beginning of the string variable.
The text block contains:
[FIRST_NAME] [LAST_NAME], This message is to inform you that...
The variables are defined as:
$fname = "John";
$lname = "Doe";
$messagebody = str_replace('[FIRST_NAME]',$fname,$messagebody);
$messagebody = str_replace('[LAST_NAME]',$lname,$messagebody);
The result I get is:
[FIRST_NAME] Doe, This message is to inform you that...
Regardless of which tag I put first or how the syntax is {TAG} $$TAG or [TAG], the first one never gets replaced.
Can anyone tell me why and how to fix this?
Thanks
Until someone can provide me with an explanation for why this is happening, the workaround is to put a string in front and then remove it afterward:
$messagebody = 'START:'.$messagebody;
do what you need to do
$messagebody = substr($messagebody,6);
I believe it must have something to do with the fact that a string starts at position 0 and that maybe the str_replace function starts to look at position 1.
I'm trying to print out all the elements in this array, and when I display it, it only prints out Pickup laundry.
var todo = ["Return Calls", "Write blog", "Cook Dinner", "Pickup laundry"]
for element in todo {
print(element)
}
I'm not sure why this is wrong...
I copied your code and pasted it into an app. I ran the app. I saw this in the console:
Return Calls
Write blog
Cook Dinner
Pickup laundry
So I conclude that either you are lying — that is not your code, or that is not what is printed — or you don't know how to test (e.g. you don't know how to read the console or you're in a playground and you don't understand where the console is).
I'm currently teaching myself the Dart language, and my first app doesn't seem to be working right. Here's the code that's causing trouble:
usrLoc = int.parse(query("#txtLoc").text);
When I try to run the app, it opens fine, but when I click the button that triggers this (and three other similar parses), the debugger stops and tells me "Source not found" for int._native_parse(), int._parse(), and int.parse().
Any help would be greatly appreciated.
The text property for the specified element #txtLoc returns an empty string.
The parse method requires that:
The source must be a non-empty sequence of base- radix digits, optionally prefixed with a minus or plus sign ('-' or '+').
You can specify an onError named argument in your call to parse, which takes a callback that handles the invalid input. E.g., if you want the parse call to return the value 42 for all invalid input, you can do this:
usrLoc = int.parse(query("#txtLoc").text, onError: (val) => 42);
If you really expect the element to have some text, you can store the result of query("#txtLoc").text into a separate variable and verify the value. It would also be interesting to check what the real element type is or which tag is marked with id #txtLoc.
If you want to get the content of an input element, you should use the value property instead of text:
query("#txtLoc").value