I'm trying to setup automated e2e tests using nativescript-dev-appium. I can't figure out how to locate a TextField when running a NativeScript app through Appium on Android. I'm using tns-core-modules v5.2.1 and nativescript-angular 7.0.2.
The only NativeScript element property I can find that seems to be for automation tests to find elements is automationText. When I set automationText on iOS, I can find a text field by using the Appium driver's driver.findElementByAutomationId or driver.findElementByAutomationText. However, when on Android, neither of those methods return the right element. findElementByAutomationId doesn't work at all (I think automation IDs may be iOS-specific), and findElementByAutomationText is returning a label next to my TextField and not the TextField itself.
My actual view has quite a few TextFields, but here's the basic idea:
<StackLayout>
<Label text="Name"></Label>
<TextField automationText="Name" ...></TextField>
</StackLayout>
Then, in my e2e test, I want to do this
const nameInput = await driver.findElementByAutomationText("Name") // Returns the Label and not the TextField
Since findElementByAutomationText seems to be searching elements by Text and not by AutomationText on Android, what is the most reliable way I could find my TextField when running my tests? Preferably, I'd like a cross-platform solution so I don't have to use different find strategies on iOS and Android.
Why can't you ask the developer to set id locator for the given component and use below snippet.
await driver.findElementById("#name");
I see your component doesn't have locator which is a reliable also....
Related
I noticed that my buttons are not working on the IOS devices, it seems that the click event is not called. Everything is working perfectly on the windows, android, Linux. Since I don't have access to any mac I was trying to debug it on the browserStack, I am getting this error every time I am trying to click the button:
ERROR TypeError: undefined is not an object (evaluating 't.path[4]')
I might be completely wrong, but I think that it might be related with the SVG's rect that is inside of the button (I am using it as a progress bar), on the rect load event I am accessing it to find its length. Maby it is called "too early" so it cannot access the rect correctly. Previously I was using the ngAfterViewInit with the setTimeout inside to manage the same effect.
<rect
#rect
width="96"
height="96"
rx="8"
fill="none"
stroke-width="4"
[ngStyle]="{
'stroke-dasharray': strokeDasharray,
'stroke-dashoffset': strokeDashoffset
}"
(load)="getRectLength()"
/>
getRectLength() {
this.length = this.rect.nativeElement.getTotalLength();
this.strokeDasharray = this.length;
}
Code:
https://github.com/mateuszkornecki/chess-clock/tree/master/src
Live demo:
https://mateuszkornecki.github.io/chess-clock/settings
Steps to reproduce:
Simply click on one of the big buttons with the counter, after a click it should start counting.
I tested it on several IOS devices, it was not working on everyone regardless of the IOS version. That's my first project made with Angular so there is a chance that I've made a simple mistake. Any help will be appreciated!
I have found the source of the problem. I was trying to use the event.path array on the click event. It looks that it is not available on the Safari. I fixed the problem by using the event.composedPath instead of the event.path
References:
https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath
Im just working with codeceptjs and using appium driver for testing android application.
Now i have different issues with this framework. Im currently working for a test, where i have to use swipeLeft, but it isnt working, there is nothing happen when that function is calling, also swipe, swipeRight, swipeUp, swipeDown. Has anyone already solved this problem or can i use alternatively a back() function or something?
Use the following syntax to make your code work:
I.executeScript('mobile: swipe', {direction: 'left'});
Have you consider Touch Perform (or Action) ? It is working for me
I have used webdriverio and it seems like Codeceptjs have similarities with their implementations of appium methods for mobile automation.
Are you testing using Android or iOS device?
Have you tried using different method overrides for Swipes?
On my experience, iOS and Android have different Speed and Offset settings you need to adjust the values until you get the swipe action working.
And of course you need to make sure you are selecting the appropriate View/Slider/Element that is scrollable, otherwise swipe will fail.
https://codecept.io/helpers/Appium
I am working on automating a iOS app using Appium-Java.
While writing the Page objects we need to find identifiers (driver.findelement) or when UI changes.
Currently its tedious job, as manually need to traverse through till required screen & then write the selectors( n CSS / XPath / XCUnit based Xpath)
Currently, there's no easy way to test CSS selectors / XPath (unlike web where we can test it then & there on Firefox / chrome using browser add-ons)
Is there any way to invoke certain screen directly instead of traversing from the starting point in iOS/Android native app or Cordova based app, while writing the selectors?
Kindly advise. Thanks.
For a Cordova-based iOS app, you can use wd and wd-bridge to provide a mechanism to allow Appium to communicate directly with the Webview, enabling you to use CSS selectors.
This blog post gives a great tutorial on how to setup such a test environment using Protractor/Jasmine.
You can then write Protractor tests which allow you to reference your app UI elements as HTML components, e.g.:
describe('Testing the app', function () {
it('01. should have a header', function () {
var header = element(by.id('header'));
expect(header.getAttribute('class')).toContain('toolbar');
});
});
I am currently writing Appium automation tests in NodeJS for iOS. Although I am having issues with UIAStaticText elements. Even though they are visible on screen I constantly get ElementNotFound error.
I am using the XPath for the element displayed in Appium Inspector - it is in the format "//UIAApplication/UIAWindow/UIAStaticText[1]" In the app code the element is a UIALabel.
I'm trying to get the value of the label but currently unable to getAttribute but it can't find the element.
Is there a known limitation with UIAStaticText elements and is there a workaround?
Many thanks.
I'm not sure if you are asking how to get an attribute or how to properly find an element. I'll assume find an element.
I'm not sure of any known issues with UIAStaticText but I would try using the following line
driver.findElement(By.xpath("//UIAStaticText[contains(#text, '*Static Text*')]"));
or
driver.findElement(By.xpath("//UIAStaticText[contains(#label, '*label Text*')]"));
This way you are not depending on the previous items within the xpath. A good way to test if you have a good xpath is to use the copy xml button in the appium inspector and see if your xpath returns a unique item.
In most cases I have run into the label matches the name or the text.
Hope that answers your question.
I am using Appium Mobile Driver. I want to identify platform specific class name (Control) of Mobile Element (For Android - Text View, Edit Text, Radio Button etc)
MobileElement.getClass() just returns the generic class name io.appium.java_client.android.AndroidElement.
Although Android's UIAutomatorViewer exposes 'class' property but that is not
accessible programmatically with Appium using MobileElement.getAttribute("class"). I suspect that Appium is hiding that property (I haven't tried directly using UiAutomator).
Does anyone have a clue?
Also any other way by which we can find out the class name programmatically using Appium or Do I need to use UiAutomator?