7

We are evaluating App Test Tools and Appium is a candidate for us, however I could not find a good solution how to Mock the backend when using Appium?

Consider: - I want to have a single UI test which will be executed on iOS and Android apps (Appium supposes to be multiplatform)

  • The test scenario:

    1. Press on a button in Native App.
    2. Native App will call an external API (needs to be mocked).
    3. Native App shows some text.
    4. Assertion.

Questions:

  • How to mock the API call?

  • Appium uses the built project (e.g. apk). is there any way to integrate and configure the application before building from Appium side? e.g. if Appium triggers the build, then the App should uses the fake API response (JSONs).

masoodg
  • 581
  • 5
  • 8

3 Answers3

1

As far as I know, Appium does not have the capacity to mock any API because all appium does is look into the screen and automate what a user can do manually like clicking a button etc.

Paul Sturm
  • 2,118
  • 1
  • 18
  • 23
0

Appium invokes Application under test (AUT) and performs an action on it (Like click, press, enter text). If AUT points at a certain endpoint to get responses Appium cannot change that. Although AUT can be built to consume a mock endpoint.

create a local mock server and expose it on a port (ex:3000) and use ngrok to create a publicly accessible endpoint and then build your app to point at this endpoint. mockserver can be a hybrid mock server which can mock some responses and rest of them can be directed to real backend.

Tejasvi Manmatha
  • 564
  • 7
  • 12
0

Additional way to get some info from device logs. On my project in iOS app developers hid all info there due to security, but in Android app I can read log data. Here is where I can save device logs.

  1. conftest.py

    @pytest.fixture
    def appdriver():
    
    driver = config.get_driver_caps()
    
    if config.IS_IOS:
        driver.start_recording_screen(videoQuality='high', videoType='mpeg4', videoFps='24')
    else:
        driver.start_recording_screen()
    
    yield driver
    
    attach_device_log(driver)
    save_video(driver)
    driver.quit()
    
  2. attach_device_log()

    def attach_device_log(appdriver):
    if config.IS_ANDROID:
        device_logs = appdriver.get_log('logcat')
    else:
        device_logs = appdriver.get_log('syslog')
    
    os.path.dirname(os.path.abspath('/tests/'))
    
    with open('device_log.txt', 'w') as file:
        file.write('')
    
        for item in device_logs:
            file.write('%s\n' % item)
        file.close()
    
    allure.attach.file(
        source=f'device_log.txt', name='device_log')
    

In my example I get logs for the report only. You can get logs during a test and parse data as you want.

Mikhail Barinov
  • 120
  • 1
  • 2
  • 10