Mahesh Jagtap
Mahesh Jagtap

Reputation: 128

Unit testing QWizard with QtTest

I am writing unit test cases for my QT application which contains a QWizard. I am using QtTest framework. But I am not able to get the Next button clicked on my wizard page.

welcomePage->m_installedVersion->lineEdit()->setText("1102");
welcomePage->m_upgradeVersion->lineEdit()->setText("12");
welcomePage->completeChanged(); //Only the above two text fields are mandatory so Next button should be enabled here, but it is not. So I have manually enabled it below.

myWizard.getNextButton()->setEnabled(true);
while( !myWizard.getNextButton()->isEnabled())
{

}

//Trying different ways to click on Next    
QTest::mouseClick(myWizard.getNextButton(), Qt::RightButton, Qt::NoModifier, QPoint(), 5000);
QSignalSpy(myWizard.getNextButton(), &QPushButton::clicked);
myWizard.getNextButton()->click();

The initializePage for the second page does not get called, so I don't think Next button has been clicked. How can I go to the Next page while unit testing?

Upvotes: -1

Views: 185

Answers (1)

Taron
Taron

Reputation: 1235

I would try clicking it with left mouse button.

QTest::mouseClick(myWizard.getNextButton(), Qt::LeftButton, Qt::NoModifier, QPoint(), 5000);

and also make sure in your test that the button is visible and enabled, like:

QCOMPARE( myWizard.getNextButton().isEnabled(), true);
QCOMPARE( myWizard.getNextButton().isVisible(), true);

Invisible and disabled buttons do nothing when clicked. And Next-Buttons in wizards are often disabled until the required fields in the wizard page are filled.

Upvotes: 1

Related Questions