Skip to content

Commit

Permalink
Prepare 241 (Codeception#4904)
Browse files Browse the repository at this point in the history
* updates to composer

* updated changelog

* fixed installing pecl modules

* * Added documentation for `callArtisan`
* Fixed warning tests for PHPUnit 5.6

* fixed travis builds

* fixed WebDriver tests
  • Loading branch information
DavertMik authored Mar 31, 2018
1 parent 08e487b commit 59afc7c
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 61 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 78,7 @@ before_install:
install:
- '[[ -z "$CI_USER_TOKEN" ]] || composer config github-oauth.github.com ${CI_USER_TOKEN};'
# Add extensions
- '[[ -z "$PECL" ]] || (yes "" | pecl install $PECL)'
- '[[ -z "$PECL" ]] || (yes "" | pecl install -f $PECL)'
# Clone test repository
- '[[ "$FRAMEWORK" == "Codeception" ]] || git clone -q --depth=1 $TEST_REPO framework-tests'
- '[[ "$FRAMEWORK" == "Codeception" ]] || git --git-dir framework-tests/.git log -n 1'
Expand Down Expand Up @@ -128,5 128,4 @@ before_script:
# Build
- php codecept build -c $TEST_PATH
script:
#- '[[ !("$FRAMEWORK" == "Codeception" && "$TRAVIS_PHP_VERSION" == "7.1") ]] || php codecept run coverage' # run coverage tests on php only
- php codecept run $SUITES -c $TEST_PATH
26 changes: 20 additions & 6 deletions CHANGELOG-2.4.md
Original file line number Diff line number Diff line change
@@ -1,3 1,22 @@
#### 2.4.1

* Fixed `PHP Fatal error: Uncaught Error: Call to undefined method Codeception\Test\Descriptor::getTestDataSetIndex()` when filtering tests
* Better support of PHPUnit warning status by @edno:
* support PHPUnit addWarning()
* display 'W' instead of success for warning test cases
* Fixed Running test with invalid dataprovider by @okneloper. Fixed #4888 by @edno
* [Yii2] **Request flow and database transactions refactored** (by @sammousa):
* **Breaking** Application is no longer available in helpers via `$this->getModule('Yii2'')->app`, now you must use `\Yii::$app` everywhere
* Multiple databases are now supported
* More reliable application state before and during test execution
* Fixtures method is now configurable
* Subset of misconfigurations are now detected and informative messages created
* Fixed using `$settings['path']` in `Codeception\Configuration::suiteSettings()` on Windows by @olegpro
* [Laravel5] Added Laravel 5.4 (5.1 backward compatible) support for `callArtisan` method in Laravel5 module. See #4860 by @mohamed-aiman
* Fixed #4854: unnecessary escaping in operation arguments logging by @nicholascus
* Fixed humanizing steps for utf8 strings by @nicholascus. See #4850
* Fixed parsing relative urls in `parse_url`. See #4853 by @quantum-x

#### 2.4.0

* **PHPUnit 7.x compatibility**
Expand All @@ -10,12 29,7 @@
* `_failed` called when test fails
* `_passed` called when tests is successful
* `_after` is called for failing and successful tests
* Yii2 Module request flow and database transactions refactored (by @sammousa):
* Multiple databases are now supported
* More reliable application state before and during test execution
* Fixtures method is now configurable
* Subset of misconfigurations are now detected and create informative messages
* Application is no longer available via the `$module->app`, now you must use `\Yii::$app` everywhere

**Upgrade Notice**: If you face issues with underscore PHPUnit class names (like PHPUnit_Framework_Assert) you have two options:

* Lock version for PHPUnit in composer.json: "phpunit/phpunit":"^5.0.0"
Expand Down
17 changes: 2 additions & 15 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 96,21 @@ public function testCoverage()
public function testWebdriver($args = '', $opt = ['test|t' => null])
{
$test = $opt['test'] ? ':'.$opt['test'] : '';
$container = $this->taskDockerRun('davert/selenium-env')
->detached()
->publish(4444, 4444)
->env('APP_PORT', 8000)
->run();

$this->taskServer(8000)
->dir('tests/data/app')
->background()
->host('0.0.0.0')
->run();

sleep(3); // wait for selenium to launch

$this->taskCodecept('./codecept')
->test('tests/web/WebDriverTest.php'.$test)
->suite('web')
->args($args)
->run();

$this->taskDockerStop($container)->run();
}

public function testLaunchServer($pathToSelenium = '~/selenium-server.jar ')
public function testLaunchServer()
{
$this->taskExec('java -jar '.$pathToSelenium)
->background()
->run();

$this->taskServer(8010)
->background()
->dir('tests/data/rest')
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 29,7 @@
"symfony/css-selector": ">=2.7 <5.0",
"symfony/dom-crawler": ">=2.7 <5.0",
"behat/gherkin": "^4.4.0",
"codeception/phpunit-wrapper": "^6.0|^7.0",
"codeception/phpunit-wrapper": "^6.0.9|^7.0.6",
"codeception/stub": "^1.0"
},
"require-dev": {
Expand Down
9 changes: 6 additions & 3 deletions src/Codeception/Module/Laravel5.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 419,22 @@ public function dontSeeEventTriggered($events)
* <?php
* $I->callArtisan('command:name');
* $I->callArtisan('command:name', ['parameter' => 'value']);
* ?>
* ```
* Use 3rd parameter to pass in custom `OutputInterface`
*
* @param string $command
* @param array $parameters
* @param OutputInterface $output
* @return string
*/
public function callArtisan($command, $parameters = [], OutputInterface $output = null)
{
$console = $this->app->make('Illuminate\Contracts\Console\Kernel');
if (!$output) {
$console->call($command, $parameters);
return trim($console->output());
$output = trim($console->output());
$this->debug($output);
return $output;
}

$console->call($command, $parameters, $output);
Expand Down
64 changes: 38 additions & 26 deletions src/Codeception/Module/WebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 341,18 @@ public function _requires()
return ['Facebook\WebDriver\Remote\RemoteWebDriver' => '"facebook/webdriver": "^1.0.1"'];
}

/**
* @return RemoteWebElement
* @throws ModuleException
*/
protected function getBaseElement()
{
if (!$this->baseElement) {
throw new ModuleException($this, "Page not loaded. Use `\$I->amOnPage` (or hidden API methods `_request` and `_loadPage`) to open it");
}
return $this->baseElement;
}

public function _initialize()
{
$this->wdHost = sprintf('%s://%s:%s%s', $this->config['protocol'], $this->config['host'], $this->config['port'], $this->config['path']);
Expand Down Expand Up @@ -682,7 694,7 @@ protected function getProxy()
public function _getCurrentUri()
{
$url = $this->webDriver->getCurrentURL();
if ($url == 'about:blank') {
if ($url == 'about:blank' || strpos($url, 'data:') === 0) {
throw new ModuleException($this, 'Current url is blank, no page was opened');
}
return Uri::retrieveUri($url);
Expand Down Expand Up @@ -1087,7 1099,7 @@ protected function findField($selector)
public function seeLink($text, $url = null)
{
$this->enableImplicitWait();
$nodes = $this->baseElement->findElements(WebDriverBy::partialLinkText($text));
$nodes = $this->getBaseElement()->findElements(WebDriverBy::partialLinkText($text));
$this->disableImplicitWait();
$currentUri = $this->_getCurrentUri();

Expand All @@ -1102,7 1114,7 @@ public function seeLink($text, $url = null)

public function dontSeeLink($text, $url = null)
{
$nodes = $this->baseElement->findElements(WebDriverBy::partialLinkText($text));
$nodes = $this->getBaseElement()->findElements(WebDriverBy::partialLinkText($text));
$currentUri = $this->_getCurrentUri();
if (!$url) {
$this->assertEmpty($nodes, "Link containing text '$text' was found in page $currentUri");
Expand Down Expand Up @@ -1213,7 1225,7 @@ public function dontSeeInFormFields($formSelector, array $params)

protected function proceedSeeInFormFields($formSelector, array $params, $assertNot)
{
$form = $this->match($this->baseElement, $formSelector);
$form = $this->match($this->getBaseElement(), $formSelector);
if (empty($form)) {
throw new ElementNotFound($formSelector, "Form via CSS or XPath");
}
Expand Down Expand Up @@ -1540,7 1552,7 @@ protected function findCheckable($context, $radioOrCheckbox, $byValue = false)
}

if (is_array($radioOrCheckbox) or ($radioOrCheckbox instanceof WebDriverBy)) {
return $this->matchFirstOrFail($this->baseElement, $radioOrCheckbox);
return $this->matchFirstOrFail($this->getBaseElement(), $radioOrCheckbox);
}

$locator = Crawler::xpathLiteral($radioOrCheckbox);
Expand Down Expand Up @@ -1610,7 1622,7 @@ public function checkOption($option)

public function uncheckOption($option)
{
$field = $this->findCheckable($this->baseElement, $option);
$field = $this->findCheckable($this->getBaseElement(), $option);
if (!$field) {
throw new ElementNotFound($option, "Checkbox by Label or CSS or XPath");
}
Expand Down Expand Up @@ -1671,10 1683,10 @@ public function attachFile($field, $filename)
*/
protected function getVisibleText()
{
if ($this->baseElement instanceof RemoteWebElement) {
return $this->baseElement->getText();
if ($this->getBaseElement() instanceof RemoteWebElement) {
return $this->getBaseElement()->getText();
}
$els = $this->baseElement->findElements(WebDriverBy::cssSelector('body'));
$els = $this->getBaseElement()->findElements(WebDriverBy::cssSelector('body'));
if (isset($els[0])) {
return $els[0]->getText();
}
Expand All @@ -1683,7 1695,7 @@ protected function getVisibleText()

public function grabTextFrom($cssOrXPathOrRegex)
{
$els = $this->match($this->baseElement, $cssOrXPathOrRegex, false);
$els = $this->match($this->getBaseElement(), $cssOrXPathOrRegex, false);
if (count($els)) {
return $els[0]->getText();
}
Expand All @@ -1695,7 1707,7 @@ public function grabTextFrom($cssOrXPathOrRegex)

public function grabAttributeFrom($cssOrXpath, $attribute)
{
$el = $this->matchFirstOrFail($this->baseElement, $cssOrXpath);
$el = $this->matchFirstOrFail($this->getBaseElement(), $cssOrXpath);
return $el->getAttribute($attribute);
}

Expand All @@ -1712,7 1724,7 @@ public function grabValueFrom($field)

public function grabMultiple($cssOrXpath, $attribute = null)
{
$els = $this->match($this->baseElement, $cssOrXpath);
$els = $this->match($this->getBaseElement(), $cssOrXpath);
return array_map(
function (WebDriverElement $e) use ($attribute) {
if ($attribute) {
Expand Down Expand Up @@ -1769,7 1781,7 @@ public function dontSeeElement($selector, $attributes = [])
public function seeElementInDOM($selector, $attributes = [])
{
$this->enableImplicitWait();
$els = $this->match($this->baseElement, $selector);
$els = $this->match($this->getBaseElement(), $selector);
$els = $this->filterByAttributes($els, $attributes);
$this->disableImplicitWait();
$this->assertNotEmpty($els);
Expand All @@ -1784,7 1796,7 @@ public function seeElementInDOM($selector, $attributes = [])
*/
public function dontSeeElementInDOM($selector, $attributes = [])
{
$els = $this->match($this->baseElement, $selector);
$els = $this->match($this->getBaseElement(), $selector);
$els = $this->filterByAttributes($els, $attributes);
$this->assertEmpty($els);
}
Expand All @@ -1809,7 1821,7 @@ public function seeNumberOfElements($selector, $expected)

public function seeNumberOfElementsInDOM($selector, $expected)
{
$counted = count($this->match($this->baseElement, $selector));
$counted = count($this->match($this->getBaseElement(), $selector));
if (is_array($expected)) {
list($floor, $ceil) = $expected;
$this->assertTrue(
Expand Down Expand Up @@ -2157,7 2169,7 @@ protected function getSubmissionFormFieldName($name)
*/
public function submitForm($selector, array $params, $button = null)
{
$form = $this->matchFirstOrFail($this->baseElement, $selector);
$form = $this->matchFirstOrFail($this->getBaseElement(), $selector);

$fields = $form->findElements(
WebDriverBy::cssSelector('input:enabled,textarea:enabled,select:enabled,input[type=hidden]')
Expand Down Expand Up @@ -2255,7 2267,7 @@ public function submitForm($selector, array $params, $button = null)
*/
public function waitForElementChange($element, \Closure $callback, $timeout = 30)
{
$el = $this->matchFirstOrFail($this->baseElement, $element);
$el = $this->matchFirstOrFail($this->getBaseElement(), $element);
$checker = function () use ($el, $callback) {
return $callback($el);
};
Expand Down Expand Up @@ -2565,8 2577,8 @@ public function maximizeWindow()
*/
public function dragAndDrop($source, $target)
{
$snodes = $this->matchFirstOrFail($this->baseElement, $source);
$tnodes = $this->matchFirstOrFail($this->baseElement, $target);
$snodes = $this->matchFirstOrFail($this->getBaseElement(), $source);
$tnodes = $this->matchFirstOrFail($this->getBaseElement(), $target);

$action = new WebDriverActions($this->webDriver);
$action->dragAndDrop($snodes, $tnodes)->perform();
Expand Down Expand Up @@ -2597,7 2609,7 @@ public function moveMouseOver($cssOrXPath = null, $offsetX = null, $offsetY = nu
{
$where = null;
if (null !== $cssOrXPath) {
$el = $this->matchFirstOrFail($this->baseElement, $cssOrXPath);
$el = $this->matchFirstOrFail($this->getBaseElement(), $cssOrXPath);
$where = $el->getCoordinates();
}

Expand Down Expand Up @@ -2678,7 2690,7 @@ public function pauseExecution()
*/
public function doubleClick($cssOrXPath)
{
$el = $this->matchFirstOrFail($this->baseElement, $cssOrXPath);
$el = $this->matchFirstOrFail($this->getBaseElement(), $cssOrXPath);
$this->webDriver->getMouse()->doubleClick($el->getCoordinates());
}

Expand Down Expand Up @@ -2819,7 2831,7 @@ protected function matchFirstOrFail($page, $selector)
*/
public function pressKey($element, $char)
{
$el = $this->matchFirstOrFail($this->baseElement, $element);
$el = $this->matchFirstOrFail($this->getBaseElement(), $element);
$args = func_get_args();
array_shift($args);
$keys = [];
Expand Down Expand Up @@ -2954,7 2966,7 @@ public function appendField($field, $value)

if ($type == 'checkbox') {
//Find by value or css,id,xpath
$field = $this->findCheckable($this->baseElement, $value, true);
$field = $this->findCheckable($this->getBaseElement(), $value, true);
if (!$field) {
throw new ElementNotFound($value, "Checkbox or Radio by Label or CSS or XPath");
}
Expand All @@ -2981,7 2993,7 @@ public function appendField($field, $value)
*/
protected function matchVisible($selector)
{
$els = $this->match($this->baseElement, $selector);
$els = $this->match($this->getBaseElement(), $selector);
$nodes = array_filter(
$els,
function (WebDriverElement $el) {
Expand Down Expand Up @@ -3096,7 3108,7 @@ protected function isPhantom()
*/
public function scrollTo($selector, $offsetX = null, $offsetY = null)
{
$el = $this->matchFirstOrFail($this->baseElement, $selector);
$el = $this->matchFirstOrFail($this->getBaseElement(), $selector);
$x = $el->getLocation()->getX() $offsetX;
$y = $el->getLocation()->getY() $offsetY;
$this->webDriver->executeScript("window.scrollTo($x, $y)");
Expand Down Expand Up @@ -3239,7 3251,7 @@ public function performOn($element, $actions, $timeout = 10)
{
$this->waitForElement($element, $timeout);
$this->setBaseElement($element);
$this->debugSection('InnerText', $this->baseElement->getText());
$this->debugSection('InnerText', $this->getBaseElement()->getText());

if (is_callable($actions)) {
$actions($this);
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/RunCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 487,7 @@ public function runCestWithTwoFailedTest(CliGuy $I)

public function runWarningTests(CliGuy $I)
{
$I->executeCommand('run unit WarningTest.php:testWarningInvalidDataProvider', false);
$I->executeCommand('run unit WarningTest.php', false);
$I->seeInShellOutput('There was 1 warning');
$I->seeInShellOutput('WarningTest::testWarningInvalidDataProvider');
$I->seeInShellOutput('Tests: 1,');
Expand Down
2 changes: 1 addition & 1 deletion tests/data/app/db
Original file line number Diff line number Diff line change
@@ -1 1 @@
a:1:{s:6:"params";a:0:{}}
a:0:{}
3 changes: 2 additions & 1 deletion tests/web.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,7 @@ modules:
config:
WebDriver:
url: http://localhost:8000
browser: firefox
browser: chrome
window_size: 1200x768
restart: true # Use a new browser window for each test (to isolate test cases from each other)
env:
Expand All @@ -30,6 30,7 @@ env:
WebDriver:
browser: chrome
window_size: false
restart: false
capabilities:
chromeOptions:
args: ["--headless", "--disable-gpu", "--disable-extensions"]
Expand Down
Loading

0 comments on commit 59afc7c

Please sign in to comment.