test/curlyq_scrape_test.rb in curlyq-0.0.9 vs test/curlyq_scrape_test.rb in curlyq-0.0.10
- old
+ new
@@ -9,14 +9,44 @@
# Tests for tags command
class CurlyQScrapeTest < Test::Unit::TestCase
include CurlyQHelpers
def setup
+ @screenshot = File.join(File.dirname(__FILE__), 'screenshot_test')
+ FileUtils.rm_f("#{@screenshot}.pdf") if File.exist?("#{@screenshot}.pdf")
+ FileUtils.rm_f('screenshot_test.png') if File.exist?("#{@screenshot}.png")
+ FileUtils.rm_f("#{@screenshot}_full.png") if File.exist?("#{@screenshot}_full.png")
end
- def test_scrape
+ def teardown
+ FileUtils.rm_f("#{@screenshot}.pdf") if File.exist?("#{@screenshot}.pdf")
+ FileUtils.rm_f('screenshot_test.png') if File.exist?("#{@screenshot}.png")
+ FileUtils.rm_f("#{@screenshot}_full.png") if File.exist?("#{@screenshot}_full.png")
+ end
+
+ def test_scrape_firefox
result = curlyq('scrape', '-b', 'firefox', '-q', 'links[rel=me&content*=mastodon][0]', 'https://brettterpstra.com/2024/01/10/introducing-curlyq-a-pipeline-oriented-curl-helper/')
json = JSON.parse(result)
- assert_match(/Mastodon/, json['content'], 'Should have retrieved a Mastodon link')
+ assert_equal(Array, json.class, 'Result should be an Array')
+ assert_match(/Mastodon/, json[0]['content'], 'Should have retrieved a Mastodon link')
+ end
+
+ def test_scrape_chrome
+ result = curlyq('scrape', '-b', 'chrome', '-q', 'links[rel=me&content*=mastodon][0]', 'https://brettterpstra.com/2024/01/10/introducing-curlyq-a-pipeline-oriented-curl-helper/')
+ json = JSON.parse(result)
+
+ assert_equal(Array, json.class, 'Result should be an Array')
+ assert_match(/Mastodon/, json[0]['content'], 'Should have retrieved a Mastodon link')
+ end
+
+ def test_screenshot
+ curlyq('screenshot', '-b', 'firefox', '-o', @screenshot, '-t', 'print', 'https://brettterpstra.com')
+ assert(File.exist?("#{@screenshot}.pdf"), 'PDF Screenshot should exist')
+
+ curlyq('screenshot', '-b', 'chrome', '-o', @screenshot, '-t', 'visible', 'https://brettterpstra.com')
+ assert(File.exist?("#{@screenshot}.png"), 'PNG Screenshot should exist')
+
+ curlyq('screenshot', '-b', 'firefox', '-o', "#{@screenshot}_full", '-t', 'full', 'https://brettterpstra.com')
+ assert(File.exist?("#{@screenshot}_full.png"), 'PNG Screenshot should exist')
end
end