minkphp / phpunit-mink Goto Github PK
View Code? Open in Web Editor NEWLibrary for using Mink in PHPUnit tests. Supports session sharing between tests in a test case.
License: BSD 3-Clause "New" or "Revised" License
Library for using Mink in PHPUnit tests. Supports session sharing between tests in a test case.
License: BSD 3-Clause "New" or "Revised" License
Before recipient check it happened, that upon first test ended all tests received the "test.ended" event and stopped their sessions.
To solve that problem we now check that a BrowserConfiguration which received an event has same test case object attached to it, that one which sent the event.
Such behavior however isn't covered by tests.
We've using encrypted env variables for pass SauceLabs access credentials in .travis.yml
file. For security reasons Travis doesn't decrypt those for Pull Requests (see http://docs.travis-ci.com/user/build-configuration/#Secure-environment-variables).
We should check, that if we're building on Travis + this is Pull Request (TRAVIS_SECURE_ENV_VARS or TRAVIS_PULL_REQUEST), then skip these tests.
Right now there a dependency on PHPUnit in composer.json which:
@stof , can we just remove PHPUnit dependency?
Right now call to BrowserTestCase::getSession()
will not only create session, but also start it automatically. The auto-start behavior comes from IsolatedSessionStategy
.
This behavior might not be desired one, because browser is opened even before any user code, that interacts with it is started.
I think that we can create proxy around Session class, that would ignore explicit calls to start
method and will auto-start (if not running) on call to ->visit
method.
Currently session is started automatically (to put tracking cookie in it) during test run when coverage collection is enabled.
We should only start session when remote coverage collection is enabled (which by the way is disabled by default).
I've had an interesting use case reported in #51 today: the value of baseUrl
setting in browser configuration isn't applied when $this->getSession()->visit('/some/relative/path')
call is made.
The person was most likely working with Behat/MinkExtension before and expected similar to happen here as well. Of course this won't work in this library due absence of Gherkin or similar language that later would be transformed into actual PHP code. Here PHP code is written directly.
If there a need, then maybe the prepareUrl($url)
protected method needs to be added to the test case class, that would:
baseUrl
setting in browser configurationWe can actually take these methods from MinkExtension itself.
I'm not sure if this is feature, that will be widely adopted among library users though.
Would be nice to be able to use this together with PhantomJs.
Currently documentations has links to https://github.com/Behat/Mink, that needs to be replaced to http://mink.behat.org/
Add SauceLabs and BrowserStack logos at repo homepage and docs homepage.
Refactor BrowserConfigurationFactory::createAPIClient
in a way, that we'll end up in abstract ApiBrowserConfiguration::createAPIClient
and each sub-class would create needed client as it see fits.
Proposed change would allow to remove dependency of ApiBrowserConfiguration
descendant classes to the BrowserConfigurationFactory
.
Don't merge associated PR before #40, because there method is made public.
Reference: http://www.copyright.gov/circs/circ01.pdf (page 4)
Before: @copyright Alexander Obuhovich <[email protected]>
After: @copyright 2013 Alexander Obuhovich <[email protected]>
The baseUrl I set in the static $browsers
variable does not have any effect. Take this example:
<?php
namespace AppBundle\Tests\Controller;
use aik099\PHPUnit\BrowserTestCase;
class WhateverControllerTest extends BrowserTestCase
{
public static $browsers = [
[
'driver' => 'selenium2',
'baseUrl' => 'http://www.google.com',
'port' => 8643
]
];
public function testAbc()
{
$this->getSession()->visit('/');
die($this->getSession()->getPage()->getContent());
}
}
?>
This gives me an output like this:
<html><head></head><body></body></html>
However, if I change the argument I pass to visit()
to something like http://www.google.com
instead, everything works as expected.
Pimple 3 is stable (it is basically Pimple 2 without the BC layer for the old Pimple
name as this BC layer was impossible to provide in the C extension).
The requirement should allow using it (if the library uses the Pimple\Container
name everywhere, it should be a matter of changing the constraint to ~2|~3
)
Recently the https://github.com/minkphp organization were created and all Mink-related repositories were moved there. I believe this repository is quite Mink-related as well to be moved there as well.
Here are some specifics about this repo:
.travis.yml
) for testing SauceLabs and BrowserStack services (I'm not sure if either of services allows for personal open-source account usage in another GitHub organization)//cc @stof
Just trying to run my phpunit tests through Mink and Zombie driver. Here is my config
array(
'driver' => 'zombie',
// Defaults for this driver
'port' => 8124,
'driverOptions' => array(
'node_bin' => 'node',
'server_path' => null,
'threshold' => 2000000,
'node_modules_path' => '/Users/path to/node_modules/',
),
),
I have installed zombie locally with npm and exported NODE_PATH in my .zshrc
When I run my test I get following
PHPUnit 4.5.1 by Sebastian Bergmann and contributors.
E
Time: 4.12 seconds, Memory: 6.75Mb
There was 1 error:
1) BrandingHomeTest::testHomePage
RuntimeException: Server did not respond in time: () [Stopped]
/Users//vendor/behat/mink-zombie-driver/src/Behat/Mink/Driver/NodeJS/Server.php:399
/Users//vendor/behat/mink-zombie-driver/src/Behat/Mink/Driver/NodeJS/Server.php:300
/Users//vendor/behat/mink-zombie-driver/src/Behat/Mink/Driver/ZombieDriver.php:78
/Users/vendor/behat/mink/src/Session.php:70
/Users//vendor/aik099/phpunit-mink/library/aik099/PHPUnit/Session/IsolatedSessionStrategy.php:79
/Users/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:289
/Users/HomeTest.php:11
/Users/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:371
/Users/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:319
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
I am not sure if I am missing any config ?
Have someone tried that ?
On the Travis CI the testCreateBrowserConfiguration
test can't finish within 1 second and is blocked by PHP_Invoker
which results in failed build (e.g. https://travis-ci.org/minkphp/phpunit-mink/jobs/47426343). This happens at random PHP versions and random times.
Make BrowserConfiguration::createSession
method to remember each created session somewhere in central place (shared between browser configurations).
Then via register_shutdown_function
ensure, that all sessions are stopped. This would save the day when #5 will be implemented, because we'll have 1 session per browser which is only reset (not stopped) in each test/test case.
PHPUNIT
and SELENIUM
words are being used in prepend.php
and append.php
append.php
with a function registered via register_shutdown_function
(as in Codeception)Taking a screenshot of failed test is great way to help developers in debugging what's failed.
I think that we need an option to make screenshots of failing tests and optionally, when under Jenkins environment also output the path to a screenshot (see https://www.youtube.com/watch?v=QzAnUzqAsqE).
Based on format in https://github.com/Behat/MinkExtension/blob/b1740f4c866cfbd47e1f292c1c318517b7b649b7/doc/index.rst we can allow to set the driver
option within browser configuration that later can be used during session creation.
We also need to add support for existing Mink drivers.
I'm not sure why, but right now SauceLabs tests are not passing due The Selenium Server is not active on host ...
error. See https://travis-ci.org/minkphp/phpunit-mink/jobs/46299060#L476
Need to run them locally and debug all WebDriver communication to determine cause of a problem.
Right now BrowserConfiguration::createSession
method allows to create a new session (no auto-start) based on browser configuration.
To implement #5 it would be great to:
BrowserConfiguration::terminateSession
method, that would (according to termination setting) stop or reset given session.The other Mink libraries are using the Symfony2 coding standards, which are a superset of PSR-2.
The current coding standards are conflicting with PSR-2, making it harder for new contributors to get them right (and forcing more experienced contributors to reconfigure their IDEs when switching to this project).
I identified 2 main violations of PSR-2 in the current coding standards:
I haven't reviewed everything in depth to build an exhaustive list though.
Note that a nice thing when using the PSR-2 coding standard is that the PHP-CS-Fixer can be used to fix many violations automatically (instead of just complaining in PHPCS). this is how I ensure the consistent coding standards on other Mink repos (the PHP-CS-Fixer also handles many Symfony-specific rules on top of PSR-2 btw).
Hi there,
I am getting with v2.0.0 the error
Fatal error: Call to undefined method PHPUnit_Framework_TestSuite_DataProvider::setEventDispatcher() in [snip]\vendor\aik099\phpunit-mink\library\aik099\PHP
Unit\TestSuite\AbstractTestSuite.php on line 91
Here is my test:
<?php
namespace Tests;
use aik099\PHPUnit\BrowserTestCase;
/**
* Description of testCrossBrowserLayout
*
* @author KEH
*/
class CrossBrowserLayoutTest extends BrowserTestCase {
public static $browsers = array(
array(
'host' => 'localhost',
'port' => 4444,
'browserName' => 'firefox',
'baseUrl' => 'http://www.google.com',
),
);
public function testPageProvider() {
// parse your data file however you want
$data = array();
$data[] = array(
'pageid' => 'A0001',
'pagename' => 'home.htm',
'pagetype' => 'MAS'
);
return $data;
}
/**
* @dataProvider testPageProvider
*/
public function testPushAndPop($page) {
$this->assertTrue($page['pageid'] == 'A0001');
}
}
I really need the data provider to crawl through several pages and execute tests on them.
Can you help out?
Create tests that would verify, that all events dispatched across the system during test execution, are received by whoever has subscribed to them.
The shared session strategy is supposed to switch focus to 1st opened window in the session before each test. This is done by specifying empty window name to the Session::switchToWindow
call of the Mink library.
I'm not sure anymore that it's the correct approach.
After #12 is implemented the session driver creation is moved away from SessionFactory
class to the corresponding driver factories. And the SessionFactory
only has 1 line long method called createSession
:
The only class using that method is IsolatedSessionStrategy
that can create/start sessions. I propose, that we:
ISessionFactory
interfaceSessionFactory
classSessionFactory::createSession
method into IsolatedSessionStrategy::session
method@stof , can you please create PR similar to qa-tools/qa-tools#125 for this library?
Currently, the created session is terminated using the stop
method which closes the browser completely and reopens it when the next session is created.
This takes a lot of time. If there is no need for such restriction (session creation for each test/test case), then we need to be able to use the reset
method, which would only clear browser cookies.
Then we also need to visit the base URL (no matter what) on each session creation to ensure that any visual state of the last visited page is reset as well (e.g. checkbox sticky state for example, where page reload doesn't uncheck checkboxes).
The draft name for this functionality is soft isolated session strategy
.
Problem I'm facing is when a single SauceLabs/BrowserStack account is used to test multiple websites. In such scenario tests for both websites are mixed with no easy way to identify them.
I'm proposing to:
project
for BrowserStack (https://www.browserstack.com/automate#builds-projects)first tag
for SauceLabs (https://saucelabs.com/docs/additional-config)to identify a particular browser configuration.
Example in section #per-test-configuration produce error: Fatal error: Call to a member function createBrowserConfiguration() on a non-object in blabla/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php on line 242
As I understood from the code, developer should set instance of BrowserConfigurationFactory for BrowserTestCase first?!
Framework extensibility needs to be improved. To do that we need to:
Coding standard allows to skip DocBlocks completely in test suite and that's why we can:
/**
* Test description.
*
* @return void
*/
@expects...
tags)Migrate documentation to ReadTheDocs.org as Mockery did for example.
Include "@throws" in "createDriver" method of driver factories, because otherwise there would be a CS violation. Probably CS was changed a bit since original code was written.
In the PHPUnit 4.6 the TestSuite::setDisallowChangesToGlobalState
method was added and is called during test suite run. During testing the test suite class is being mocked, but since it's unaware about this new method being called this all ends up in failing test with this error:
1) tests\aik099\PHPUnit\Integration\SuiteBuildingTest::testSuiteTearDown
BadMethodCallException: Method Mockery_19_aik099_PHPUnit_TestSuite_BrowserTestSuite::setDisallowChangesToGlobalState() does not exist on this mock object
/home/user/phpunit-mink/tests/aik099/PHPUnit/Integration/SuiteBuildingTest.php:86
/home/user/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:149
/home/user/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:100
The tests on travis that passed were executed using PHPUnit 4.5 version.
Current license says:
/**
* This file is part of the phpunit-mink library.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @copyright Alexander Obuhovich <[email protected]>
* @link https://github.com/aik099/phpunit-mink
*/
The repo url is wrong and maybe something needs to be done about @copyright
tag, but I'm not sure what.
@stof , ideas?
I am running tests with PHPUnit, using Mink to write acceptance tests.
I have come across the error when modifying the "GeneralTest" class given in the examples.
To reproduce:
For now, the only workaround I have is to omit the shared session declaration and have a new browser window load for each test method (unnecessarily slow).
Right now BrowserConfiguration
is created for each test in a testcase (new object) even if we know ahead, that all tests in a test case will be using same configuration (via $browsers
static class property).
Need to move that up to BrowserTestSuite
class.
Right now the following 2 browser configurations are supported:
Now BrowserStack also supports Selenium through WebDriver protocol (see https://www.browserstack.com/automate/php) and we need to add browser configuration to use it.
Hi,
I found a bug about SharedSessionStrategy.
At 131 lines in SharedSessionStrategy.php file, $this->_session->switchToWindow()
has no parameters. This will cause Selenium2 throws an exception if I use shared strategy.
After I change this line to $this->_session->switchToWindow($this->_session->getWindowName())
, it works.
So please fix this bug. Thanks.
PS. Blow is the error details
WebDriver\Exception\UnknownError: unknown error: 'name' must be a nonempty string
(Session info: chrome=46.0.2490.86)
(Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 3.13.0-32-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'ubuntu', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7.0_75'
Session ID: 82b9bf3f777bba7a5bc3c73f322bc90a
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.com.google.Chrome.x7DP64}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=46.0.2490.86, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
/home/litb/workspace/browser_test/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:155
/home/litb/workspace/browser_test/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:140
/home/litb/workspace/browser_test/vendor/instaclick/php-webdriver/lib/WebDriver/Session.php:273
/home/litb/workspace/browser_test/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:407
/home/litb/workspace/browser_test/vendor/behat/mink/src/Session.php:304
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/Session/SharedSessionStrategy.php:131
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/Session/SharedSessionStrategy.php:103
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:289
/home/litb/workspace/browser_test/tests/LoginTest.php:69
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:371
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:319
Currently the Selenium dependency is hardcoded:
selenium
Mink driver is a requirement in composer.json
timeout
and desiredCapabilities
settings in BrowserConfiguraiton
only apply to SeleniumAfter #12 is implemented we can, but this will be BC break for sure:
selenium
requirement in composer.json
with suggest tag, that Mink itself usesdesiredCapabilities
and timeout
from global BrowserConfiguration
options to Selenium2 driver specific optionsI have multiple test methods with shared sessionStrategy. In the first test, i visit my URL. If this test is passing, the other tests work as well. Otherwise, the session is reset to a blank page. Maybe it's a feature, not a bug? But I think it should be saved.
Code:
class ExampleTest extends BrowserTestCase
{
public static $browsers = array(
array(
'driver' => 'selenium2',
'host' => 'localhost',
'port' => 4444,
'browserName' => 'firefox',
'baseUrl' => 'http://localhost',
'sessionStrategy' => 'shared'
),
);
public function test1()
{
$session = $this->getSession();
$session->visit( 'http://localhost/test' );
$this->assertTrue( 1 == 2 );
}
public function test2()
{
// blank page if test1 is failing
file_put_contents('/tmp/screenshot.png', $this->getSession()->getDriver()->getScreenshot());
}
}
I've tried to use phpunit-mink with my Silex application, but stumbled upon a roadblock. Silex 1.2 (current stable) uses Pimple ~1.0 while phpunit-mink requires Pimple 2.0 or upper. Composer is not able to resolve the conflicts, as Pimple public interface has changed.
My idea is to remove dependency on Pimple in Composer to avoid conflicts. Some ways I see it can be done:
Personally I'm in favor of Dependency Inversion, but libraries depending on Dependency Injection Container are hard to integrate due to such issues. Let me know your thoughts.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.