Skip to content

Mock intercept looks like has a side effect on can't load the data from the internet from the second test case within one Appium session #91

@ansonliao

Description

@ansonliao

My Appium interceptor-plugin version is 1.0.2. My test case suite of WebDriverIO is similar to the following.

The test suite "Intercept Mock Tests" below includes 2 test cases.
The problem is when the first test case finishes successfully (add mock, and remove mock no problem), and when the test runner continues to the second test case, the mobile app is stuck at the await loadDataOnTheHomeScreen(); this step will load data and displays on the screen, the problem is the app is keep loading data until the test case failed, when the test case failed, the Appium session is end, the network is resumed and the data is loaded and shows on the home screen.
How can I solve this problem?

Thanks.

var mockId;
describe("Intercept Mock Tests", () => {
  before(async () => {
    await launchApp();
  });

  beforeEach(async () => {
    await loadDataOnTheHomeScreen();
  });

  afterEach(async() => {
    await driver.execute("interceptor: removeMock", {
          id: mockId,
        });
  });

  ["enabled", "disabled"].forEach((mode) => {
     it("Mock Response", async () => {
        const mockConfig = {
              url: "**/api/v1/mobile/access",
              updateResponseBody: [
                {
                  jsonPath: "$.githubAccess",
                  value: mode === "enabled",
                },
            ],
          };
        mockId = await driver.execute("interceptor: addMock", {
          config: mockConfig,
        });
        await $("~github.login").click();
        if (mode ==== "enabled") {
          await expect($("~github.login.button")).toBeDisplayed();
        } else {
          await expect($("~github.login.button")).not.toBeDisplayed();
        }
      });
  });
 
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions