Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correcting errors in the documentation #127

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/browser-aliases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ Browser Aliases
===============
All previous examples demonstrate various ways how browser configuration can be defined, but they all have
same downside - server connection details stay hard-coded in test case classes. This could become very
problematic if:
problematic when:

* same test cases needs to be executed on different servers (e.g. each developer runs them on his own machine)
* due change in server connection details each test case class needs to be changed
* the same test cases needs to be executed on the different servers (e.g. each developer runs them on his own machine)
* due change in the server connection details each test case class needs to be changed

To solve this problem a browser aliases were introduced. Basically a browser alias is predefined browser
To solve this problem a browser aliases were introduced. Basically a browser alias is a predefined browser
configuration, that is available in the test case by it's alias. Here is how it can be used:

#. create base test case class, by extending ``BrowserTestCase`` class in the project
with ``getBrowserAliases`` method in it
#. the ``getBrowserAliases`` method will return an associative array of a browser configurations (array key acts as alias name)
#. the ``getBrowserAliases`` method will return an associative array of a browser configurations (array key acts as an alias name)
#. in any place, where browser configuration is defined use ``'alias' => 'alias_name_here'`` instead of actual browser configuration
#. feel free to override any part of configuration defined in alias
#. feel free to override any part of the configuration defined in the alias

.. note:: Nested aliases are also supported.

Expand Down
52 changes: 26 additions & 26 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Configuring Browser
===================
The browser needs to be configured in a test case before being able to access `Mink`_ session.
All possible ways of browser configuration are described below.
The browser needs to be configured in a test case before being able to access the `Mink`_ session.
All possible ways of the browser configuration are described below.

Per Test Configuration
^^^^^^^^^^^^^^^^^^^^^^
It is possible to configure browser individually for each test within a test case by creating
an instance of ``\aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration`` class in ``setUpTest``
method in of test case class and setting it via ``setBrowser`` method.
an instance of the ``\aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration`` class in the
``setUpTest`` method of test case class and setting it through the ``setBrowser`` method.

.. literalinclude:: examples/configuration/config_via_setup_method.php
:linenos:
Expand All @@ -16,30 +16,30 @@ method in of test case class and setting it via ``setBrowser`` method.
Per Test Case Configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^
In case, when all tests in a test case share same browser configuration it's easier to specify it via
static ``$browsers`` property (array, where each item represents a single browser
configuration) in that test case class.
the static ``$browsers`` property (array, where each element represents a single browser configuration)
in that test case class.

.. literalinclude:: examples/configuration/config_via_browsers_property.php
:linenos:
:emphasize-lines: 8,9,16

.. note:: When several browser configurations are specified in ``$browsers`` array, then each test
in a test case will be executed against each of browser configurations.
.. note:: When several browser configurations are specified in the ``$browsers`` array, then each test
in a test case will be executed against each of the browser configurations.

Browser Session Sharing
^^^^^^^^^^^^^^^^^^^^^^^
As a benefit of shared (per test case) browser configuration, that was described above is an ability
to not only share browser configuration, that is used to create `Mink`_ session, but to actually share
created sessions between all tests in a single test case. This can be done by adding ``sessionStrategy``
option (line 14) to the browser configuration.
As a benefit of the shared (per test case) browser configuration, that was described above is an ability
to not only to share the browser configuration, that is used to create `Mink`_ session, but to actually share
created sessions between all tests in a single test case. This can be done by adding the ``sessionStrategy``
option (line 15) to the browser configuration.

.. literalinclude:: examples/configuration/per_test_case_browser_config.php
:linenos:
:emphasize-lines: 15

Selecting the Mink Driver
^^^^^^^^^^^^^^^^^^^^^^^^^
With the help of ``driver`` and ``driverOptions`` browser configuration settings (since v2.1.0) it's possible to
With the help of the ``driver`` and the ``driverOptions`` browser configuration settings (since v2.1.0) it's possible to
specify which `Mink`_ driver to use. This file demonstrates how to use each driver:

.. literalinclude:: examples/configuration/driver_showcase.php
Expand All @@ -53,22 +53,22 @@ Each browser configuration consists of the following settings (all optional):
======================= ==================================================================================================
Name Description
======================= ==================================================================================================
``driver`` Mink driver name (defaults to ``selenium2``, since v2.1.0)
``driver`` Mink driver name (defaults to the ``selenium2``, since v2.1.0)
``driverOptions`` Mink driver specific options (since v2.1.0)
``host`` host, where driver's server is located (defaults to ``localhost``)
``port`` port, on which driver's server is listening for incoming connections (determined by driver)
``host`` host, where driver's server is located (defaults to the ``localhost``)
``port`` port, on which driver's server is listening for the incoming connections (determined by the driver)
``timeout`` connection timeout of the server in seconds ('selenium2' driver only, defaults to ``60``)
``browserName`` name of browser to use (e.g. ``firefox``, ``chrome``, etc., defaults to ``firefox``)
``desiredCapabilities`` parameters, that allow to fine-tune browser and other 'selenium2' driver options (e.g. 'tags',
'project', 'os', 'version')
``baseUrl`` base url of website, that is tested
``browserName`` name of the browser to use (e.g. ``firefox``, ``chrome``, etc., defaults to the ``firefox``)
``desiredCapabilities`` parameters, that allow to fine-tune browser and other ``selenium2`` driver options (e.g. ``tags``,
``project``, ``os``, ``version``)
``baseUrl`` base url of the website, that is tested
``sessionStrategy`` used session strategy (defaults to ``isolated``)
``type`` type of configuration (defaults to ``default``, but can also be ``saucelabs`` or ``browserstack``)
``apiUsername`` API username of used service (applicable to 'saucelabs' and 'browserstack' browser configurations)
``apiKey`` API key of used service (applicable to 'saucelabs' and 'browserstack' browser configurations)
``type`` type of the configuration (defaults to ``default``, but also can be ``saucelabs`` or ``browserstack``)
``apiUsername`` API username of the used service (applicable to the ``saucelabs`` and ``browserstack`` browser configurations)
``apiKey`` API key of the used service (applicable to ``saucelabs`` and ``browserstack`` browser configurations)
======================= ==================================================================================================

There are also corresponding setters (e.g. ``setHost``) and getters (e.g. ``getHost``) for each of mentioned
above settings, that allow to individually change them from ``setUpTest`` method before test has started.
There are also corresponding setters (e.g. ``setHost``) and getters (e.g. ``getHost``) for each of the mentioned
above settings, that allow to individually change them from the ``setUpTest`` method before test has started.

.. _`Mink`: https://github.com/Behat/Mink
.. _`Mink`: https://github.com/minkphp/Mink
12 changes: 6 additions & 6 deletions docs/examples/configuration/config_via_setup_method.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class PerTestBrowserConfigTest extends BrowserTestCase
*/
protected function setUpTest()
{
// To create regular browser configuration via BrowserConfigurationFactory.
// Creates the regular browser configuration using "BrowserConfigurationFactory".
$browser = $this->createBrowserConfiguration(array(
// options goes here (optional)
));

// To create "Sauce Labs" browser configuration via BrowserConfigurationFactory.
// Creates the "Sauce Labs" browser configuration using "BrowserConfigurationFactory".
$browser = $this->createBrowserConfiguration(array(
// required
'type' => 'saucelabs',
Expand All @@ -24,12 +24,12 @@ protected function setUpTest()
// optional options goes here
));

// To create "BrowserStack" browser configuration via BrowserConfigurationFactory.
// Creates the "BrowserStack" browser configuration using "BrowserConfigurationFactory".
$browser = $this->createBrowserConfiguration(array(
// required
'type' => 'browserstack',
'api_username' => 'bs_username',
'api_key' => 'bs_api_key',
'apiUsername' => 'bs_username',
'apiKey' => 'bs_api_key',
// optional options goes here
));

Expand All @@ -40,7 +40,7 @@ protected function setUpTest()
));
$browser->setBaseUrl('http://www.test-host.com');

// Set browser configuration to test case.
// Set browser configuration to the test case.
$this->setBrowser($browser);

parent::setUpTest();
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/getting-started/cloud_selenium_configs.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ class BrowserConfigExampleTest extends BrowserTestCase
'browserName' => 'firefox',
'baseUrl' => 'http://www.google.com',
),

// BrowserStack browser configuration.
array(
'type' => 'browserstack',
'api_username' => '...',
'api_key' => '...',
'apiUsername' => '...',
'apiKey' => '...',
'browserName' => 'firefox',
'baseUrl' => 'http://www.google.com',
),

// Regular browser configuration.
array(
'driver' => 'selenium2',
Expand Down
38 changes: 19 additions & 19 deletions docs/getting-started.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Getting Started
===============
Below you'll find all needed information to find your way across the library.
Below you'll find all the needed information to find your way across the library.

Installation
^^^^^^^^^^^^
Library can be installed using Composer like so:
The library can be installed using Composer like so:

1. define the dependencies in your ``composer.json``:

Expand All @@ -25,45 +25,45 @@ Library can be installed using Composer like so:

Basic Usage
^^^^^^^^^^^
#. sub-class test case class from ``\aik099\PHPUnit\BrowserTestCase`` class (line 5)
#. define used browser configurations in static ``$browsers`` property of that class (line 8-21)
#. access `Mink`_ session by calling ``$this->getSession()`` method in your test (line 26)
#. access browser configuration by calling ``$this->getBrowser()`` method in your test (line 40)
#. sub-class the test case class from the ``\aik099\PHPUnit\BrowserTestCase`` class (line 5)
#. define used browser configurations in the static ``$browsers`` property of that class (line 8-16)
#. access the `Mink`_ session by calling the ``$this->getSession()`` method in your test (line 21)
#. access browser configuration by calling the ``$this->getBrowser()`` method in your test (line 35)

.. literalinclude:: examples/getting-started/general_test.php
:linenos:
:emphasize-lines: 5,8,21,35
:emphasize-lines: 5,8-16,21,35

Selenium in Cloud
^^^^^^^^^^^^^^^^^
When using Selenium-based solution for automated testing in the cloud (e.g. `Sauce Labs`_ or `BrowserStack`_) you need to
specify following settings:
Selenium in the Cloud
^^^^^^^^^^^^^^^^^^^^^
When using Selenium-based solution for the automated testing in the cloud (e.g. `Sauce Labs`_ or `BrowserStack`_)
you'll need to specify the following settings:

* ``'type' => 'saucelabs'`` or ``'type' => 'browserstack'``
* ``'apiUsername' => '...'``
* ``'apiKey' => '...'``

instead of ``host`` and ``port`` settings. In all other aspects everything will work the same as if all
instead of the ``host`` and ``port`` settings. In all other aspects everything will work the same as if all
tests were running locally.

.. literalinclude:: examples/getting-started/cloud_selenium_configs.php
:linenos:
:emphasize-lines: 11-13,19-21
:emphasize-lines: 11-13,20-22

Continuous Integration
^^^^^^^^^^^^^^^^^^^^^^
When website under test isn't publicly accessible, then:
When the website under test isn't publicly accessible, then:

#. secure tunnel needs to be created from website under test to server, that runs the tests
#. created tunnel identifier needs to specified in the ``PHPUNIT_MINK_TUNNEL_ID`` environment variable
#. secure tunnel needs to be created from the website under test to the server, that runs the tests
#. the created tunnel identifier needs to specified in the ``PHPUNIT_MINK_TUNNEL_ID`` environment variable

.. note:: Before v2.1.0 the environment variable was called ``TRAVIS_JOB_NUMBER``.

How to Create a Tunnel
----------------------
* SauceLabs: https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy
* BrowserStack: http://www.browserstack.com/automate/php#setting-local-tunnel
* SauceLabs: https://docs.saucelabs.com/secure-connections/sauce-connect-5/
* BrowserStack: https://www.browserstack.com/docs/automate/selenium/getting-started/php/local-testing

.. _`Mink`: https://github.com/Behat/Mink
.. _`Mink`: https://github.com/minkphp/Mink
.. _`Sauce Labs`: https://saucelabs.com/
.. _`BrowserStack`: http://www.browserstack.com/
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Service Integrations
.. |BrowserStack| image:: /assets/images/browserstack_logo.png
.. _BrowserStack: https://www.browserstack.com/

.. _`Mink`: https://github.com/Behat/Mink
.. _`Mink`: https://github.com/minkphp/Mink

.. toctree::
:maxdepth: 2
Expand Down
18 changes: 10 additions & 8 deletions docs/remote-code-coverage.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Remote Code Coverage
====================
Browser tests are executed on different machine, then one, where code coverage information is collected
Browser tests are executed on the different machine, than one, where the code coverage information is collected
(and tests are executed). To solve that problem this library uses remote coverage collection. Following
steps needs to be performed before using this feature:

On Remote Server
^^^^^^^^^^^^^^^^
This is web-server, where website used in tests is located.

#. Install `Xdebug <http://xdebug.org/>`_ PHP extension on web-server
#. Copy ``library/aik099/PHPUnit/RemoteCoverage/RemoteCoverageTool.php`` into web-server's DocumentRoot directory.
#. Install the `Xdebug`_ PHP extension on the web-server
#. Copy the ``library/aik099/PHPUnit/RemoteCoverage/RemoteCoverageTool.php`` file into the web-server's DocumentRoot directory.
#. Include following code before your application bootstraps:

.. code-block:: php
Expand All @@ -21,9 +21,9 @@ This is web-server, where website used in tests is located.

On Test Machine
^^^^^^^^^^^^^^^
This is machine, where PHPUnit tests are being executed.
This is machine, where the PHPUnit tests are being executed.

Following code needs to be placed in the ``setUpTest`` method of the test case class (that extends ``BrowserTestCase``
Following code needs to be placed in the ``setUpTest`` method of the test case class (that extends the ``BrowserTestCase``
class) to enable remote coverage information collection:

.. code-block:: php
Expand All @@ -35,7 +35,9 @@ class) to enable remote coverage information collection:

How This Works
^^^^^^^^^^^^^^
#. each test sets a special cookie on website under test
#. when cookie is present, then ``RemoteCoverageTool.php`` script collects coverage information and stores it on disk
#. once test finishes, then ``http://host/?rct_mode=output`` url is accessed on remote server, which in turn returns collected coverage information
#. each test sets a special cookie on the website under test
#. when cookie is present, then the ``RemoteCoverageTool.php`` script collects coverage information and stores it on disk
#. once test finishes, then the ``http://host/?rct_mode=output`` url is accessed on remote server, which in turn returns collected coverage information
#. remote coverage information is then joined with coverage information collected locally on test machine

.. _`Xdebug`: https://xdebug.org/
Loading