使用 Internet Explorer 进行 E2E 测试,我需要下载一个文件
E2E test with internet explorer where I need to download a file
如何在量角器中创建 Internet Explorer 配置文件以自动下载文件。
我找到了 Chrome 和 Firefox,但找不到 Internet Explorer
参考:Protractor e2e test case for downloading pdf file
谢谢
虽然这不能直接回答您的问题,here 是关于“如何使用 selenium 下载文件以及为什么不应该”的优秀博客的 link。作者讨论了不同的用例,并在 Java 中提供了一个后门解决方案来执行此操作。文章提到的最关键的问题是
"What are you going to do with this downloaded file?"
"Do you want to just makes sure that you get 200 OK from the server?"
"Do you want to verify the content?"
显然大多数人会对“200 OK 验证”说“是”,如果你想验证 PDF 文档的内容,那么它无论如何都在 selenium 的范围之外。 article 提供了 Java 解决方案来检查您是否从服务器获得 200 OK,因为您使用的是量角器,我将提供一个 nodejs 解决方案。
var request = require('request');
var fileDownloadElement = element(by.css('#download'));
fileDownloadElement.getAttribute('href').then(function(url) {
request(url,function(error, response, body){
if(error) {
throw new Error('Error downloading file', error);
}
if(response.statusCode !== 200) {
throw new Error('Server threw non 200 OK status ->', response.statusCode);
}
if(!body) {
throw new Error('Server did not respond with any data');
} else {
//write body to a file if you want to do anything with it
}
});
});
我在这里使用了 request 客户端,您可以使用它或任何其他类似的客户端。
免责声明:我没有测试过这段代码,但希望你能理解。
如何在量角器中创建 Internet Explorer 配置文件以自动下载文件。
我找到了 Chrome 和 Firefox,但找不到 Internet Explorer
参考:Protractor e2e test case for downloading pdf file
谢谢
虽然这不能直接回答您的问题,here 是关于“如何使用 selenium 下载文件以及为什么不应该”的优秀博客的 link。作者讨论了不同的用例,并在 Java 中提供了一个后门解决方案来执行此操作。文章提到的最关键的问题是
"What are you going to do with this downloaded file?"
"Do you want to just makes sure that you get 200 OK from the server?"
"Do you want to verify the content?"
显然大多数人会对“200 OK 验证”说“是”,如果你想验证 PDF 文档的内容,那么它无论如何都在 selenium 的范围之外。 article 提供了 Java 解决方案来检查您是否从服务器获得 200 OK,因为您使用的是量角器,我将提供一个 nodejs 解决方案。
var request = require('request');
var fileDownloadElement = element(by.css('#download'));
fileDownloadElement.getAttribute('href').then(function(url) {
request(url,function(error, response, body){
if(error) {
throw new Error('Error downloading file', error);
}
if(response.statusCode !== 200) {
throw new Error('Server threw non 200 OK status ->', response.statusCode);
}
if(!body) {
throw new Error('Server did not respond with any data');
} else {
//write body to a file if you want to do anything with it
}
});
});
我在这里使用了 request 客户端,您可以使用它或任何其他类似的客户端。
免责声明:我没有测试过这段代码,但希望你能理解。