XCTest unable to find textfield - ios

I am learning XCTest framework. I want to test whether the textfield accepts numeric values or not [which it should not]. But XCTest is unable to find the textfield.
XCUIApplication().textFields["name"].typeText("123")
XCTAssertEqual(XCUIApplication().textFields["name"].title, "")
name is palceholder of textfield. I have only one textfield in this demo app. But test always fails on 1st line of test code and no error is shown.
Note: I have made the appropriate code for not letting the textfield
accept numeric values.

If you want to examine an element, first step is to check whether it is accessible by an identifier or not. The crash happens because the system can not find the text field named "name".
You have to set an identifier to that text field.
yourTextField.accessibilityIdentifier = "myTextField"
Now, you can get the textfield by the string "myTextField"
XCUIApplication().textFields["myTextField"]
Use Voice over/Accessibility inspector to check elements labels/values/identifiers.

Related

Grab value from parse column into label

I have made a small app that uses Parse, I have a signUp viewController, and after signing up I have a usersVC viewController.
Inside Parse dashboard I added a column named profileName, I want that after signing up to grab the value that is inside this column to some label.
Here parse dashboard:
enter image description here
I mean I need something like: profileNameLbl.text = PFUser.current().profileName
but of course this wont compile.
On swift 4.2 use:
PFUser.current()?[“profileName”] as? String

Archer to Archer Data Feed in RSA Archer

Need to create Archer to Archer Data Feed that should set value of two fields as NULL in a cross referenced application, if the value of a field is Approved in first field. I am not getting how can I send a NULL value to the fields through data feed??
Archer doesn't have "NULL" value, but you still can get it done like this:
Step 1. Calculation. Open your data feed configuration and go to the source definition tab. Add a new field to the end of the list and make it calculated.Add formula to check value of 1st field that present in the data source and if it is equal to "Approved" then return empty string.
Something like this
=IF([field field] = VALUEOF([first field],[Approved]), "","SOMETHING ELSE")
The key here is to have this calculation return an empty string when you need it - "".
I suggest you to test your calculation in the calculated field in the application before you put it in the calculated data source field.
Step 2. Data feed mapping. Now you need to map new calculated field in your data feed to the field you want to remove value from. Go to the mapping tab in your data feed configuration and map the field. Make sure to selection options "Replace value" and "Empty Values" - this way existing value will be replaced even with empty values.
Similar approach works for me in multiple data feeds.
Good luck!
You can use novalue() function in the calculation
I don't believe there is a concept of NULL in Archer. The closest you're probably going to get is blank/empty. To do that, in the Data Map tab of your data feed, click the edit icon under Actions column. Check the box that Empty Values should be populated rather than ignored.
Assumption is that what is in the question is the only task required by the data feed.
Create report with the filter set as First Field = Approved
Fields to display should contain tracking id (tracking ID which is configured to System ID) of the Target app along with the Tracking ID of the Cross-Reference App.
In Source Definition add new source and give it an adequate name as clear or Null if you want
Where it says Raw Data Field in the drop-down, update this to static. Leave the source as not configured or unconfigured.
Map this newsource to the 2 fields that you are trying to clear. In Options set to Replace and uncheck add unknown and set to populate empty values.
Map the Tracking ID of the Target app and map the Tracking ID of the cross-reference.
Set key field definition for both apps to the tracking id
Set data feed to update only. Remove checkmark for create
If your are doing more than just clearing the 2 fields, then
Stan Utevski answer is mostly correct except you must have the field you are evaluating for "Approve" in the fields to display of your report. Otherwise the calculation will not validate.

Appium XCUIElement showing the same displayed text in accessibility id, value, name, label

I've started using Appium for iOS app automation. The developers had put the ids and name to every element in the app code to assist the automation engineers, however, when I inspect it using Appium it doesn't show any of them. It shows only the same displayed text in accessibility id, value, name, label.
What should I ask developer so that those id and names can be used for automation using Appium.
You should ask the developer to set the accessibility id for the elements.
My advice is that you should also ask the developer to change the accessibility id to something that is not exactly the value of the element, for example: if you have a button that says "Open", some devs will just give it the id "Open". You should ask them to set the accessibility id as "open" or even "openID" - in this way you can make sure that all the elements have an accessibility ID and you can easily spot missing ID's and ask the developer to add them.
In ios whatever the value given to the label of an element that will become the accessibility id of the element.Accessibility id is simply nothing but the text visible on the screen.In the example shown above the name or label will be the accessibility id of the element.
driver.findElement(By.ID(“Drive”)).click();
driver.findElementByAccessibilityId(“Drive”).click();
driver.findElement(By.name(“Drive”)).click();
driver.findElementByName(“Drive”).click();
In the above example "Drive" may be the label or name.
Appium will first search for an accessibility id that matches. If there is none found, a string match will be attempted on the element labels. Finally, if the id passed in is a localization key, it will search the localized string.
Just ask your developers to give label to every element and that label will become the accessibility id of that particular element.
From my experience I learned that, Identifier field is necessary to provide accessiblity/ name attribute to the element in iOS app.
Then you can identify elements with
#iOSFindBy(accessibility = "myid")
public MobileElement SOME_OBJECT;
Or
driver.findElementByAccessibilityId("myid")
Note: Providing any value to Label field will override the actual value displayed on the screen. So, generally avoid to provide any value to the Label field. This will ensure that, we'll be able to fetch the visible text from any element by element.getText().
Also, its important to understand that why the value to Identifier should be given to the only required objects.
For instance, If you want to identify elements like Btn Previous or Btn next then one need to avoid assigning Identifier value to Header or View(parent object). I find that ,providing value to parent suppress the Identifier for child elements.

What is the id that the calaba.sh-ios query gets based on?

When I use the query to pull the elements on the screen one of the attributes it gives me is id, however I can not find what determines its value. It is not the Restoration ID nor the Object ID. In some places it is the same as the background image name, others it is the class name, and most of the time it is nil.
I am try to find what is the id value that calaba.sh sees so I can set it in the app code to use as a unique identifier for my tests like I'm doing for android.
The 'id' is the accessibilityIdentifier.
It it is more usual, however, to search by mark.
On iOS a mark is:
accessibilityIdentifier
accessibilityLabel
if the view responds to text, then the mark will be the text.
query("view marked:'sign-in'")

Is it possible to get label of any text field inside any interceptor?

I have made a custom interceptor to display the error messages in my own format. It is successful to an extent.
But i would like to know can we get label of any textfield directly from invocation object?
Thanks in advance
If your field labels are localized, then yes, you can get the label text. Otherwise, no, since they would just be a string literal in the JSP.
Assuming you have a localized property:
field.firstName = First Name
You can get that from your interceptor using:
LocalizedTextUtil.findDefaultText(
"field.firstName",
invocation.getInvocationContext().getLocale()
);
However, if you provide more details on what you are trying to do, we may be able to offer better solutions.

Resources