Skip to content

Commit cf74336

Browse files
authored
Console (#5450)
* Setting up interactive shell * Updated docs for interactive shell, minor improvements * added HTML snapshot some tests * Removed pause execution test * renamed Shell trait to pause, updated documentation
1 parent 4ae8025 commit cf74336

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

src/Codeception/Module/WebDriver.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ public function _saveScreenshot($filename)
707707
$this->webDriver->takeScreenshot($filename);
708708
} catch (\Exception $e) {
709709
$this->debug('Unable to retrieve screenshot from Selenium : ' . $e->getMessage());
710+
return;
710711
}
711712
}
712713

@@ -757,9 +758,26 @@ public function makeScreenshot($name = null)
757758
}
758759
$screenName = $debugDir . DIRECTORY_SEPARATOR . $name . '.png';
759760
$this->_saveScreenshot($screenName);
760-
$this->debug("Screenshot saved to $screenName");
761+
$this->debugSection('Screenshot Saved', "file://$screenName");
762+
}
763+
764+
public function makeHtmlSnapshot($name = null)
765+
{
766+
if (empty($name)) {
767+
$name = uniqid(date("Y-m-d_H-i-s_"));
768+
}
769+
$debugDir = codecept_output_dir() . 'debug';
770+
if (!is_dir($debugDir)) {
771+
mkdir($debugDir, 0777);
772+
}
773+
$fileName = $debugDir . DIRECTORY_SEPARATOR . $name . '.html';
774+
775+
$this->_savePageSource($fileName);
776+
$this->debugSection('Snapshot Saved', "file://$fileName");
761777
}
762778

779+
780+
763781
/**
764782
* Resize the current window.
765783
*
@@ -2697,17 +2715,6 @@ public function clickWithRightButton($cssOrXPath = null, $offsetX = null, $offse
26972715
$this->webDriver->getMouse()->contextClick();
26982716
}
26992717

2700-
/**
2701-
* Pauses test execution in debug mode.
2702-
* To proceed test press "ENTER" in console.
2703-
*
2704-
* This method is useful while writing tests,
2705-
* since it allows you to inspect the current page in the middle of a test case.
2706-
*/
2707-
public function pauseExecution()
2708-
{
2709-
Debug::pause();
2710-
}
27112718

27122719
/**
27132720
* Performs a double-click on an element matched by CSS or XPath.

tests/web/WebDriverTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ public function testScreenshot()
135135
@unlink(\Codeception\Configuration::outputDir().'testshot.png');
136136
}
137137

138+
public function testSnapshot()
139+
{
140+
$this->module->amOnPage('/');
141+
@unlink(\Codeception\Configuration::outputDir().'testshot.png');
142+
$testName="debugTest";
143+
144+
$this->module->makeHtmlSnapshot($testName);
145+
$this->assertFileExists(\Codeception\Configuration::outputDir().'debug/'.$testName.'.html');
146+
@unlink(\Codeception\Configuration::outputDir().'debug/'.$testName.'.html');
147+
}
148+
138149
public function testSubmitForm()
139150
{
140151
$this->module->amOnPage('/form/complex');
@@ -414,12 +425,6 @@ public function testAppendFieldRadioButtonByLabelFails()
414425
$this->module->appendField('form input[name=terms]', 'Get Off123');
415426
}
416427

417-
public function testPauseExecution()
418-
{
419-
$this->module->amOnPage('/');
420-
$this->module->pauseExecution();
421-
}
422-
423428
// Issue https://github.com/Codeception/Codeception/pull/875
424429
public function testFillPasswordOnFormSubmit()
425430
{

0 commit comments

Comments
 (0)