0

I have one Java Jar file that I am able to use successfully in my selenium framework. I would like to use the same jar file in my Ruby automation. Can anyone help me ? Note: I am using PDF-util jar file (To compare two pdf's, pixel to pixel)

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • Please provide some context as to what you want to do. i am unable to understand from the question alone. What is your use case in ruby, and how are you implementing it in selenium? – sakurashinken Nov 02 '17 at 23:54
  • i need to compare two pdf (pixel to pixel or including image) using ruby. i didn't found any proper gems for this case. But i found PDF-util.jar file and i was able to do the scenario in selenium. How can i implement the same in ruby – abin paulose Nov 03 '17 at 00:40

1 Answers1

0

If you really want to use that jar, then you probably can use %x() or backticks to use your jar from test by calling like java -jar /path/to/PDF-util.jar some args here.

Also you may want to have a look at ImageMagick gem, it might do what you need.

And if it's enough to compare binary files, the original and the one you can download in your test, you may compare their hash sums and it should be enough.

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • Thanks Alex for the response. After comparing the PDF i need to locate the places where mismatch happened. pdf-util will do everything. What about the imageMagick ? – abin paulose Nov 03 '17 at 02:25
  • Can you please explain more about how can i use use %x() or backticks to use "pdf-util" jar . I never tried. Please help me – abin paulose Nov 03 '17 at 02:30
  • if you use jar from here https://github.com/vinsguru/pdf-util. it's possible to use it like java -jar pdfutil.jar /path/to/file1.pdf /path/to/file2.pdf /path/to/diff/image. so you can call this command as a shell script from ruby script, as %x("java -jar /path/to/pdfutil.jar #{file1_path} #{file2_path} #{image_path}"). %x returns result from stdout, so in case images don't match it will contain "WARNING: Image compared - does not match". – Alex Tepliashin Nov 03 '17 at 03:04
  • here you can find the difference between %x() and back ticks and even more.. https://stackoverflow.com/questions/6338908/ruby-difference-between-exec-system-and-x-or-backticks – Alex Tepliashin Nov 03 '17 at 03:07
  • So i need to use like below ? java -jar pdfutil.jar C:\Users\file1.pdf C:\Users\file2.pdf C:\Users\image – abin paulose Nov 03 '17 at 03:14
  • Also where should i save the jar file ? How to link to project ? – abin paulose Nov 03 '17 at 03:17
  • you can put it to your project root and then I guess will'll be able to refer it simply as pdfutil.jar. of course you can put it to some dir, called lib, bin or something, or you can even put it somewhere else and use some env variable (https://en.wikipedia.org/wiki/Environment_variable, https://ruby-doc.org/core-2.1.4/ENV.html) to parameterize path to the jar file, it'll help to avoid storing it in your version control system. – Alex Tepliashin Nov 03 '17 at 03:24