Skip to content

SIFT iOS Local Set Up

Olena Vashchenko edited this page Mar 30, 2023 · 5 revisions

Getting Started

Start by visiting Application and Tests Build Setup to learn how to integrate SIFT into your project:

  • Build a binary for XCUITest from the terminal
  • Setup SIFT node(s)
  • Description of the fields in the config file table
  • How to set up SSH key
  • Setup test nodes
  • Local simulators and connected devices
  • How to set up multiple simulators of the same model
  • In case of issues

Then find out how to run the tests from SDK IDE or the command line.

Find out how to collect the tests run results by visiting one of the corresponding section:

  • View results from Finder
  • View results from the command line
  • View results from Xcode

View results in different formats:

  • Final results.json view
  • Final results.txt view
  • Final results.xml view

For more help and examples, watch our video tutorials and use our sample app.

Environment requirements

SIFT is a native solution, which means you use the same tech stack as you do while creating your app. Programing language - Objective-C or Swift. Development environment - Mac, Xcode version 13 and above. Also - the Homebrew application.

Tip In case you’re missing Xcode documentation, SDK, go to https://developer.apple.com/ To install Homebrew, visit https://docs.brew.sh/Installation

Watch this video tutorial for more information on setting up the SDK.

Application and tests build setup

Open your application from Xcode and create a Test Plan to set up.

Watch video tutorial

Next, you should make the builds for testing. To do this, follow this path: Product -> Build For -> Testing

Next, go to the DerivedData folder, and find the path to the file .xctestrun. In the following steps, you will use this path in the config.json file as a value for the key "xctestrunPath".

Build a binary for XCUITest from the terminal

Use the terminal to build a binary for testing. Specify a path to DerivedData so that it will be easier to find the xctestrun file. Use the path to the xctestrun file from this directory as a value for the key "xctestrunPath"

Example:

xcodebuild -workspace MyApp.xcworkspace -scheme MyAppScheme -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12,OS=16.2' -derivedDataPath pathToFolderForXctestrunFIle build-for-testing

Or with the project file

xcodebuild -project MyApp.xcodeproj -scheme MyAppScheme -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12,OS=16.2' -derivedDataPath pathToFolderForXctestrunFIle build-for-testing

Setup sift node(s)

Go to https://github.com/engeniousio/sift-ios (production branch).

Watch video tutorial

Create a new empty folder on your computer and clone SIFT repo.

To launch SIFT, open the terminal, then go to the folder with SIFT, and write this command: sh make.sh for M1 processors use this one arch -x86_64 sh make.sh

Watch video tutorial

When the script is completed, write the following command: swift build -c release Wait for the indication that the build is complete.

You are now ready to enable remote login by following this path:

System Preferences -> Sharing -> Remote Login

Then set up SSH key.

Watch video tutorial

Next, go to the path SIFT\.build\release and create here "config.json" file. Click the config.json file hold option button and Copy “config.json” as Pathname.

To continue to build and set up SIFT nodes, return to the SIFT folder and select the “Package.swift” folder.

Create and set up a new scheme for the SIFT’s test run

Create a new scheme for the SIFT’s test run. Then set up the scheme. Add parameters to the scheme:

  • First, choose “Run” in the left panel. Then add Arguments Passed On Launch:
  • “run” command for running tests
  • “--config” + the path to the config.json file on your sift node
  • “--verbose”

Using this scheme, you can run SIFT from Xcode.

Watch video tutorial

You are now ready to use the path to create the config file. Now you can reuse the template of the config file.

Example of reusing the template of the config file to set up the test run, output file and deployment:

`{`
 `"xctestrunPath": "path to .xctestrun, this file generate by Xcode when make a build for test",`
    `"outputDirectoryPath": "path where tests results will be collected",`
    `"rerunFailedTest": 1, //attempts for retry`
    `"testsBucket": 1,`
    `"testsExecutionTimeout": 120, //timeout`
    `"nodes": //array of nodes (mac)`
    `[`
        `{`
          `"name": "Node1",`
          `"host": "127.0.0.1",`
          `"port": 22,`
          `"deploymentPath": "path where all necessary stuff will be stored on the node",`
         `"UDID": {`
                        `"devices": ["devices udid, can be null"],`
                        `"simulators": ["simulators udid, can be null"]`
                    `},`
          `"xcodePath": "/Applications/Xcode.app",`
          `"authorization": {`
            `"data": {`
              `"username": "username",`
              `"password": "password"`
            `}`
          `}`
        `}`
    `]`
`}`

Setup the output folder.

Add a new folder for the Results of the runs.

Create the folder for the deployment

Then create another folder for the development. Then copy the path to "WorkSpaceSift" and paste it in config.json file as a value for "deploymentPath".

