Codeception: Attempt to close tab throws error: [ModuleException] WebDriver: Will not close the last open tab

37 views Asked by At

I use Codeception PHP Testing Framework v4.2.2 for test automation.

This is the scenario, I am trying to automate:

  1. Login to outlook with one email id

  2. Send mail

3.Log out

4.Close the tab

5.Login again with another email id

For step #4, to close the browser tab I used code: $I->closeTab();

However the code is failing at this step & giving the below error:

[ModuleException] WebDriver: Will not close the last open tab

codeception error

Not sure, where it is going wrong? How to close the tab (one & only tab in the window) without any error?

Snippet of my code below:

public function closeBrowserTab(RestAPIAdminUserTester $I) {
//outlook url
$I->amOnUrl($this->outlookURL);
$I->waitForElement($this->webElementforLogIn, 10);
//wait for mailbox to load
$I->wait(5);
//Click on logout
$I->waitForElementAndClick($this->webElementForLogOut, 10);
//Close the tab
$I->closeTab();
//Log in to outlook using another email
$I->amOnUrl($this->outlookURL);
$I->waitForElement($this->webElementforLogIn, 10);
}

Please note:

If I open a new tab & try to close the new tab like below, I dont get any error:

$I->openNewTab();
$I->amOnUrl('https://outlook.office.com/mail');
$I->wait(5);
$I->closeTab();

Wondering, how to close the tab successfully when the browser window has only 1 tab?

0

There are 0 answers