nativescript-dev-appium
nativescript-dev-appium copied to clipboard
Localization testing with appium mocha
Hi.
I'm currently trying to figure out a good way to test localization of an app and have some trouble accessing the label text of a button UIElement after i've accessed the element by automation text. After accessing the button UIElement i'm only able to get the automationText to test against.
It's my first time doing any form of testing with nativescript, appium and mocha and i might go about it completely wrong and if so advise would be much appreciated.
What i'm testing on iPad simulator (9.7 inch) with OS v. 12.4 node v10.16.3 npm v6.9.0 {N} v. 6.0.1 runtimes v 6.0.1 nativescript-localize for i18n localization
I've followed setup instructions and found some issues here where people hadn't installed carthage, which i've installed.
A simple test looks something like this
const daDK = require(dk.default.json); // localization file for danish const changeUserButton = await driver.findElementByAutomationText('changeUserButton'); expect(await changeUserButton.text()).to.be.equal(daDK.user.change_user);
Doing a log of the await changeUserButton.text()
retreives the automationText where it should have been Skift Bruger.
I've also tried to access elements in different way ie. with findElementByXPath and findElementByText (though i've read text is only android).
Any suggestions as to solve this?
My struggles to do localization tests continues today and i hope someone can share some light in my currently dark and unimaginative thought process. The problem is along the same lines as my previous comment but now i cannot extract text from labels - atleast on ios! Android does this fine though.
I've got this label on a page
<Label id="createUserTitle" class="userCreationHLabel" text="{{ L('user.user_create.title') }}" horizontalAlignment="center" automationText="titleLabel" />
and when i'm fetching this label in my e2e-specc file i'm doing the same as before,
const titleLabel = await driver.findElementByAutomationText('titleLabel');
Both platforms locate the object without issue. When I'd like to make a simple test to check the text within the label I do
expect(await titleLabel.text()).to.be.equal(daDK.user.user_create.title);
where daDK.user.user_create.title = Bruger.
If i do this on a textfield and i insert some text using the
someTextFieldUIElementObject.type('test text')
and then running
someTextFieldUIElementObject.text()
it outputs the text that was just typed. So to me it seem like an issue with ui-element objects that have "static" text like labels and buttons, where they are created with the automation text as their text property instead if the actual textproperty.
In light of this new blog entry from Nativescript i thought i'd try once more to get appium and Nativescript working with textual elements. So i've updated everything to the latest versions as follows,
Appium: 1.16.0 nativescript-dev-appium: 6.1.3 node: 10.18.0 {N}: 6.1.2 npm: 6.13.4
I've isolated the issue enough to conclude it's not something that's wrong with my previous implementation. Creating the default template using
tns create
adding appium using
npm install --save-dev nativescript-dev-appium
and then adding automationTexts to the UI elements of the main-page.xml still makes it retreive the automation text upon calling
await someLabelElement.text()
Is this really intentional and if so what is the best practice to test textual elements? This is quite troublesome, not only for localization testing but also if dynamic text is used anywhere in your app!
For the sake of clarity i've added a screenshot of the main-page.xml, the e2e.specc generated when adding the appium package and the result.
ANY help would be appreciated or we have to find some other solution to test with.



Hi @schnapzz, I've been having the exact issue as you. I don't know why other people aren't having this issue as well because it seems like a huge impediment if you cannot check text values on iOS. Have you happen to find any work-arounds since your most recent update by chance?
Hi @keerl, Sad to hear we're in the same boat and no I have not. Since my latest post our testing have gone fairly stale and time haven't been allocated to research this further. If you by chance succeed in solving the problem I'll be more than pleased to hear the solution!
Apparently this is a known problem, but there hasn't been anything that I know of to fix it. https://stackoverflow.com/questions/54797434/nativescript-dev-appium-uielement-text-uielement-getattributevalue-ret
I did find a work-around though. Anywhere I'm trying to read/check the text value of a label, I bind the automationText property to the exact same value as the text. I can then just search for the text I want using findElementByAutomationText() and that will give me the UIElement I want with that text if it exists.