Git Product home page Git Product logo

Comments (9)

andreiaionitoaiesv avatar andreiaionitoaiesv commented on July 17, 2024 3

Found the issue. For future google searches.
GOOD

Allure.add_attachment(
  name: filename,
  source: File.open("screenshots/#{filename}.png"),
  type: Allure::ContentType::PNG,
   test_case: true
)

BAD

Allure.add_attachment(
      name: filename,
      source: "/path/to/file",
      type: Allure::ContentType::PNG,
      test_case: true
)

Source must be a File object for the PNG, JPG case. I though that I needed to send the path for the source file.

from allure-ruby.

andrcuns avatar andrcuns commented on July 17, 2024

@andreiaionitoaiesv

Thanks for the issue. I will have to check out the order how rspec executes hooks. It's possible that allure test object is already finalised when this hook is executed.

from allure-ruby.

andrcuns avatar andrcuns commented on July 17, 2024

@andreiaionitoaiesv
I actually couldn't reproduce the issue. You can check the example here, attachments are added fine.

Also, just noticed that you state to be using different versions for commons and allure-rspec. You should be using same version and technically You do not need to require allure-ruby-commons, it is a dependency of allure-rspec.

from allure-ruby.

andrcuns avatar andrcuns commented on July 17, 2024

Closing, not reproducible with latest 2.13.3 version

from allure-ruby.

andreiaionitoaiesv avatar andreiaionitoaiesv commented on July 17, 2024

@andrcuns

I just cloned the repository from here

         ` undefined method `steps' for nil:NilClass`

So I've tried different stuff and I can't make this to work. Can you please provide a working example?

from allure-ruby.

andreiaionitoaiesv avatar andreiaionitoaiesv commented on July 17, 2024

Screenshot 2020-02-05 at 17 25 17

After a quick look I've noticed that the current_executable seems to be nil. I did not have the chance to dig deeper, but correct me if I'm wrong it seems as you said initially that It's possible that allure test object is already finalised when this hook is executed.

from allure-ruby.

andrcuns avatar andrcuns commented on July 17, 2024

@andreiaionitoaiesv

How exactly You rspec runner is configured?
Here is the output of test run if executed via rake task like it is mentioned in README:

❯ bundle exec rake test

test_feature
  test_case_1 (FAILED - 1)
  must be pending example (PENDING: Not yet implemented)
  must be pending example 2 (PENDING: Not yet implemented)

Some usecase 2
  10 cannot be greater than 19 (FAILED - 2)
  4 must not be equal to 5 (FAILED - 3)
  should pass

Some usecase 1
  should have some steps (FAILED - 4)
  string 'aaa' cannot be equal to string 'bbb' (FAILED - 5)
  must be broken test case (FAILED - 6)

Some usecase 4
  10 cannot be greater than 19 (FAILED - 7)
  4 must not be equal to 5 (FAILED - 8)

Some usecase 3
  10 cannot be greater than 19 (FAILED - 9)
  4 must not be equal to 5 (FAILED - 10)

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) test_feature must be pending example
     # Not yet implemented
     # ./spec/test_feature_0/test_case_1_spec.rb:16

  2) test_feature must be pending example 2
     # Not yet implemented
     # ./spec/test_feature_0/test_case_1_spec.rb:18


