WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

How to using WireMock.NET with Appium to mock mobile app response

Open vfongmala-willowinc opened this issue 4 years ago • 4 comments

I have a mobile app which is pointing to real URL (with HTTPS). I run an automation test on the app by using Appium framework.

I want to intercept the response from real URL with the mock data without changing the URL on the app. What would be the correct configuration to start the server?

What I've tried.

  1. I set Android emulator proxy to my local machine IP address with port 7777
  2. I setup the WireMock server like this
_server = WireMockServer.Start(new WireMockServerSettings()
{
    Urls = new[] { "https://<real url>:443"},
    Port = 7777,
    Logger = new WireMockConsoleLogger(),
});
  1. I didn't have any specific certificate setup for HTTPS. Do I need one?

However, it doesn't seems to work as I expect. Emulator couldn't connect to WireMock server and couldn't connect to the real server either.

vfongmala-willowinc avatar Oct 07 '21 05:10 vfongmala-willowinc

Hi @vfongmala-willowinc,

You could take a look over it,Proxying

_server = WireMockServer.Start(new WireMockServerSettings()
{
    Urls = new[] { "http://localhost:777"},
    ProxyAndRecordSettings = new ProxyAndRecordSettings
    {
        Url = "https://<real url>:443",
        SaveMapping = true,
        SaveMappingToFile = true,
        SaveMappingForStatusCodePattern = "2xx"
    },
    Logger = new WireMockConsoleLogger(),
});

I think you should change the URL in the app for http://localhost:777 that is the WireMock.Net service then, if all will be working you should see an auto generate file with a name (GUID) in __admin/mappings

After you mock it, then you should run again the wiremock.net server but with this config:

_server = WireMockServer.Start(new WireMockServerSettings()
{
    Urls = new[] { "http://localhost:777"},
    StartAdminInterface = true,
    ReadStaticMappings = true,
    Logger = new WireMockConsoleLogger(),
});

Finally you will be able to use the mock data in the URL "http://localhost:777".

leolplex avatar Oct 07 '21 15:10 leolplex

Hi @leolplex Can I do the mock server without recording and mapping? And Can I do it without changing app URL to localhost? I already have mock data for responses. And I just want to make the responses of it.

vfongmala-willowinc avatar Oct 07 '21 16:10 vfongmala-willowinc

Hi @vfongmala-willowinc

Yes you can mock server without recording and mapping but you need keep the WireMockDotNet standar.

I don't know how mock without changing app URL.

Take a look over this WireMock.Net structure.

leolplex avatar Oct 10 '21 17:10 leolplex

Hi @leolplex, сan I use wiremock as a proxy I need to skip all requests to the real server but while researching all requests and answers, in order to get the right answer coming to the phone I replaced the data, as it is done in the Charles program?

Vadym1123456 avatar Oct 25 '21 12:10 Vadym1123456

I'm closing this issue for now.

If there are any Appium specific steps to take, I can create a new WIKI page, but I think that the general idea on how to use WireMock.Net is the same for all integrations.

Else, please create a new issue with a wiki-page proposal on this topic.

StefH avatar Sep 19 '22 05:09 StefH