Preliminary setup of the test nodes

Click on App in the left column. Then click on Window to view the drop-down list. Click on Devices and Simulators. Select a simulator to acquire the identifier. Update the simulator identifier in the code.

Setup the username and password

Paste the name of your Mac and the password to Mac as a value for "username" and "password". Then save config.json.

Description of the fields in the config file table

Description of fields in the table

Field Description
xctestrunPath to get this file you have to build the project for tests and then go to DerivedData folder and find the path to the file .xctestrun
outputDirectoryPath in your SIFT folder create Results folder and give the path to this key
host 127.0.0.1, - Localhost has always the IP address 127.0.0.1. For remote nodes use the ip address of the remote machine
port 22 - for SSH connection
username name of your machine - use the terminal command “echo $USER” and you will see the name of your machine
password password of your machine
deploymentPath you can create WorkspaceSift folder right in your SIFT folder. Sift creates copies of test runners on every node and keeps and uses them from this folder

How to set up SSH key

  1. The first step is to create the key pair on the client machine:

ssh-keygen -t rsa

  1. Once you have entered the Gen Key command, you will get a few more questions about the file to save the key and a passphrase. Use the default id_rsa name for the key and empty passphrase.

  2. Once the key pair is generated, it’s time to place the public key on the server that we want to use. You can copy the public key into the new machine’s authorized_keys file with the command:

cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

  1. Alternatively, you can add in the keys using SSH (if authorized keys exist):

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

  1. Make sure that remote login is allowed on your machine:

ssh username@ip-address

  1. Now you can log into your user profile. You will not be prompted for a password. However, you will be asked to enter the passphrase at that time (and whenever else you log in in the future), if you set a passphrase when creating your SSH key.

Setup test nodes

Watch video tutorial

Local simulators and connected devices

You need to check the simulators' UDID for every node separately because they differ for different machines. You can do this using the same procedure that was mentioned earlier as follows:

  1. Go to Xcode -> Window->Devices and Simulators
  2. In this window, you can observe the data about connected devices or simulators; the field “Identifier is” your UDID.

How to set up multiple simulators of the same model

Xcode gives you one simulator for one model by default. But if you need to run your tests with the same model, you can add it manually.

  1. Open Xcode -> Window -> Devices and Simulators
  2. Tap-click on Add button(“+”) in the upper left corner of the screen
  3. In the “Create a new simulator” box, choose the model you want to add
  4. Give the new simulator a different name and choose the OS version and click “Create”

In case of issues

To avoid issues while running tests on a device, follow these recommendations:

  1. check if you have trusted certificates (Xcode -> Preferences -> Accounts -> Manage certificates),
  2. check if your app is verified on the device (Settings -> General -> VPN & Device Management),
  3. make a special device build for testing (choose your device or Any iOS Device(arm64) in Xcode before building for testing)

Run The Tests

Watch video tutorial

Running the tests

Following the schema created earlier, you may run tests with SIFT from the Xcode project. Please check that all Pre-requirements have been implemented. When you are ready with your config.json file, go to the SIFT repo-> .build -> release and save config.json file here.

The .build folder is supposed to be hidden. To make your folders unhidden, follow these commands: use the shortcut “command+shift+>” (or in the terminal, type in defaults write com.apple.Finder AppleShowAllFiles true and press “Enter”. Then type in killall Finder and press “Enter” again) and you will see hidden files; you need to open the “.build->release” folder and paste here your JSON file.

Start a test run from SDK IDE

In Xcode, choose the scheme you’ve created for running Sift and run the project. For example, execute the test run by clicking on the iPhone 14 Pro button in the lower right of the screen.

All tests will be loaded, and the simulator will be displayed.

Start the test run from the command line

Watch video tutorial

In the terminal, go to sift -> .build -> release folder (the folder where Sift executable is located) and write the commands:

./sift run --config config.json // run the tests

./sift list --config config.json // print all tests from the bundle (check before the run)

View Results

Watch video tutorial

The Test results can be viewed in different ways. Choose the option that best fits your needs.

View results from Finder

When you run your tests, go to the directory you set in config.json file as a value for "outputDirectoryPath" and check the output.

View results in different formats

Go to "outputDirectoryPath" that you set in config.json file and check results in formats .json, .txt, .xcresult and .xml.

View results from the command line

You can view results in the command line only if you run tests from the command line.

View results from Xcode

To view the results from Xcode, follow the path: Xcode -> sift -> Results/final

View the statistics of the Xcode test run.

View the test run results

If you want to save all run results, move them to a separate folder because SIFT refreshes the Results folder before every new test run.

Final results.json view Final results.txt view Final results.xml view