Failures:

  1) test_feature test_case_1
     Failure/Error: expect(10).to be > 19

       expected: > 19
            got:   10
     # ./spec/test_feature_0/test_case_1_spec.rb:12:in `block (3 levels) in <top (required)>'
     # ./spec/test_feature_0/test_case_1_spec.rb:11:in `block (2 levels) in <top (required)>'

  2) Some usecase 2 10 cannot be greater than 19
     Failure/Error: expect(10).to be > 19

       expected: > 19
            got:   10
     # ./spec/test_feature_1/some_other_spec.rb:7:in `block (2 levels) in <top (required)>'

  3) Some usecase 2 4 must not be equal to 5
     Failure/Error: expect(5).to eq(4)

       expected: 4
            got: 5

       (compared using ==)
     # ./spec/test_feature_1/some_other_spec.rb:11:in `block (2 levels) in <top (required)>'

  4) Some usecase 1 should have some steps
     Failure/Error: expect(0).to eq(1)

       expected: 1
            got: 0

       (compared using ==)
     # ./spec/test_feature_1/some_steps_spec.rb:18:in `block (3 levels) in <top (required)>'
     # ./spec/test_feature_1/some_steps_spec.rb:17:in `block (2 levels) in <top (required)>'

  5) Some usecase 1 string 'aaa' cannot be equal to string 'bbb'
     Failure/Error: expect('aaa').to eq('bbb')

       expected: "bbb"
            got: "aaa"

       (compared using ==)
     # ./spec/test_feature_1/some_steps_spec.rb:23:in `block (2 levels) in <top (required)>'

  6) Some usecase 1 must be broken test case
     Failure/Error: raise 'Unexpected exception'

     RuntimeError:
       Unexpected exception
     # ./spec/test_feature_1/some_steps_spec.rb:27:in `block (2 levels) in <top (required)>'

  7) Some usecase 4 10 cannot be greater than 19
     Failure/Error: expect(10).to be > 19

       expected: > 19
            got:   10
     # ./spec/test_feature_2/some_fourth_spec.rb:7:in `block (2 levels) in <top (required)>'

  8) Some usecase 4 4 must not be equal to 5
     Failure/Error: expect(5).to eq(4)

       expected: 4
            got: 5

       (compared using ==)
     # ./spec/test_feature_2/some_fourth_spec.rb:11:in `block (2 levels) in <top (required)>'

  9) Some usecase 3 10 cannot be greater than 19
     Failure/Error: expect(10).to be > 19

       expected: > 19
            got:   10
     # ./spec/test_feature_2/some_third_spec.rb:7:in `block (2 levels) in <top (required)>'

  10) Some usecase 3 4 must not be equal to 5
      Failure/Error: expect(5).to eq(4)

        expected: 4
             got: 5

        (compared using ==)
      # ./spec/test_feature_2/some_third_spec.rb:11:in `block (2 levels) in <top (required)>'

Finished in 0.05041 seconds (files took 0.26706 seconds to load)
13 examples, 10 failures, 2 pending

Failed examples:

rspec ./spec/test_feature_0/test_case_1_spec.rb:6 # test_feature test_case_1
rspec ./spec/test_feature_1/some_other_spec.rb:6 # Some usecase 2 10 cannot be greater than 19
rspec ./spec/test_feature_1/some_other_spec.rb:10 # Some usecase 2 4 must not be equal to 5
rspec ./spec/test_feature_1/some_steps_spec.rb:6 # Some usecase 1 should have some steps
rspec ./spec/test_feature_1/some_steps_spec.rb:22 # Some usecase 1 string 'aaa' cannot be equal to string 'bbb'
rspec ./spec/test_feature_1/some_steps_spec.rb:26 # Some usecase 1 must be broken test case
rspec ./spec/test_feature_2/some_fourth_spec.rb:6 # Some usecase 4 10 cannot be greater than 19
rspec ./spec/test_feature_2/some_fourth_spec.rb:10 # Some usecase 4 4 must not be equal to 5
rspec ./spec/test_feature_2/some_third_spec.rb:6 # Some usecase 3 10 cannot be greater than 19
rspec ./spec/test_feature_2/some_third_spec.rb:10 # Some usecase 3 4 must not be equal to 5

❯ allure serve report/allure-results
Generating report to temp directory...
Report successfully generated to /var/folders/hb/x8g3t9c93_v6_c_7lz02rl3m0000gn/T/1863617268208488389/allure-report
Starting web server...
2020-02-05 18:22:52.811:INFO::main: Logging initialized @2339ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://192.168.1.114:49681/>. Press <Ctrl+C> to exit

Make sure whatever executes rspecs is correctly configured, all the gems are up to date, and ruby version is > 2.5.

Current executable can be nil, if you try to add step before the test suite was even started. My original assumption was wrong, it checked it out and hooks are handled correctly.

from allure-ruby.

andreiaionitoaiesv avatar andreiaionitoaiesv commented on July 17, 2024

Thanks. I kinda got it to work. But the attachments are broken. For the PNG type:

Screenshot 2020-02-06 at 11 20 46

Any idea why this is happening? Here is the spec helper.

Allure.add_attachment( name: filename, source: "./screenshots/#{filename}.png", type: Allure::ContentType::PNG, test_case: true )

The path and filename are correct. I'm a little confused about the
def prepare_attachment(name, type) extension = ContentType.to_extension(type) || return file_name = "#{UUID.generate}-attachment.#{extension}" Attachment.new(name: name, source: file_name, type: type) end

I would expect that the add_attachment method just to copy and attach the specified files. But apparently in prepare_attachment you create a new file. Please correct if I'm wrong.

from allure-ruby.

andrcuns avatar andrcuns commented on July 17, 2024

It does copy a file, it happens here:

source.is_a?(File) ? copy(source.path, attachment.source) : write(attachment.source, source)

If you want to copy an existing file, it has to be an actual File object, not just a path as string.

# @param [File, String] source File or string to save as attachment

from allure-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.