Unable to see the first element in a Xamarin forms List view while running the automated UI iOS tests using xctest
Element with property in Xamarin forms "ListViewCachingStrategy.RetainElement" , the first element is missing from the list view while running the tests in iOS .
Inbetween the tests if we remove the WDA and tried the same scenario, it works as expected.
The first element was displayed when working with xamarin forms (v4.7.0.1351) and it is observed with only the current version.
Manually trying the same scenario does not have any issues , Elements are displayed as expected, issue is observed only through automation
XCTest
RSS for tagCreate and run unit tests, performance tests, and UI tests for your Xcode project using XCTest.
Posts under XCTest tag
145 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Unable to record and play the new contacts permission system dialog.
App: https://developer.apple.com/documentation/contacts/accessing-a-person-s-contact-data-using-contacts-and-contactsui
func handleContactsAccessAlert() {
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let allowButton = springboard.buttons["Allow Full Access"]
allowButton.tap()
let access6ContactsButton = springboard.alerts["Allow full access to 6 contacts?"].scrollViews.otherElements.buttons["Allow"]
access6ContactsButton.tap()
}
func handleContactsPermissionAlert() {
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let allowButton = springboard.buttons["Continue"]
if allowButton.exists {
allowButton.tap()
sleep(5)
handleContactsAccessAlert()
}
}
func testContactPermissions() {
let app = XCUIApplication()
app.launch()
app.buttons["Request Access"].tap()
sleep(5)
handleContactsPermissionAlert()
sleep(5)
app.collectionViews/*@START_MENU_TOKEN@*/.staticTexts["Kate Bell"]/*[[".cells.staticTexts[\"Kate Bell\"]",".staticTexts[\"Kate Bell\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
}
I have some (very old ObjC) XCUITests, in Xcode 15.2. I recently noticed programmatic screenshots are not saving. The screenshots generated automatically by XCUITest are saving fine. This is code that used to work as expected; I do not know when it broke as I haven't had need to run this in a while.
-(void)takeScreenshotWithName:(NSString *)name {
XCUIScreenshot *screenshot = XCUIScreen.mainScreen.screenshot;
XCTAttachment *attachment = [XCTAttachment attachmentWithScreenshot:screenshot];
attachment.lifetime = XCTAttachmentLifetimeKeepAlways;
attachment.name = name;
[self addAttachment:attachment];
UIImage *image = screenshot.image;
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
During testing I added the UIImageWriteToSavedPhotosAlbum call, to verify the code is running and the image is available - and it does. But I really don't want these images cluttering up my library.
The results are the same whether I run my tests from within Xcode, or via the command line.
I need these screenshots so I have a set in PNG format, with standardized naming, for archiving, searching, and comparisons. The automatic screenshots are in Xcode's format - useful when reviewing a single test, which isn't my use case here.
I'm trying to measure app launch time in an existing Xcode project. I added a simple test that's supposed to display a "no baseline" message and a button to set a baseline, but when I run the test, it just succeeds without showing the pop-up.
It works in a new project, so I suspect there might be a specific setting in my existing project that's causing the issue. The project is about 6 years old.
Does anyone know if there's a particular setting I need to enable for launch tests to display the baseline pop-up in older projects?
I'm running the test from new project in Xcode 14.2.
Existing project in Xcode 15.2 and 14.2 both succeed with no baseline message.
Thank you!
The connection to service named com.apple.testmanagerd was invalidated: failed at lookup with error 3 - No such process.
Currently I am struggling with this problem while running tests runner
`xcrun devicectl device process launch --console --device '000000000000000000000' 'com.gl.RunnerPOC-Watch-AppUITests.xctrunner
What may be causing the issue?
Thanks in advance
Is it planned to add ability to run Xcode test bundles using devicectl tool? If it is possible now how to achieve it?
Is there any other ways to run tests bundle .app file using command line?
I need to run my tests bundle independently from Xcode. Previously, I used to deploy it and run as regular iOS application, it would execute test cases and display 'Automation running' label. I needed to execute tests some time after deploy and in different time of the day, so it is a problem for my team right now. So, UI Tests Runner app file does not launch and 'Automation Running' label is not displayed, is there any possible ways to run tests as it was or other ways to run tests not from Xcode.
Hello,
I am wondering if anyone else has seen this bug:
Create a multiline TextField like so:
TextField("a string", text: $myDataStore.placeholder, axis: .vertical)
.accessibilityIdentifier("placeholder")
.multilineTextAlignment(.leading)
.lineLimit(...3)
.textFieldStyle(CustomTextFieldStyle(text: $myDataStore.placeholder, hasErrors: myDataStore.placeholder.isEmpty))
Then create a UITest that accesses it.
let multilineTextField = app.textViews["placeholder"] // note that multiline textFields can only be accessed as textVIEWS, not textFIELDS. They simply do not appear under po.textFields
let exists = multilineTextField.waitForExistence(timeout: 3)
XCTAssertTrue(exists, "The field did not appear in time.")
multilineTextField.tap()
// everything is fine up to here
//BUG: multiline textfields will not tap into keyboard on larger device types like the iPhone 15, but they will on SEs.
multilineTextField.typeText("A Test") // fails on anything other than an SE, "Neither element nor any descendant has keyboard focus"
What is happening here?
Currently Swift Testing has much less features than XCTest, so the adoption will be very slow from our side. Notable features we miss are UI tests, performance tests and attachments.
I did not want to create many issues in Swift Testing GitHub project as lots of these shortcoming are most probably tracked internally (I can see lots of references to radars in GitHub issues.)
So, my question is: Is it a good idea to wait with wider adoption or should we experiment with other tools like swift Benchmarks?
This issue started to appear in the last couple of weeks. And it's annoying because Xcode Cloud actually is based on build duration. Here is a sample:
The whole build took like 10 minutes.
We can easily consume the 25 hours free tier because of these. The crash logs are completely useless. And the failing tests change from one run to the other and on different simulators. I really hope Xcode Cloud team look into this as it's frustrating and kills the whole point of Xcode Cloud (BTW, these issues won't happen on Bitrise).
In XCTestCase, I write data to a file "/tmp/somefile", but the file does not exist in /tmp when I do ls in Terminal.
Where is the file actually created?
Using accessibilityRepresentation on a TextField breaks the UI tests ability to access the field.
It's pretty simple to reproduce. Having found a workaround that doesn't involve removing the custom representation during UI testing.
struct ContentView: View {
@State var text = ""
var body: some View {
VStack {
TextField(text: $text, axis: .vertical) {
EmptyView()
}
.frame(maxHeight: .infinity, alignment: .topLeading)
.padding(8)
.foregroundStyle(.black) // text color
.tint(.blue) // caret color
.overlay {
RoundedRectangle(cornerRadius: 4)
.fill(.clear)
.strokeBorder(.gray)
}
.accessibilityRepresentation {
// axis: .vertical does weird things to VO
// So the representation is a textfield without that
TextField(text: $text, prompt: nil) {
EmptyView()
}
}
.accessibilityLabel("Text area")
}
.padding()
}
}
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
let element = app.textFields["Text area"]
// let element = app.textViews["Text area"] // when no customRepresentation used
element.tap()
element.typeText("Hello")
}
Im having an issue on how to refer to this view / "Allow with passcode" button while UI testing
Im trying to UI test our setup procedure and ScreenTime is a part of that process so I need this approval before I go to my next VC
let stHandler = addUIInterruptionMonitor(withDescription: "“Allow Access to Screen Time")
{ (alert)
or
let stHandler = addUIInterruptionMonitor(withDescription: "“Allow Access to Screen Time")
{ (group)
dont work
Anyone any ideas?
Thanks in advance
I have a bug I am writing a UI Test for and I am struggling to find a way to test the fixed UI vs the buggy UI. In the buggy version, the UI element is visible on the screen but has a 0,0 width and height. It's visible because it's not set to 'clip to bounds', so it's overlaying the rest of my UI.
The app sets the element to be hidden in certain situations and I wanted to make sure in my test, that it's not on the screen in that situation. The problem is that .exists returns true in both situations (.hidden == true, .hidden == false), and .isHittable always returns false because its either no on the screen at all or has a 0,0 width, height.
So I can't use .exists; I can't use .isHittable; and I can't use the .frame either. Is there simply a way to check if it's actually visible?
When trying to test a Catalyst application with XCTest the application crashes at startup with Symbol not found error when certain frameworks are in use. This is caused by XCTest / Xcode adding /Applications/Xcode.app/Contents/SharedFrameworks to DYLD_FRAMEWORK_PATH causing dyld to load the macOS specific framework variant of for example RealityKit instead from /System/iOSSupport/System/Library/Frameworks as defined in the load commands.
Which leads to symbol mismatches, for example ARView.Environment.Color is a UIColor on Mac Catalyst but an NSColor on macOS (_$s10RealityKit6ARViewC11EnvironmentV10BackgroundV5coloryAGSo7UIColorCFZ vs. _$s10RealityKit6ARViewC11EnvironmentV10BackgroundV5coloryAGSo7NSColorCFZ)
Tried prepending /System/iOSSupport/System/Library/Frameworks to the DYLD_FRAMEWORK_PATH env var of the test target, but via some private frameworks still wrong framework variants were loaded.
Any ideas for possible fixes or workarounds?
I'm looking for a way (hopefully with a compiler directive) - in debug mode as well as in my UITests - to determine if a GPX file is being used. You use a GPX file for simulating location - it is set within the scheme settings under "Core Location - Allow Location Simulation".
Is this possible?
I have filed this as FB13722352. I am sharing it here because I haven't seen it mentioned anywhere online yet and am curious if anyone else has run into it.
In Xcode 15.3+, writing data to disk fails when running the tests for a Framework project in a fresh simulator. Specifically, if the selected simulator has never been launched before (i.e. is newly-created), any test execution that attempts to write data into the NSDocumentDirectory directory will fail for a period of time after the simulator is first launched (I've observed between 10s and 20s). After that period of time, the same data write action will succeed. It appears that Xcode 15.3+ is starting test execution too soon, without waiting a sufficient amount of time for the Simulator to fully boot. This issue does not occur in Xcode 15.2 or prior versions.
Since the issue only appears in a fresh (never-before booted) simulator, it is likely to pop up consistently in CI test runs (where simulators are not re-used). This can cause confusion because the same test would not fail locally when re-using an existing simulator.
When the issue appears, the file write API returns the following error:
Domain=NSCocoaErrorDomain Code=4 "The folder “testFile” doesn’t exist." UserInfo={NSFilePath=[...]/data/Documents/testFile, NSUserStringVariant=Folder, NSUnderlyingError= {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"} }
Reproduction Steps:
Open Xcode 15.3 or 15.4. Make sure Simulator.app is closed.
Using the "Devices and Simulators" window, create a new iPhone 15 Pro simulator with iOS 17.4 (other devices and OS versions work as well). Do not launch this new simulator.
Create a new Framework project and add a test that performs and then checks the output of a data write to the Document directory (see example test code below).
Select the new simulator (created in step 2) as the test run target and run the test.
Here's an example test that fails in the scenario outlined above:
- (void)testBasicRepro {
NSString *testString = @"Hello, World!";
NSData *data = [testString dataUsingEncoding:NSUnicodeStringEncoding];
// Get documents directory
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *testFileURL = [url URLByAppendingPathComponent:@"testFile"];
// Write the data
NSError *error;
bool result = [data writeToURL:testFileURL options:NSDataWritingAtomic error:&error];
// Check if it was successful
XCTAssertTrue(result);
XCTAssertNil(error);
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:testFileURL.path]);
}
Workaround
The workaround that I have come up with is to create a test that runs first (by disabling parallelization and randomization, and making sure the test class filename is alphabetically first). Alternatively, it could be called from the setUp method in any test files that are affected. This test performs a data write and checks the result in a loop in order to block until the data write succeeds (i.e. the Simulator is sufficiently booted for data write operations to complete).
- (void)testWorkaroundBug {
NSString *testString = @"Hello, World!";
NSData *data = [testString dataUsingEncoding:NSUnicodeStringEncoding];
NSError *error;
// Get documents directory
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *testFileURL;
NSDate *startTime = [NSDate date];
NSLog(@"Starting test at %@", startTime);
for (int i = 0; i < 120; i++) {
// Create unique URL
testFileURL = [documentsURL URLByAppendingPathComponent:[NSString stringWithFormat:@"testFile-%@", @(i)]];
// Write the data
BOOL success = [data writeToURL:testFileURL options:NSDataWritingAtomic error:&error];
// Check if it exists
if (success && [[NSFileManager defaultManager] fileExistsAtPath:testFileURL.path]) {
NSLog(@"Test file %@ was created successfully! Elapsed time %@s", @(i), @(fabs([startTime timeIntervalSinceNow])));
return;
}
else {
NSLog(@"Test file %@ was not created. Error: %@. Sleeping for 0.5s and trying again.", @(i), error);
[NSThread sleepForTimeInterval:0.5];
}
}
}
Hi,
Recently noticed this issue on Xcode 15.2
When I select a Test Plan, disable a class, enable just 1 test within that class and refresh the test plan the entire class gets enabled again.
steps to notice the issue:
Select Test Plan 1
Disable a class
Enable 1 test within the class
Select Test Plan 2
Select Test Plan 1
Disabled class and all the tests inside the class are enabled.
Note: For now the workaround for that is disabling each test of the class individually
Does anyone have any idea why this is happening? If theres a way to disable a class instead of disabling each test inside the class?
In V 0.1 of my app, I went with a simple option for a piece of business logic in my app.
I then changed something else that caused my simplified business logic to now crash the app at startup.
Excellent, a chance to use Test. Driven Design to replace my flawed business logic.
So I wrote my first test TDD test, but when I tried to run the test... It doesn't run because running the test target seems to start by actually running my full app (which as I described in chapter 1 is currently crashing)
Have I configured something incorrectly? or is it normal that when I attempt to run a single test, step 1 is running the full app?
(note: it is very easy for me to disable/avoid the business logic causing my crash. This question is more about my lack of understanding of what it means to run a test target.)
thanks in advance for any and all responses.
Mike
Hello everyone, I looked at various methods how to Unit/UITest SwiftData but I couldn't find something simple. Is it even possible to test SwiftData? Does someone found a solution for that?