简体   繁体   English

将整个网页与所有资产一起保存在Selenium WebDriver中

[英]Save entire web page with all assets in Selenium WebDriver

I am looking a way to save the current DOM state of the webpage into a separate .html/.mht file with all images, JavaScript and CSS files included. 我正在寻找一种将网页的当前DOM状态保存到包含所有图像,JavaScript和CSS文件的单独的.html / .mht文件中的方法。

I know driver. PageSource 我认识driver. PageSource driver. PageSource / driver.getPageSource() allows to get the current DOM state, but how can I save all statically/dynamically referenced images, JavaScript files, CSS files and other assets? driver. PageSource / driver.getPageSource()允许获取当前的DOM状态,但是如何保存所有静态/动态引用的图像,JavaScript文件,CSS文件和其他资产?

Example, why I need this: 例子,为什么我需要这个:

For instance, the web application is a Single Page Application , based on KnockoutJS framework. 例如,Web应用程序是基于KnockoutJS框架的Single Page Application
When an error occurs during the test execution, I would like to have the HTML page which has all dynamically generated content in order to investigate the problem. 如果在测试执行过程中发生错误,我希望HTML页面包含所有动态生成的内容,以便调查问题。

When I perform a static HTTP download -- it always gives me the project login page, instead of the current opened documents. 当我执行静态HTTP下载时-它总是为我提供项目登录页面,而不是当前打开的文档。

Ok I think you might be thinking about the issue in a wrong way. 好的,我认为您可能会以错误的方式考虑此问题。 Downloading the whole thing is not the answer to your problem. 下载整个内容并不能解决您的问题。

Selenium is a very good tool for understanding flaws in the software from the user perspective based on the stories and requirements but when it comes to the underlying issues and it's investigation you are going to need the right tool for job. Selenium是一个很好的工具,可以根据用户的故事和要求从用户的角度理解软件中的缺陷,但是当涉及到潜在问题和调查时,您将需要正确的工具来工作。

luckily if you are using KO and MVVM pattern you are benefiting from a code structure that lends itself well to unit testing which is exactly what you need in order to investigate what has gone wrong and not the snapshot code of the application. 幸运的是,如果您使用的是KO和MVVM模式,那么您将从代码结构中受益,该代码结构非常适合进行单元测试,这正是您需要调查发生问题的地方,而不是应用程序的快照代码。

if for all methods in your view model (or at least the important ones) you write good unit test coverage (jasmine.js is so easy to use) you can just run your test suite and when a selenium test fails then see which unit tests are also failing and that will get you a lot quicker to the solution. 如果对于视图模型中的所有方法(或至少重要的方法)都编写了良好的单元测试覆盖率(jasmine.js如此易于使用),您可以只运行测试套件,而当硒测试失败时,则查看哪些单元测试也会失败,这将使您更快地找到解决方案。

here are some resources for you to look at: 以下是一些资源供您查看:

KnockoutJS and Testing KnockoutJS和测试

http://machadogj.com/2011/10/unit-testing-wit-knockout-js-with-tdd.html http://machadogj.com/2011/10/unit-testing-wit-knockout-js-with-tdd.html

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

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