Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-141426

Add runtime warnings if TestCase.grabImage() is called on an invisible Item

XMLWordPrintable

      Code

      import QtQuick
      import QtTest
      
      TestCase {
          id: testCase
          //visible: true // <-- One possible solution
      
          Rectangle {
              id: redSquare
              color: "red"
              width: 100
              height: 100
          }
      
          function test_grabAndCheckColor() {
              const img = testCase.grabImage(redSquare)
              compare(img.pixel(0, 0), Qt.color("red"));
          }
      }
      

       

      Outcomes

      FAIL!  : example::test_grabAndCheckColor() Compared values are not the same
         Actual   (): #ffffff
         Expected (): #ff0000
      

      Here, grabImage() fails because redSquare is not visible (because testCase is not visible). This can be quite unintuitive.

       

      Suggestion
      We should produce a runtime warning if TestCase.grabImage() is called on an invisible Item.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes