【发布时间】:2014-08-05 11:47:32
【问题描述】:
我正在使用 Watir-WebDriver 运行我们的 Rails 应用程序的自动化测试,并在过去几天探索了比较特定元素的屏幕截图的可能性。
我正在使用这个 gem:watir-extensions-element-screenshot (here) 来捕获特定元素的屏幕截图。此 gem 捕获整个页面的屏幕截图,然后对其进行裁剪以挑选出请求的元素。
这一切在 Chrome 和 Firefox 中运行良好,但 Internet Explorer 引起了问题。当我运行自动化测试时,crop! 函数会引发以下异常:ChunkyPNG::OutOfBounds: Original image width is too small!
当crop_width + x > width 时抛出此异常,其中crop_width 是要裁剪的元素的宽度,x 是要裁剪的图像左上角的 x 坐标,width 是原始图像的宽度。
当我在测试期间打印一些值时,我确实可以确认上面的值:crop_width: 940, crop_height: 562x: 363, y: 211width: 900, height: 520 #why are these so small?
当我在 IRB 中手动捕获相同元素的屏幕截图时,它工作得很好:irb(main):013:0> b = Watir::Browser.new :ie=> #<Watir::Browser:0x422422cc url="http://localhost:5555/" title="WebDriver">irb(main):014:0> b.goto 'localhost:3000'irb(main):015:0> b.div(:id => 'lbcontent').screenshot('ie_test.png')
@987654336 @x: 371, y: 195width: 1680, height: 909=> #<File:ie_test.png (closed)>
所以显然 IEDriverServer 在捕获屏幕截图时会调整大小,但在 IRB 中一切正常......有人有解释和/或解决方案吗?
【问题讨论】:
标签: internet-explorer screenshot watir-webdriver