Copy *.db3 file to iOS Simulator

Hi,

what I want to achieve for the Test of my .NET MAUI App is that my Appium Test provides the corresponding Test-Database file and if I am in Test-Execution my App takes this Database instead of the productive one.

I already have provided the corresponding flags so that my App detects it is in Test-Execution mode and could switch the database path correspondingly. For my Android Test it is already working that I provide the *.db3 SQLite database file to the Simulator via driver?.PushFile(remoteFilePath, new FileInfo(localFilePath)); after the driver instance was created.

For iOS it does not work with the Upload of the file. First of all, I detected that driver = new IOSDriver(_appiumService.ServiceUrl, options); already starts the iOS Simulator and the corresponding App including detection if it is Test Execution.

But, what still is missing is the *.db3 File in the corresponding folder of the iOS Simulator instance. The command driver?.PushFile(remoteFilePath, new FileInfo(localFilePath)); does not work and it quits with an error message that the file type is not allowed/supported. So, it seems like only media files are allowed.

Is there a way, how I can provide my database file to the corresponding iOS Simulator “Library” Directory having the right App-UDID (which is generated for every run of the Simulator) and prior to the final launch of the App?

Okay, it looks like the following worked:

// Source file
string localFilePath = Path.Combine("TestDatabase", "MyTestDatabaseSQLite.db3");

// Read and convert to Base64 format
byte[] data = File.ReadAllBytes(localFilePath);
string base64Data = Convert.ToBase64String(data);

// "data" here means the AppDataDirectory and the file will be copied to subfolder /Library/TestDatabase/... on iOS Simulator
driver?.PushFile("@com.myapp.app:data/Library/TestDatabase/MyTestDatabaseSQLite.db3", base64Data);