Closed AndreiH closed 7 years ago
You should add code similar in README inside your tests. Main idea is that instead of using absolute paths for files generated within your tests (e.g. saving them to /tmp directory or whatever) you should use file_path
helper.
However, the error you are experiencing exists probably because you have not installed watir-rspec successfully. Did you run watir-rspec install
as specified in README?
Specifically you seem to have missing config.include Watir::RSpec::Helper
statement inside your spec helper.
You can also avoid that problem by specifying browser instance explicitly by using it's variable or whatever you have it set for:
@browser.file_field(...)
Thank you for the response @jarmo !
I installed the watir-rspec as specified in the README. All the required configuration is in the spec_helper.rb as required. Still "file_field(..)" method is not recognized. Even if I do something like this, after a test spec, it still does not work. The HTML report is generated, but there are no screenshots:
after do
screenshot_file_path = Watir::RSpec.file_path("custom_screenshot.jpg")
end
As it's also specified here: https://stackoverflow.com/questions/28985347/custom-screeshot-for-watir-rspec-reporter
I see you also commented on this issue, but I did not see a response how it got resolved. By the way, I only want screenshots whenever there is a fail. I self induce test fails, but still no screenshots.
Thanks !
Did you try calling file_field
method directly on your Watir::Browser
object instance?
It's hard to help without actually seeing your source code, but it seems that either spec_helper
is not loaded by your specs, Watir::RSpec::Helper
is not included into your specs or some other weird issue.
Can you provide me minimal set of code which I could run myself to reproduce this problem? Also, provide me with minimal Gemfile
(and Gemfile.lock
) and Ruby version too.
Closing this due to inactivity. Please reopen if issue still persists.
Hello,
I would like to setup the HTMLFormatter into my project, when I run the automated tests. After successfully installing watir-rspec into rspec_helper.rb, I also wanted to setup the screenshots to be attached to the html report. I was unsuccessful. The watir-rspec readme states:
You can use Watir::RSpec.file_path to have links automatically in the html report to the files created during tests. uploaded_file_path = Watir::RSpec.file_path("uploaded.txt") File.open(uploaded_file_path, "w") {|file| file.write "Generated File Input"} file_field(:name => "upload-file").set uploaded_file_path
Where do I put this code? When I put it in my spec_helper.rb, I get this error: undefined method 'file_field' for main:Object (NoMethodError)
Can anyone please help me and tell me what I'm doing wrong? I did not find any other documentation to help me resolve this. Maybe this will help a lot of beginners understand. Thanks in advance !