0

We are integrating PayPal Express Checkout into our e-commerce application. The way this works is there a "gateway" that connects the website to the PayPal servers via the PayPal SDKs. I am writing integration tests for that API in Visual Studio. With regular API tests, it is possible to chain requests in any order and run tests. Here is the flow with a typical Express Checkout Integration SetExpressCheckout Call -> get token and login with buyer account (in a browser) -> Optional GetExpressCheckout Call -> DoExpressCheckout Call -> DoAuthorize Call -> DoCapture Call

The issue is that I am unable to simulate the browser login without breaking the test flow. I need to be able to start the test, have the test class open a browser window. I can login there and close the window. Now, I need the test to detect the browser closure and then process with DoExpressCheckout and the subsequent tests. Can this be achieved ?

I searched for some tools but all I get is browser automation. It does not apply to me because at this point I do not have a website to work with. I am just going off of JSON request to my "gateway".

Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

2

Building upon the answer given by @philn, I built a method for it. For the benefit of everyone, here is the code.

    private bool CustomerLogin(string token)
    {
        Process browserProcess = new Process()
        {
            EnableRaisingEvents = true
        };
        bool success = false;

        browserProcess.StartInfo = new ProcessStartInfo("iexplore.exe",
            "-nomerge https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + token);
        browserProcess.Exited += browserProcess_Exited;
        browserProcess.Start();
        browserProcess.WaitForExit();

        if (eventHandled) success = true;
        return success;
    }

    //Event handler for browser login
    internal void browserProcess_Exited(object sender, EventArgs e)
    {
        eventHandled = true;

    }
0

Not a perfect solution, but

have the test class open a browser window. I can login there and close the window. Now, I need the test to detect the browser closure

can be archieved with something similar to this: Wait till a process ends

Community
  • 1
  • 1
philn
  • 313
  • 2
  • 13