简体   繁体   中英

How to integrate a PayPal browser login into Visual Studio Integration tests?

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".

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;

    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM