简体   繁体   English

如何将PayPal浏览器登录信息集成到Visual Studio集成测试中?

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

We are integrating PayPal Express Checkout into our e-commerce application. 我们正在将PayPal Express Checkout集成到我们的电子商务应用程序中。 The way this works is there a "gateway" that connects the website to the PayPal servers via the PayPal SDKs. 运作方式是有一个“网关”,可通过PayPal SDK将网站连接到PayPal服务器。 I am writing integration tests for that API in Visual Studio. 我正在Visual Studio中为该API编写集成测试。 With regular API tests, it is possible to chain requests in any order and run tests. 使用常规API测试,可以按任何顺序链接请求并运行测试。 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 这是典型的Express Checkout集成SetExpressCheckout调用->获取令牌并使用买方帐户登录(在浏览器中)的流程->可选的GetExpressCheckout调用-> DoExpressCheckout调用-> DoAuthorize调用-> DoCapture调用

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. 现在,我需要测试以检测浏览器是否关闭,然后使用DoExpressCheckout和后续测试进行处理。 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". 我刚从JSON请求发送到我的“网关”。

Building upon the answer given by @philn, I built a method for it. 在@philn给出的答案的基础上,我为它建立了一个方法。 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 可以使用类似以下内容的文件: 等待过程结束

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 中一次运行使用 Restharp 和 Web 应用程序编写的 xUnit 集成测试? - how to run xUnit integration tests written using Restharp and web application at a time in visual studio? 是否可以使用Visual Studio获得用于集成测试的代码覆盖率数据? - Is it possible to get code coverage data for integration tests using Visual Studio? MSTest-使用Visual Studio服务(TFS和持续集成)运行测试 - MSTest - Running tests using visual studio services (TFS and Continous Integration ) 如何将 sonarqube 与 Visual Studio 解决方案集成 - How to integrate sonarqube with a visual studio solution 如何在 Visual Studio 2019 中将 python 代码与 C# 集成 - How to integrate python code with C# in Visual Studio 2019 如何在Visual Studio 2008中集成C ++编译器 - How to Integrate C++ compiler in Visual Studio 2008 如何将 SAP B1 集成到 Visual Studio 2008? - How I can SAP B1 to integrate to visual studio 2008? 如何将 Astra sdk 与 Visual Studio 2013 C# 集成? - How to integrate Astra sdk with visual studio 2013 C#? 使用Visual Studio Team Services通过内存中的SQL数据库运行单元/集成测试 - Running Unit / Integration tests through an in-memory SQL database using Visual Studio Team Services 如何编写集成测试? - How to write integration tests?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM