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

Create post_test.rb to test posting at /post #5605

Merged
merged 22 commits into from May 2, 2019
Merged

Conversation

jywarren
Copy link
Member

For #5316

@plotsbot
Copy link
Collaborator

plotsbot commented Apr 24, 2019

1 Message
📖 @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.

Generated by 🚫 Danger

@jywarren
Copy link
Member Author

OK, seeing this in #5525 and #5526:


ERROR["test_posting_from_the_editor", #<Minitest::Reporters::Suite:0x000055b7f104ec38 @name="PostTest">, 154.474844297]
 test_posting_from_the_editor#PostTest (154.47s)
Selenium::WebDriver::Error::SessionNotCreatedError:         Selenium::WebDriver::Error::SessionNotCreatedError: session not created: Chrome version must be between 70 and 73
          (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Linux 4.4.0-101-generic x86_64)
            test/system/post_test.rb:9:in `block in <class:PostTest>'

@jywarren
Copy link
Member Author

OK back in business:


[Screenshot]: tmp/screenshots/failures_test_posting_from_the_editor.png
ERROR["test_posting_from_the_editor", #<Minitest::Reporters::Suite:0x000056161ce0cd00 @name="PostTest">, 142.33899468700008]
 test_posting_from_the_editor#PostTest (142.34s)
Capybara::ElementNotFound:         Capybara::ElementNotFound: Unable to find field ".ple-module-title input" that is not disabled
            test/system/post_test.rb:11:in `block in <class:PostTest>'

@jywarren
Copy link
Member Author

Hmm.

ERROR["test_posting_from_the_editor", #<Minitest::Reporters::Suite:0x0000563b3b460e70 @name="PostTest">, 36.109343785999954]
 test_posting_from_the_editor#PostTest (36.11s)
Capybara::ElementNotFound:         Capybara::ElementNotFound: Unable to find field "input#title-input" that is not disabled
            test/system/post_test.rb:15:in `block in <class:PostTest>'


visit '/post'

fill_in("input#title-input", with: "My new post")
Copy link
Member Author

Choose a reason for hiding this comment

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

You'd think this would work, but it doesn't seem to!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @jywarren , the syntax is correct . I think we are not logged-in and hence this text field is not visible .

@sagarpreet-chadha
Copy link
Contributor

I think we should sign-in like this :

Screenshot 2019-04-26 at 11 38 17 AM

Screenshot 2019-04-26 at 11 38 36 AM

Source : http://blog.mechanicles.com/2018/03/04/gotchas-rails-system-testing.html
https://thoughtbot.com/blog/automatically-wait-for-ajax-with-capybara

end

test 'posting from the editor' do
UserSession.create(users(:bob)) # log in
Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, perhaps because this doesn't create a session in the headless browser?

@jywarren
Copy link
Member Author

OK, trying to log in via Capybara commands! Hope i got it right!

@jywarren
Copy link
Member Author


[Screenshot]: tmp/screenshots/failures_test_posting_from_the_editor.png
ERROR["test_posting_from_the_editor", #<Minitest::Reporters::Suite:0x000055d637834560 @name="PostTest">, 232.907265617]
 test_posting_from_the_editor#PostTest (232.91s)
Capybara::ElementNotFound:         Capybara::ElementNotFound: Unable to find link or button "Log in"
            test/system/post_test.rb:11:in `block in <class:PostTest>'

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."
"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."
@jywarren
Copy link
Member Author


ERROR["test_posting_from_the_editor", #<Minitest::Reporters::Suite:0x00007fa76da09e90 @name="PostTest">, 290.7586481359999]
 test_posting_from_the_editor#PostTest (290.76s)
RuntimeError:         RuntimeError: not a redirect!  
            test/system/post_test.rb:18:in `block in <class:PostTest>'
  911/911: [===============================] 100% Time: 00:05:08, Time: 00:05:08

test 'posting from the editor' do
visit '/'

click_on 'Login'
Copy link
Member

Choose a reason for hiding this comment

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

  1. Here we are visiting login but on line 29 we get the message
    User was successfully created. Can you please explain this code snippet?
  2. We have same integration test here
    test 'redirect to login page if user is not logged in and then redirect back to desired page after login' do
    get '/post?tags=question:question&template=question'
    follow_redirect!
    assert_equal '/login', path
    post '/user_sessions', params: { user_session: { username: users(:jeff).username, password: 'secretive' } }
    follow_redirect!
    assert_equal '/post?tags=question:question&template=question', request.fullpath
    end
    so one of these will become redundant.
  3. In theory of Software Testing at my university, we are taught that System tests are written to validate the non-functional parameters like server load time, access time between end nodes etc. Are we also going to do those amazing stuff later on?
  4. I am having difficulty in installing the prerequisites for System tests. Can you please tell a good reference? I searched a lot but none worked during past one week.
  5. How can we use Recaptcha or Spamaway in system test? Any idea. You may require them in this pr too in case we want assert_selector('#notice', 'User was successfully created.').

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree on redundant, but I'm not sure how to create a session we can use to test logged-in stuff. I tried doing as we do in other tests, with UserSession.new() or whatever, but I think it literally isn't connecting that session we make in the back-end to an actual logged in session that Capybara can interact with on headless chrome! So, i'm trying to log in manually here... how else ought we to log in? Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Are we also going to do those amazing stuff later on?

My biggest interests in system tests are:

  1. testing the interaction of our complex JS with the Rails app, end-to-end, because things keep breaking here
  2. seeing screenshots!

But yeah... lots of other possibilities.

@jywarren
Copy link
Member Author

OK! Added a real image URL to scraped_image -- wow, system tests are powerfully interconnected!

@jywarren
Copy link
Member Author

Great,


ERROR["test_posting_from_the_editor", #<Minitest::Reporters::Suite:0x00007f9c32e19bc0 @name="PostTest">, 26.728502618999983]
 test_posting_from_the_editor#PostTest (26.73s)
Capybara::ElementNotFound:         Capybara::ElementNotFound: Unable to find visible field "text-input" that is not disabled
            test/system/post_test.rb:21:in `block in <class:PostTest>'

visit '/post'

fill_in("Title", with: "My new post")
fill_in("text-input", with: "All about this interesting stuff")
Copy link
Member Author

Choose a reason for hiding this comment

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

Here, we need a better way to select the right field. Maybe this is because we're in wysiwyg and not markdown mode?

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 May 1, 2019


ERROR["test_posting_from_the_editor", #<Minitest::Reporters::Suite:0x0000563003891078 @name="PostTest">, 164.87261782500002]
 test_posting_from_the_editor#PostTest (164.87s)
NoMethodError:         NoMethodError: undefined method `response_code' for nil:NilClass
            test/system/post_test.rb:28:in `block in <class:PostTest>'

find('.ple-publish').click
# find('.ple-publish').click # may have to do it twice if it prompts for an image

assert_response :redirect
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, here... NoMethodError: NoMethodError: undefined method response_code' for nil:NilClass`

Copy link
Member Author

Choose a reason for hiding this comment

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

line 26 is not right, we shouldn't have to click twice. Not sure why this isn't working...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. i used Capycorder to try this but it didn't get everything:

it 'SHOULDDOSOMETHING' do
  visit('/post')
  page.should have_selector('.wk-wysiwyg')
  page.should have_selector('html  > body > .container > .row > .pl-editor > .ple-content > .ple-module-title.ple-module.row > .ple-module-content.col-lg-9:nth-child(1) > .form-control.input-lg')
  fill_in('undefined', :with => 'title title')
  page.should have_selector('.ple-publish.btn.btn-lg.btn-primary.float-right')
end

Copy link
Member Author

Choose a reason for hiding this comment

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

But in fact on stable, posting is not working, so maybe this is just because the functionality is broken?

Copy link
Member Author

@jywarren jywarren May 1, 2019

Choose a reason for hiding this comment

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

i see a 500 on https://stable.publiclab.org/post,

title: testing
body: testing
authenticity_token: yYh7o/22lYcj6XJ0dJViugBbFW72WK790hzjEJAFI52tUAZEijrbnzc3+d1ZZaj+LgBwIoz2PK6pwJslzEWgRw==
draft: false
tags: 
has_main_image: 
main_image: 
node_images: 
image[photo]: 

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this 500 possibly due to email not sending? I thought we'd resolved this but who knows... hmm. We may need to try to pull the logs here since this is not failing in tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, think I resolved the 500 on stable... testing....

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, it's resolved on stable. Still not here, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I realized that it's not doing a real redirect... it's JS sending us to a new page. So, I'm using a snippet from https://stackoverflow.com/questions/20243208/how-can-i-test-in-capybara-that-a-page-has-not-reloaded-javascript-onclick-in to show that assert_page_reloads and then just going forward with the next steps!

@jywarren
Copy link
Member Author

jywarren commented May 2, 2019

Hmm!

ERROR["test_posting_from_the_editor", #<Minitest::Reporters::Suite:0x0000562bd33af458 @name="PostTest">, 330.5202703770001]
 test_posting_from_the_editor#PostTest (330.52s)
ArgumentError:         ArgumentError: Unused parameters passed to Capybara::Queries::SelectorQuery : ["Research note published. Get the word out on the discussion lists!"]
            test/system/post_test.rb:31:in `block (2 levels) in <class:PostTest>'
            test/system/post_test.rb:41:in `assert_page_reloads'
            test/system/post_test.rb:27:in `block in <class:PostTest>'

@jywarren
Copy link
Member Author

jywarren commented May 2, 2019

Closer...

 FAIL["test_posting_from_the_editor", #<Minitest::Reporters::Suite:0x000055ef3c2ed728 @name="PostTest">, 109.48764913100001]
 test_posting_from_the_editor#PostTest (109.49s)
        expected to find visible css "h1" with text "My new post" but there were no matches. Also found "<<ERROR>>", which matched the selector but not all filters. 
        test/system/post_test.rb:29:in `block (2 levels) in <class:PostTest>'

@jywarren
Copy link
Member Author

jywarren commented May 2, 2019

Maybe we need to tell it to load the page JavaScript sends it to?

follow_redirect!? or something?

@jywarren
Copy link
Member Author

jywarren commented May 2, 2019

🤞

@jywarren jywarren merged commit e190eae into master May 2, 2019
@jywarren
Copy link
Member Author

jywarren commented May 2, 2019

Hooray!!!! System test running!!!

@sagarpreet-chadha
Copy link
Contributor

Wow amazing !!! 🙌

@SidharthBansal
Copy link
Member

SidharthBansal commented May 3, 2019 via email

SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
* Create post_test.rb

*     UserSession.create(users(:bob)) # log in

* Update post_test.rb

* Update rich.html.erb

* Update post_test.rb

* Update post_test.rb

* Trying login via modal

* add login-button id

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* Update post_test.rb

* /images/pl.png in scraped image

* /images/pl.png in scraped image

* Update post_test.rb

* add assert_page_reloads

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb
jywarren pushed a commit that referenced this pull request May 10, 2019
* OAuth route creation for MK and SWB

* OAuth routes created

* Github working properly

* Modified the route to accept the provider

* OAuth completed

* removed codeclimate issues

* Documentation added

* test modified

* tests modified

* modified test to have roles

* Travis is passing

* Added OAuth tests

* made travis pass

* username removed from CDSM

* Removed redundant test

* Fixing date issue in subscription mailer (#5638)

* add nid to rss titles (#5644)

* Fix scraped image system test bug (#5646)

* Fix scraped image system test bug

* Update node_test.rb

* Create post_test.rb to test posting at /post (#5605)

* Create post_test.rb

*     UserSession.create(users(:bob)) # log in

* Update post_test.rb

* Update rich.html.erb

* Update post_test.rb

* Update post_test.rb

* Trying login via modal

* add login-button id

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* Update post_test.rb

* /images/pl.png in scraped image

* /images/pl.png in scraped image

* Update post_test.rb

* add assert_page_reloads

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* fixed image drag and drop bug (#5657)

* Database tweaks for performance (#5575)

* Database tweaks for performance

* Reduce innodb buffer pool size because of low memory

* Reduce RAM burden

* Reduce memory consumption following mysqltuner advice.

* Even more conservative limits for RAM

* Update home.html.erb

* Corrected the number of notes appearing on one line (#5661)

* Some mistakes corrected in notes.html.erb

* Wait 4

* Issue 5259: Used logged_in_as method to replace current_user.role condition (#5660)

* Update subscriptions.html.erb

* fix logged_in_as in controllers (#5677)

* fix logged_in_as in controllers

* add wait 4 to system test... odd

* Update subscriptions.html.erb

* Update subscriptions.html.erb

* Bump cytoscape from 3.5.4 to 3.6.0 (#5662)

Bumps [cytoscape](https://github.com/cytoscape/cytoscape.js) from 3.5.4 to 3.6.0.
- [Release notes](https://github.com/cytoscape/cytoscape.js/releases)
- [Commits](cytoscape/cytoscape.js@v3.5.4...v3.6.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Dashboard system test (#5682)

* Dashboard system test

* Update dashboard_test.rb

*   Capybara.default_max_wait_time = 5

* fix
digitaldina pushed a commit to digitaldina/plots2 that referenced this pull request May 12, 2019
* Create post_test.rb

*     UserSession.create(users(:bob)) # log in

* Update post_test.rb

* Update rich.html.erb

* Update post_test.rb

* Update post_test.rb

* Trying login via modal

* add login-button id

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* Update post_test.rb

* /images/pl.png in scraped image

* /images/pl.png in scraped image

* Update post_test.rb

* add assert_page_reloads

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb
digitaldina pushed a commit to digitaldina/plots2 that referenced this pull request May 12, 2019
…clab#5640)

* OAuth route creation for MK and SWB

* OAuth routes created

* Github working properly

* Modified the route to accept the provider

* OAuth completed

* removed codeclimate issues

* Documentation added

* test modified

* tests modified

* modified test to have roles

* Travis is passing

* Added OAuth tests

* made travis pass

* username removed from CDSM

* Removed redundant test

* Fixing date issue in subscription mailer (publiclab#5638)

* add nid to rss titles (publiclab#5644)

* Fix scraped image system test bug (publiclab#5646)

* Fix scraped image system test bug

* Update node_test.rb

* Create post_test.rb to test posting at /post (publiclab#5605)

* Create post_test.rb

*     UserSession.create(users(:bob)) # log in

* Update post_test.rb

* Update rich.html.erb

* Update post_test.rb

* Update post_test.rb

* Trying login via modal

* add login-button id

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* locators instead of css

"It appears you may be passing a CSS selector or XPath expression rather than a locator. Please see the documentation for acceptable locator values."

* Update post_test.rb

* /images/pl.png in scraped image

* /images/pl.png in scraped image

* Update post_test.rb

* add assert_page_reloads

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* Update post_test.rb

* fixed image drag and drop bug (publiclab#5657)

* Database tweaks for performance (publiclab#5575)

* Database tweaks for performance

* Reduce innodb buffer pool size because of low memory

* Reduce RAM burden

* Reduce memory consumption following mysqltuner advice.

* Even more conservative limits for RAM

* Update home.html.erb

* Corrected the number of notes appearing on one line (publiclab#5661)

* Some mistakes corrected in notes.html.erb

* Wait 4

* Issue 5259: Used logged_in_as method to replace current_user.role condition (publiclab#5660)

* Update subscriptions.html.erb

* fix logged_in_as in controllers (publiclab#5677)

* fix logged_in_as in controllers

* add wait 4 to system test... odd

* Update subscriptions.html.erb

* Update subscriptions.html.erb

* Bump cytoscape from 3.5.4 to 3.6.0 (publiclab#5662)

Bumps [cytoscape](https://github.com/cytoscape/cytoscape.js) from 3.5.4 to 3.6.0.
- [Release notes](https://github.com/cytoscape/cytoscape.js/releases)
- [Commits](cytoscape/cytoscape.js@v3.5.4...v3.6.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Dashboard system test (publiclab#5682)

* Dashboard system test

* Update dashboard_test.rb

*   Capybara.default_max_wait_time = 5

* fix
@cesswairimu cesswairimu deleted the post-system-test branch May 4, 2021 14:06
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

4 participants