[英]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.