Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take screenshots during system tests, upload to Google Cloud storage, and append to Dangerbot output #5320

Closed
wants to merge 57 commits into from

Conversation

jywarren
Copy link
Member

@jywarren jywarren commented Mar 31, 2019

Re #5316 screenshots of tests

Also we might try: bin/rails test:system test to get the coverage to not run twice (we went down from 91-44% but that's because we're running tests twice and 44 is just for system tests i guess?)

https://api.rubyonrails.org/classes/ActionDispatch/SystemTestCase.html

Attempting to generate inline screenshots with https://iterm2.com/documentation-images.html

But fallback could be to generate them as files, then use Dangerfile to leave them as comments, but collasped in a <details> el:

<details>
    <summary>Screenshots 📸 (click to expand)</summary>
    <h3>Front page:</h3>
    <p><img src="dataurl" /></p>
</details>

@plotsbot
Copy link
Collaborator

plotsbot commented Mar 31, 2019

1 Error
🚫 There was an error with Danger bot’s Junit parsing: No JUnit file was found at output.xml
1 Warning
⚠️ It looks like you merged from master in this pull request. Please rebase to get rid of the merge commits – you may want to rewind the master branch and rebase instead of merging in from master, which can cause problems when accepting new code!
2 Messages
📖 @jywarren Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.
📖 #
Screenshots 📸 (click to expand)

5320-test_front_page_with_navbar_search_autocomplete.png

5320-test_viewing_the_dashboard.png

Generated by 🚫 Danger

@jywarren
Copy link
Member Author

Great -- [Screenshot]: tmp/screenshots/test_front_page_with_navbar_search_autocomplete.png

Now we just have to figure out how to use Danger to paste it into a comment, or display it inline.

@jywarren
Copy link
Member Author

plots2/Dangerfile

Lines 60 to 68 in 3d2b068

images = []
Dir.foreach('/tmp/screenshots') do |item|
next if item == '.' or item == '..'
dataurl = "data:image/png;base64," + Base64.strict_encode64(File.read(item))
images << "<h3>#{item}</h3><p><img src='#{dataurl}' /></p>"
end
screenshots = "<details><summary>Screenshots 📸 (click to expand)</summary>" + images.join + "</details>"
markdown(screenshots)

@jywarren jywarren changed the title Create screenshots_test Take screenshots during system tests, convert to data-urls, and append to Dangerbot output Mar 31, 2019
@jywarren
Copy link
Member Author

jywarren commented Mar 31, 2019

Huh, so i see:

<details><summary>Screenshots <g-emoji class="g-emoji" alias="camera_flash" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4f8.png">📸</g-emoji> (click to expand)</summary><h3>test_front_page_with_navbar_search_autocomplete.png</h3><p><a target="_blank" rel="noopener noreferrer" href=""><img style="max-width:100%;"></a></p></details>

However, later in the source code of this page, I see this dataurl which is correct!

@jywarren
Copy link
Member Author

Aha -- ok, so the dataurl gets stripped out of comments. Makes sense i guess. The image is:

image

And by editing the Dangerbot comment you can see it in there -- it's just sanitized out!

@jywarren
Copy link
Member Author

I messaged GitHub help desk to ask about limitations of dataurls. Unfortunately I can't think of another way around this except to abandon dataurls and store in Google cloud maybe.

@jywarren
Copy link
Member Author

@jywarren
Copy link
Member Author

# project_id        = "Your Google Cloud project ID"
# bucket_name       = "Your Google Cloud Storage bucket name"
# local_file_path   = "Path to local file to upload"
# storage_file_path = "Path to store the file in Google Cloud Storage"

require "google/cloud/storage"

storage = Google::Cloud::Storage.new project_id: project_id
bucket  = storage.bucket bucket_name

file = bucket.create_file local_file_path, storage_file_path

puts "Uploaded #{file.name}"

@jywarren
Copy link
Member Author

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX+AAD///+KQee0AAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EGHRIVAvrm6EMAAAAMSURBVAjXY2AgDQAAADAAAceqhY4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDYtMjlUMTg6MjE6MDIrMDI6MDDGD83DAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTA2LTI5VDE4OjIxOjAyKzAyOjAwt1J1fwAAAABJRU5ErkJggg==

dataurl


# apparently this will wait for ajax to complete?
# also, not sure we can nest css like this:
assert_select "ul.dropdown-menu li", count: 2 #, wait: 5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use:
page.assert_selector('li', text: 'Horse', visible: true)
too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren
Copy link
Member Author

jywarren commented Apr 1, 2019

Hmm, seeing:

The previous command failed, possibly due to a malformed secure environment variable.
Please be sure to escape special characters such as ' ' and '$'.
For more information, see https://docs.travis-ci.com/user/encryption-keys.

Probably need to escape keys

@jywarren
Copy link
Member Author

jywarren commented Apr 1, 2019

Hmm, two issues -- how do we require from Dangerfile?

[!] Invalid Dangerfile file: cannot load such file -- google/cloud/storage

And, we seem to be getting:

$ export RAILS_SYSTEM_TESTING_SCREENSHOT=inline
$ export GOOGLE_CLOUD_KEYFILE_JSON=[secure]
The previous command failed, possibly due to a malformed secure environment variable.
Please be sure to escape special characters such as ' ' and '$'.
For more information, see https://docs.travis-ci.com/user/encryption-keys.

@jywarren
Copy link
Member Author

jywarren commented Apr 1, 2019

Although i tested these Google Cloud upload functions locally so I know they work! https://storage.googleapis.com/plots2-screenshots/test.png for example was uploaded from Ruby using the same GOOGLE_CLOUD_KEYFILE_JSON env variable...

@jywarren
Copy link
Member Author

jywarren commented Apr 1, 2019

I'm going to put an encoded JSON value into a dummy JSON_TEST env variable in Travis to see how that appears and if it errors too.

@jywarren jywarren changed the title Take screenshots during system tests, convert to data-urls, and append to Dangerbot output Take screenshots during system tests, upload to Google Cloud storage, and append to Dangerbot output Apr 1, 2019
@jywarren
Copy link
Member Author

jywarren commented Apr 1, 2019

@icarito any idea how to properly require the Google cloud gem in Dangerfile?

@jywarren
Copy link
Member Author

Tried a couple things!

@jywarren
Copy link
Member Author

Hmm, still /usr/local/bundle/gems/multi_json-1.13.1/lib/multi_json/adapters/json_common.rb:19:in encode': "\xE2" on US-ASCII (Encoding::InvalidByteSequenceError)`

@jywarren
Copy link
Member Author

Aha, it's in: from /usr/local/bundle/gems/octokit-4.14.0/lib/octokit/client/issues.rb:292:in update_comment'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/request_sources/github/github.rb:198:in update_pull_request!'

@jywarren
Copy link
Member Author

Ahhhh! I bet it's the emoji camera! !!!!! 📸

Too bad camera... not this time!

@jywarren
Copy link
Member Author

Hmm. Well that's odd. It wasn't the emoji, i guess? /usr/local/bundle/gems/multi_json-1.13.1/lib/multi_json/adapters/json_common.rb:19:in encode': "\xE2" on US-ASCII (Encoding::InvalidByteSequenceError)`

@jywarren
Copy link
Member Author

They had the same issue here! stevekinney/pizza#103

require "google/cloud/storage"
storage = Google::Cloud::Storage.new project_id: "public-lab"
bucket = storage.bucket "plots2-screenshots"
Encoding.default_external = 'UTF-8'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encoding.default_internal = Encoding::UTF_8

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby 2.0 and above: default string encoding is UTF-8.

Thus, if you use Ruby 2.0, you could skip the encoding comment and correctly assume UTF-8 encoding everywhere by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes maybe as a follow-up?

@jywarren
Copy link
Member Author

THIS WORKED!!!!!! I'm changing the filenames, but this should be good to merge!!!!!!

@jywarren
Copy link
Member Author

Hmm, why isn't it finding output.xml... @alaxalves was this somehow related to the splitting of the system tests into a parallel process? Junit should generate in both, I'd think though...

@jywarren
Copy link
Member Author

Maybe this needs a rebase?

@jywarren
Copy link
Member Author

Made a clean squashed version of this at #5868 that is also rebased... let's see!

@jywarren
Copy link
Member Author

This is complete!!!!! #5868 worked perfectly after some tweaks!!!! Check it out 📸

@jywarren jywarren closed this Jun 12, 2019
jywarren added a commit that referenced this pull request Jun 12, 2019
jywarren added a commit that referenced this pull request Jun 12, 2019
* add screenshots for grids

Re #5320 #5868 #5316

* adjust screenshot path
rarrunategu1 pushed a commit to rarrunategu1/plots2 that referenced this pull request Jun 14, 2019
* add screenshots for grids

Re publiclab#5320 publiclab#5868 publiclab#5316

* adjust screenshot path
sagarpreet-chadha pushed a commit that referenced this pull request Jun 29, 2019
* add screenshots for grids

Re #5320 #5868 #5316

* adjust screenshot path
enviro3 pushed a commit to enviro3/plots2 that referenced this pull request Aug 15, 2019
* add screenshots for grids

Re publiclab#5320 publiclab#5868 publiclab#5316

* adjust screenshot path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants