magic_test icon indicating copy to clipboard operation
magic_test copied to clipboard

Remind users to assert for unique content on each new page

Open coolprobn opened this issue 3 years ago • 4 comments

Closes https://github.com/bullet-train-co/magic_test/issues/44

Tasks

  • Modal to show reminder to assert for unique content on each new page

Issue with default alert

When subscribing to on page load event and trying to show normal alert box from the browser it throws the error:

Error:
BasicsTest#test_getting_started:
Selenium::WebDriver::Error::UnexpectedAlertOpenError: unexpected alert open: {Alert text : this breaks the page}
  (Session info: chrome=98.0.4758.109)
    test/application_system_test_case.rb:243:in `execute'
    test/system/basics_test.rb:7:in `block in <class:BasicsTest>'

Due to this, I have implemented a simple JS and CSS modal for this feature instead of using alert.

UI Screenshot

Assertion Modal

coolprobn avatar Mar 03 '22 19:03 coolprobn

@coolprobn This is close, but there's a big issue: The JS fires the reminder even during normal running of system tests, which breaks the entire Bullet Train test suite. Instead, we need to make it so that this new reminder feature is only activated after the test encounters the magic_test command, and it is deactivated right after the user concludes their magic_test session, e.g. in lib/magic_test/support.rb:

    def magic_test
      empty_cache
      @test_lines_written = 0
      begin
        # 👋 Do something here to activate the notification JS.
        magic_test_pry_hook
        binding.pry
        # 👋 Do something here to disable the notification JS.
      rescue
        retry
      end
    end

You might be able to take advantage of page.evaluate_script in this context to set some variable on window (e.g. window.active_magic_test_session = true) and then check for that before triggering the alert... and then do the same, but = false to disable it. (You can see other examples of page.evaluate_script in the same file.)

andrewculver avatar Mar 04 '22 05:03 andrewculver

@coolprobn Also, please make sure the Bullet Train test suite is passing when linked to this branch for it's magic_test dependency in the Gemfile.

andrewculver avatar Mar 04 '22 05:03 andrewculver

@andrewculver I should have checked and tested properly, sorry.

I will fix as required and push new changes soon. Thanks.

coolprobn avatar Mar 04 '22 05:03 coolprobn

@andrewculver I have added the following code to reload the page before we stop the system test with magic test:

# reloading the page so that activeMagicTestSession variable is set and recognized by the JS
      # activeMagicTestSession is not set in the beginning because HTML file would have already been rendered before this method is invoked
      page.evaluate_script("window.location.reload()")

This was added because new variable that we are using to know if we are currently in magic test session was not being picked up. It is not recognized without page reload because all HTML and JS Scripts are rendered before this new variable is set inside support.rb

UX hasn't changed and there is a very minimum chance that user know what happened. I would love to hear your thoughts if there are any other solutions on your mind to resolve this issue.

coolprobn avatar Mar 09 '22 17:03 coolprobn