|
43 | 43 | expect { Net::VNC.open(WITH_AUTH_SERVER_DISPLAY) }.to raise_error(RuntimeError, 'Need to authenticate but no password given') |
44 | 44 | end |
45 | 45 | end |
| 46 | + |
| 47 | + context 'screenshotting' do |
| 48 | + def verify_screenshot(input) |
| 49 | + image_size = ImageSize.path(input) |
| 50 | + expect(image_size.format).to eq :png |
| 51 | + expect(image_size.width).to eq 1366 |
| 52 | + expect(image_size.height).to eq 768 |
| 53 | + end |
| 54 | + |
| 55 | + it 'should allow you to take a screenshot with a path' do |
| 56 | + Tempfile.open('ruby-vnc-spec') do |screenshotfile| |
| 57 | + Net::VNC.open(NO_AUTH_SERVER_DISPLAY) do |vnc| |
| 58 | + vnc.pointer_move(10, 15) |
| 59 | + vnc.take_screenshot(screenshotfile.path) |
| 60 | + end |
| 61 | + verify_screenshot(screenshotfile.path) |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + it 'should allow you to take a screenshot with a blob' do |
| 66 | + Tempfile.open('ruby-vnc-spec-blob') do |screenshotfile| |
| 67 | + vnc = Net::VNC.open(NO_AUTH_SERVER_DISPLAY) |
| 68 | + begin |
| 69 | + vnc.pointer_move(10, 15) |
| 70 | + blob = vnc.take_screenshot(nil) |
| 71 | + screenshotfile.write(blob) |
| 72 | + ensure |
| 73 | + vnc.close |
| 74 | + end |
| 75 | + |
| 76 | + verify_screenshot(screenshotfile.path) |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + it 'should allow you to take a screenshot with a IO-object' do |
| 81 | + screenshotfile = File.new("out.png", "w") |
| 82 | + |
| 83 | + begin |
| 84 | + Net::VNC.open(NO_AUTH_SERVER_DISPLAY) do |vnc| |
| 85 | + vnc.pointer_move(10, 15) |
| 86 | + vnc.take_screenshot(screenshotfile) |
| 87 | + end |
| 88 | + verify_screenshot(screenshotfile) |
| 89 | + ensure |
| 90 | + screenshotfile.close |
| 91 | + File.delete(screenshotfile) |
| 92 | + end |
| 93 | + end |
| 94 | + end |
46 | 95 | end |
0 commit comments