Home > other >  grabToImage not working when using qmltestrunner.exe
grabToImage not working when using qmltestrunner.exe

Time:10-01

newbee here on QML. Apologies if the question is too basic but I am stuck.

I am trying something very simple, running a simple QML unit test, but it needs to grab the image of the window and saved to the file system.

So I was looking at this tutorial and the following docs:

enter image description here

CodePudding user response:

In case you don't insist on using your call-method - the given method in docs works just fine for me:

var image = grabImage(rect);
try {
    compare(image.width, 100);
} catch (ex) {
    image.save("debug.png");
    throw ex;
}

Which would result in this for you:

Item {
    width: 800
    height: 600

    MyWindow
    {
        id: myWindowTest
    }

    TestCase{
        name: "TestButtonClick"
        when: windowShown

        function test_ClickButton()
        {
            var notSavedText = "Not saved"
            var savedText = "Saved!"

            var image = grabImage(myWindowTest);
            image.save("something.png");
                
            console.log("step 1")
            verify(myWindowTest.saveStatus === notSavedText, "Save status failed!")

            console.log("sending click")
            mouseClick(myWindowTest.saveButton)

            console.log("step 2")
            verify(myWindowTest.saveStatus === savedText, "Save status failed!")
        }

    }

}

CodePudding user response:

thank you all for the leads, indeed the "waitForRendering" resolved the issue

    function test_ClickButton()
    {
        var notSavedText = "Not saved"
        var savedText = "Saved!"


        console.log("step 1")
        verify(myWindowTest.saveStatus === notSavedText, "Save status failed!")

        console.log("sending click")
        mouseClick(myWindowTest.saveButton)

        console.log("step 2")
        verify(myWindowTest.saveStatus === savedText, "Save status failed!")

        myWindowTest.grabToImage(function(result) {
                            console.log(result)
                                result.saveToFile("scrshot.png");
                            });

        **waitForRendering(myWindowTest, 100)**

    }
  • Related