diff --git a/.gitignore b/.gitignore index 187adb2..aee4cde 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -/nbproject/ \ No newline at end of file +/nbproject/ +/vendor/ +/bin/behat +/features/ diff --git a/behat.yml b/behat.yml new file mode 100644 index 0000000..0dc5a14 --- /dev/null +++ b/behat.yml @@ -0,0 +1,12 @@ +default: + extensions: + Behat\MinkExtension: +# base_url: http://16.feature-sd-7626.website.ls.vu/ +# goutte: ~ + selenium2: ~ + suites: + default: + contexts: + - FeatureContext: + parameters: + base_url: http://php.net \ No newline at end of file diff --git a/bin/convert b/bin/convert new file mode 100644 index 0000000..a04a97f --- /dev/null +++ b/bin/convert @@ -0,0 +1,49 @@ + "\e[1;31m", + 'green' => "\e[1;32m" + ]; + echo $colors[$color]; +} + +function resetTextColor() +{ + echo "\e[0m"; +} + +try { + if ($_SERVER['argc'] < 2) { + throw new Exception("There are not enough parameters.\n"); + } + if ($_SERVER['argc'] > 2) { + throw new Exception("There are too many parameters.\n"); + } + + $filePath = $_SERVER['argv'][1]; + $fileName = strstr($filePath, strrpos($filePath, '/')); + if (preg_match('/^[0-9]/', $fileName)) { + throw new Exception("Test file name must not start with number.\n"); + } + if (!file_exists($filePath)) { + throw new Exception("Wrong file name.\n"); + } + $testGenerator = new BehatTestGenerator($filePath); + $testGenerator->generate(); + setTextColor('green'); + echo "Your test converted successfully.\n" + . "Now you can run \"bin/behat features/{$fileName}\"\n"; +} catch (Exception $ex) { + setTextColor('red'); + echo $ex->getMessage(); +} +resetTextColor(); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..cbd120d --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "fouraitch/selenium-ide-php-behat-mink-formatter", + "version": "1.0", + "license": "MIT", + "authors": [ + { + "name": "Narek Vardzelyan", + "email": "narek.vardzelyan@of.am" + } + ], + "require-dev": { + "behat/behat": "3.*@stable", + "behat/mink": "1.7.*@stable", + "behat/mink-extension": "*", + "behat/mink-goutte-driver": "*", + "behat/mink-selenium2-driver": "*" + }, + "minimum-stability": "dev", + "config": { + "bin-dir": "bin/" + }, + "autoload": { + "psr-4": {"Fouraitch\\SeleniumIdeFormatter\\": "src/"} + }, + "bin": ["bin/convert"] +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..62a5569 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1485 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "9d0e9790eb7bdb6754b788721e649002", + "content-hash": "8b51cb5bfbdeca165bafbba45a1aab45", + "packages": [], + "packages-dev": [ + { + "name": "behat/behat", + "version": "v3.0.15", + "source": { + "type": "git", + "url": "https://github.com/Behat/Behat.git", + "reference": "b35ae3d45332d80c532af69cc36f780a9397a996" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Behat/Behat/zipball/b35ae3d45332d80c532af69cc36f780a9397a996", + "reference": "b35ae3d45332d80c532af69cc36f780a9397a996", + "shasum": "" + }, + "require": { + "behat/gherkin": "~4.3", + "behat/transliterator": "~1.0", + "ext-mbstring": "*", + "php": ">=5.3.3", + "symfony/class-loader": "~2.1", + "symfony/config": "~2.3", + "symfony/console": "~2.1", + "symfony/dependency-injection": "~2.1", + "symfony/event-dispatcher": "~2.1", + "symfony/translation": "~2.3", + "symfony/yaml": "~2.1" + }, + "require-dev": { + "phpspec/prophecy-phpunit": "~1.0", + "phpunit/phpunit": "~4.0", + "symfony/process": "~2.1" + }, + "suggest": { + "behat/mink-extension": "for integration with Mink testing framework", + "behat/symfony2-extension": "for integration with Symfony2 web framework", + "behat/yii-extension": "for integration with Yii web framework" + }, + "bin": [ + "bin/behat" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Behat\\Behat": "src/", + "Behat\\Testwork": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + } + ], + "description": "Scenario-oriented BDD framework for PHP 5.3", + "homepage": "http://behat.org/", + "keywords": [ + "Agile", + "BDD", + "ScenarioBDD", + "Scrum", + "StoryBDD", + "User story", + "business", + "development", + "documentation", + "examples", + "symfony", + "testing" + ], + "time": "2015-02-22 14:10:33" + }, + { + "name": "behat/gherkin", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/Behat/Gherkin.git", + "reference": "6b3f8cf3560dc4909c4cddd4f1af3e1f6e9d80af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Behat/Gherkin/zipball/6b3f8cf3560dc4909c4cddd4f1af3e1f6e9d80af", + "reference": "6b3f8cf3560dc4909c4cddd4f1af3e1f6e9d80af", + "shasum": "" + }, + "require": { + "php": ">=5.3.1" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "symfony/yaml": "~2.1" + }, + "suggest": { + "symfony/yaml": "If you want to parse features, represented in YAML files" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.4-dev" + } + }, + "autoload": { + "psr-0": { + "Behat\\Gherkin": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + } + ], + "description": "Gherkin DSL parser for PHP 5.3", + "homepage": "http://behat.org/", + "keywords": [ + "BDD", + "Behat", + "Cucumber", + "DSL", + "gherkin", + "parser" + ], + "time": "2015-09-29 13:41:19" + }, + { + "name": "behat/mink", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/minkphp/Mink.git", + "reference": "6c129030ec2cc029905cf969a56ca8f087b2dfdf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/minkphp/Mink/zipball/6c129030ec2cc029905cf969a56ca8f087b2dfdf", + "reference": "6c129030ec2cc029905cf969a56ca8f087b2dfdf", + "shasum": "" + }, + "require": { + "php": ">=5.3.1", + "symfony/css-selector": "~2.1" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "suggest": { + "behat/mink-browserkit-driver": "extremely fast headless driver for Symfony\\Kernel-based apps (Sf2, Silex)", + "behat/mink-goutte-driver": "fast headless driver for any app without JS emulation", + "behat/mink-selenium2-driver": "slow, but JS-enabled driver for any app (requires Selenium2)", + "behat/mink-zombie-driver": "fast and JS-enabled headless driver for any app (requires node.js)" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Mink\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + } + ], + "description": "Browser controller/emulator abstraction for PHP", + "homepage": "http://mink.behat.org/", + "keywords": [ + "browser", + "testing", + "web" + ], + "time": "2015-09-20 20:24:03" + }, + { + "name": "behat/mink-browserkit-driver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/minkphp/MinkBrowserKitDriver.git", + "reference": "da47df1593dac132f04d24e7277ef40d33d9f201" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/minkphp/MinkBrowserKitDriver/zipball/da47df1593dac132f04d24e7277ef40d33d9f201", + "reference": "da47df1593dac132f04d24e7277ef40d33d9f201", + "shasum": "" + }, + "require": { + "behat/mink": "~1.7@dev", + "php": ">=5.3.6", + "symfony/browser-kit": "~2.3", + "symfony/dom-crawler": "~2.3" + }, + "require-dev": { + "silex/silex": "~1.2", + "symfony/phpunit-bridge": "~2.7" + }, + "type": "mink-driver", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Mink\\Driver\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + } + ], + "description": "Symfony2 BrowserKit driver for Mink framework", + "homepage": "http://mink.behat.org/", + "keywords": [ + "Mink", + "Symfony2", + "browser", + "testing" + ], + "time": "2015-09-21 20:56:13" + }, + { + "name": "behat/mink-extension", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/Behat/MinkExtension.git", + "reference": "06e2b99d92e175719d7e841d5be16b7df1a233c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Behat/MinkExtension/zipball/06e2b99d92e175719d7e841d5be16b7df1a233c5", + "reference": "06e2b99d92e175719d7e841d5be16b7df1a233c5", + "shasum": "" + }, + "require": { + "behat/behat": "~3.0,>=3.0.5", + "behat/mink": "~1.5", + "php": ">=5.3.2", + "symfony/config": "~2.2" + }, + "require-dev": { + "behat/mink-goutte-driver": "~1.1", + "phpspec/phpspec": "~2.0" + }, + "type": "behat-extension", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Behat\\MinkExtension": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christophe Coevoet", + "email": "stof@notk.org" + }, + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com" + } + ], + "description": "Mink extension for Behat", + "homepage": "http://extensions.behat.org/mink", + "keywords": [ + "browser", + "gui", + "test", + "web" + ], + "time": "2015-09-29 17:42:41" + }, + { + "name": "behat/mink-goutte-driver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/minkphp/MinkGoutteDriver.git", + "reference": "c8e254f127d6f2242b994afd4339fb62d471df3f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/minkphp/MinkGoutteDriver/zipball/c8e254f127d6f2242b994afd4339fb62d471df3f", + "reference": "c8e254f127d6f2242b994afd4339fb62d471df3f", + "shasum": "" + }, + "require": { + "behat/mink": "~1.6@dev", + "behat/mink-browserkit-driver": "~1.2@dev", + "fabpot/goutte": "~1.0.4|~2.0|~3.1", + "php": ">=5.3.1" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "type": "mink-driver", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Mink\\Driver\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + } + ], + "description": "Goutte driver for Mink framework", + "homepage": "http://mink.behat.org/", + "keywords": [ + "browser", + "goutte", + "headless", + "testing" + ], + "time": "2015-09-21 21:31:11" + }, + { + "name": "behat/mink-selenium2-driver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/minkphp/MinkSelenium2Driver.git", + "reference": "bedbf1999c7ba1bc6921b30ee2eadf383e7ff5c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/minkphp/MinkSelenium2Driver/zipball/bedbf1999c7ba1bc6921b30ee2eadf383e7ff5c9", + "reference": "bedbf1999c7ba1bc6921b30ee2eadf383e7ff5c9", + "shasum": "" + }, + "require": { + "behat/mink": "~1.7@dev", + "instaclick/php-webdriver": "~1.1", + "php": ">=5.3.1" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "type": "mink-driver", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Mink\\Driver\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Pete Otaqui", + "email": "pete@otaqui.com", + "homepage": "https://github.com/pete-otaqui" + } + ], + "description": "Selenium2 (WebDriver) driver for Mink framework", + "homepage": "http://mink.behat.org/", + "keywords": [ + "ajax", + "browser", + "javascript", + "selenium", + "testing", + "webdriver" + ], + "time": "2015-09-21 21:02:54" + }, + { + "name": "behat/transliterator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/Behat/Transliterator.git", + "reference": "868e05be3a9f25ba6424c2dd4849567f50715003" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Behat/Transliterator/zipball/868e05be3a9f25ba6424c2dd4849567f50715003", + "reference": "868e05be3a9f25ba6424c2dd4849567f50715003", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-0": { + "Behat\\Transliterator": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Artistic-1.0" + ], + "description": "String transliterator", + "keywords": [ + "i18n", + "slug", + "transliterator" + ], + "time": "2015-09-28 16:26:35" + }, + { + "name": "fabpot/goutte", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/FriendsOfPHP/Goutte.git", + "reference": "3cbc6ed222422a28400e470050f14928a153207e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FriendsOfPHP/Goutte/zipball/3cbc6ed222422a28400e470050f14928a153207e", + "reference": "3cbc6ed222422a28400e470050f14928a153207e", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.0", + "php": ">=5.5.0", + "symfony/browser-kit": "~2.1|~3.0", + "symfony/css-selector": "~2.1|~3.0", + "symfony/dom-crawler": "~2.1|~3.0" + }, + "type": "application", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Goutte\\": "Goutte" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A simple PHP Web Scraper", + "homepage": "https://github.com/FriendsOfPHP/Goutte", + "keywords": [ + "scraper" + ], + "time": "2015-11-05 12:58:44" + }, + { + "name": "guzzlehttp/guzzle", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "a21d3ccb7ea39a5256079adaa7f0901fde02a5b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/a21d3ccb7ea39a5256079adaa7f0901fde02a5b0", + "reference": "a21d3ccb7ea39a5256079adaa7f0901fde02a5b0", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "~1.0", + "guzzlehttp/psr7": "~1.1", + "php": ">=5.5.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0", + "psr/log": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.1-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2015-11-15 09:29:07" + }, + { + "name": "guzzlehttp/promises", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/b1e1c0d55f8083c71eda2c28c12a228d708294ea", + "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2015-10-15 22:28:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "4d0bdbe1206df7440219ce14c972aa57cc5e4982" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/4d0bdbe1206df7440219ce14c972aa57cc5e4982", + "reference": "4d0bdbe1206df7440219ce14c972aa57cc5e4982", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "PSR-7 message implementation", + "keywords": [ + "http", + "message", + "stream", + "uri" + ], + "time": "2015-11-03 01:34:55" + }, + { + "name": "instaclick/php-webdriver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/instaclick/php-webdriver.git", + "reference": "bb2bc96d91e6f8c3312a9f6899bb2370f489a638" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/instaclick/php-webdriver/zipball/bb2bc96d91e6f8c3312a9f6899bb2370f489a638", + "reference": "bb2bc96d91e6f8c3312a9f6899bb2370f489a638", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "php": ">=5.3.2" + }, + "require-dev": { + "satooshi/php-coveralls": "dev-master" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "WebDriver": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Justin Bishop", + "email": "jubishop@gmail.com", + "role": "Developer" + }, + { + "name": "Anthon Pang", + "email": "apang@softwaredevelopment.ca", + "role": "Fork Maintainer" + } + ], + "description": "PHP WebDriver for Selenium 2", + "homepage": "http://instaclick.com/", + "keywords": [ + "browser", + "selenium", + "webdriver", + "webtest" + ], + "time": "2015-07-03 18:24:04" + }, + { + "name": "psr/http-message", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2015-05-04 20:22:00" + }, + { + "name": "symfony/browser-kit", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/browser-kit.git", + "reference": "589f32fe4f43155ea303d505171634c45f15e876" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/browser-kit/zipball/589f32fe4f43155ea303d505171634c45f15e876", + "reference": "589f32fe4f43155ea303d505171634c45f15e876", + "shasum": "" + }, + "require": { + "php": ">=5.3.9", + "symfony/dom-crawler": "~2.0,>=2.0.5|~3.0.0" + }, + "require-dev": { + "symfony/css-selector": "~2.0,>=2.0.5|~3.0.0", + "symfony/process": "~2.3.34|~2.7,>=2.7.6|~3.0.0" + }, + "suggest": { + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\BrowserKit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony BrowserKit Component", + "homepage": "https://symfony.com", + "time": "2015-11-02 20:29:24" + }, + { + "name": "symfony/class-loader", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/class-loader.git", + "reference": "0dcd6ee72b76f730c12484eb489f2171029201e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/class-loader/zipball/0dcd6ee72b76f730c12484eb489f2171029201e5", + "reference": "0dcd6ee72b76f730c12484eb489f2171029201e5", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "symfony/finder": "~2.0,>=2.0.5|~3.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\ClassLoader\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony ClassLoader Component", + "homepage": "https://symfony.com", + "time": "2015-10-30 20:15:42" + }, + { + "name": "symfony/config", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/config.git", + "reference": "f042c9257b2bdebda285f7a5c089b9348bcb6f3d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/config/zipball/f042c9257b2bdebda285f7a5c089b9348bcb6f3d", + "reference": "f042c9257b2bdebda285f7a5c089b9348bcb6f3d", + "shasum": "" + }, + "require": { + "php": ">=5.3.9", + "symfony/filesystem": "~2.3|~3.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Config\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Config Component", + "homepage": "https://symfony.com", + "time": "2015-11-02 20:29:24" + }, + { + "name": "symfony/console", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "74bf9202a531cc6942454eb9e2dd1e13bde34a31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/74bf9202a531cc6942454eb9e2dd1e13bde34a31", + "reference": "74bf9202a531cc6942454eb9e2dd1e13bde34a31", + "shasum": "" + }, + "require": { + "php": ">=5.3.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/event-dispatcher": "~2.1|~3.0.0", + "symfony/process": "~2.1|~3.0.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2015-11-04 00:47:19" + }, + { + "name": "symfony/css-selector", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/css-selector.git", + "reference": "b600fec37c0efca08046d481d79e7eabc07108ff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/b600fec37c0efca08046d481d79e7eabc07108ff", + "reference": "b600fec37c0efca08046d481d79e7eabc07108ff", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\CssSelector\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony CssSelector Component", + "homepage": "https://symfony.com", + "time": "2015-10-30 20:15:42" + }, + { + "name": "symfony/dependency-injection", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/dependency-injection.git", + "reference": "eae068f6bbae4b10f096d6b3eb90953941a9c0e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/eae068f6bbae4b10f096d6b3eb90953941a9c0e4", + "reference": "eae068f6bbae4b10f096d6b3eb90953941a9c0e4", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "conflict": { + "symfony/expression-language": "<2.6" + }, + "require-dev": { + "symfony/config": "~2.2|~3.0.0", + "symfony/expression-language": "~2.6|~3.0.0", + "symfony/yaml": "~2.1|~3.0.0" + }, + "suggest": { + "symfony/config": "", + "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DependencyInjection\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DependencyInjection Component", + "homepage": "https://symfony.com", + "time": "2015-11-07 08:30:54" + }, + { + "name": "symfony/dom-crawler", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/dom-crawler.git", + "reference": "740c98235f5b6e2b0b13df2fb97c7a1c7d1a18fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/740c98235f5b6e2b0b13df2fb97c7a1c7d1a18fc", + "reference": "740c98235f5b6e2b0b13df2fb97c7a1c7d1a18fc", + "shasum": "" + }, + "require": { + "php": ">=5.3.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "symfony/css-selector": "~2.8|~3.0.0" + }, + "suggest": { + "symfony/css-selector": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DomCrawler\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "https://symfony.com", + "time": "2015-11-02 20:29:39" + }, + { + "name": "symfony/event-dispatcher", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "a5eb815363c0388e83247e7e9853e5dbc14999cc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/a5eb815363c0388e83247e7e9853e5dbc14999cc", + "reference": "a5eb815363c0388e83247e7e9853e5dbc14999cc", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.0,>=2.0.5|~3.0.0", + "symfony/dependency-injection": "~2.6|~3.0.0", + "symfony/expression-language": "~2.6|~3.0.0", + "symfony/stopwatch": "~2.3|~3.0.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2015-10-30 20:15:42" + }, + { + "name": "symfony/filesystem", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "232aa96494f0b44d25c8b7a11163c742e568c1a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/232aa96494f0b44d25c8b7a11163c742e568c1a7", + "reference": "232aa96494f0b44d25c8b7a11163c742e568c1a7", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "https://symfony.com", + "time": "2015-11-10 13:34:42" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "0b6a8940385311a24e060ec1fe35680e17c74497" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0b6a8940385311a24e060ec1fe35680e17c74497", + "reference": "0b6a8940385311a24e060ec1fe35680e17c74497", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2015-11-04 20:28:58" + }, + { + "name": "symfony/translation", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "98b89a9091dde2af772d4c74a09447d317d1bdf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/98b89a9091dde2af772d4c74a09447d317d1bdf4", + "reference": "98b89a9091dde2af772d4c74a09447d317d1bdf4", + "shasum": "" + }, + "require": { + "php": ">=5.3.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/config": "<2.7" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8", + "symfony/intl": "~2.4|~3.0.0", + "symfony/yaml": "~2.2|~3.0.0" + }, + "suggest": { + "psr/log": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com", + "time": "2015-10-30 20:15:42" + }, + { + "name": "symfony/yaml", + "version": "2.8.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "5ff00ea2999343d42398fcb793bbfc64c92235ff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/5ff00ea2999343d42398fcb793bbfc64c92235ff", + "reference": "5ff00ea2999343d42398fcb793bbfc64c92235ff", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2015-11-05 09:04:44" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": { + "behat/behat": 0, + "behat/mink": 0 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/src/BehatTestGenerator.php b/src/BehatTestGenerator.php new file mode 100644 index 0000000..849fb52 --- /dev/null +++ b/src/BehatTestGenerator.php @@ -0,0 +1,108 @@ +seleniumIdeTestData = $seleniumFileParser->parse(); + $this->seleniumRCToBehatMinkFormatter = new SeleniumRCToBehatMinkFormatter( + $this->seleniumIdeTestData + ); + } + + protected function getTestName() + { + return $this->seleniumIdeTestData['test_name']; + } + + protected function getTestMethodName() + { + return str_replace(' ', '', ucwords($this->seleniumIdeTestData['test_name'])); + } + + protected function getTestMethodContent() + { + return $this->seleniumRCToBehatMinkFormattr->format(); + } + + protected function getTestFeatureFileName() + { + return str_replace(' ', '_', $this->seleniumIdeTestData['test_name']).'.feature'; + } + + protected function createFileStructure() + { + $filename = 'features/bootstrap/'; + if (!file_exists($filename)) { + mkdir($filename, 0777,true); + } + } + + protected function generateContextFile() + { + $fileName = 'features/bootstrap/FeatureContext.php'; + $data = <<BaseUrl = \$parameters['base_url']; + } + + /** + * @Given /^{$this->getTestName()}$/ + */ + public function {$this->getTestMethodName()}() + { + {$this->seleniumRCToBehatMinkFormatter->format()} + } +} +FILE; + file_put_contents($fileName, $data); + } + + protected function generateFeatureFile() + { + $fileName = 'features/' . $this->getTestFeatureFileName(); + $data = <<getTestName()} + Feature description + + @javascript + Scenario: {$this->getTestName()} + Given {$this->getTestName()} +FILE; + file_put_contents($fileName, $data); + } + + public function generate() + { + $this->createFileStructure(); + $this->generateContextFile(); + $this->generateFeatureFile(); + } +} diff --git a/src/CommandFactory.php b/src/CommandFactory.php new file mode 100644 index 0000000..cd3af3b --- /dev/null +++ b/src/CommandFactory.php @@ -0,0 +1,214 @@ +command = $command; + } + abstract public function toBehatMink(); + protected function getElementByTarget($target) + { + $result = ''; + if (!self::$isPageCreated) { + $result = "\t\$page = \$this->getSession()->getPage();\n"; + self::$isPageCreated = true; + } + if (preg_match('/^(id|css|link|name|xpath)/', $target, $out)) { + $selectorType = $out[0]; + $selector = str_replace("'", "\'", substr($target, strpos($target, '=') + 1)); + if ($selectorType === 'id') { + return $result . "\t\$element = \$page->findById('{$selector}');\n"; + } + if ($selectorType === 'css') { + return $result . "\t\$element = \$page->find('css', '{$selector}');\n"; + } + if ($selectorType === 'link') { + return $result . "\t\$escapedValue = \$this->getSession()->getSelectorsHandler()->xpathLiteral('{$selector}');\n" + . "\t\$element = \$page->find('named', array('link', \$escapedValue));\n"; + } + if ($selectorType === 'name') { + return $result . "\t\$escapedValue = \$this->getSession()->getSelectorsHandler()->xpathLiteral('{$selector}');\n" + . "\t\$element = \$page->find('named', array('id_or_name', \$escapedValue));\n"; + } + if ($selectorType === 'xpath') { + return $result . "\t\$element = \$page->find('xpath', '{$selector}');\n"; + } + } + if (strpos($target, 'document.') === 0) { + return "\t\$element = \$this->getSession()->evaluateScript('{$target}');\n"; + } + if (strpos($target, '//') === 0) { + return $result . "\t\$element = \$page->find('xpath', \"{$target}\");\n"; + } + return $result . "\t\$element = \$page->fileById('{$target}');\n"; + } +} + +class Open extends BaseCommand +{ + public function toBehatMink() + { + return "\t\$this->getSession()->visit(\$this->BaseUrl . \"{$this->command['target']}\");\n\n"; + } +} + +//class Type extends BaseCommand +//{ +// public function toBehatMink() +// { +// $result = $this->getElementByTarget($this->command['target']) +//// . "\t\$element->sendKeys('{$this->command['value']}');\n"; +//// . "\t\$element->setValue();\n" +// . "\t\$element->focus();\n"; +// $valueAsArray = str_split($this->command['value']); +// foreach ($valueAsArray as $inputChar) { +// $asciiCodeOfInputChar = ord($inputChar); +// $jsToEvaluate = "keyboardEvent = document.createEvent('KeyboardEvent'); +//initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? 'initKeyboardEvent' : 'initKeyEvent'; +//keyboardEvent[initMethod]( +// 'keypress', // event type : keydown, keyup, keypress +// true, // bubbles +// true, // cancelable +// window, // viewArg: should be window +// false, // ctrlKeyArg +// false, // altKeyArg +// false, // shiftKeyArg +// false, // metaKeyArg +// {$asciiCodeOfInputChar}, // keyCodeArg : unsigned long the virtual key code, else 0 +// 0 // charCodeArgs : unsigned long the Unicode character associated with the depressed key, else 0 +//); +//document.dispatchEvent(keyboardEvent);"; +// $result .= "\t\$this->getSession()->evaluateScript(\"{$jsToEvaluate}\");\n"; +// } +// return $result; +// } +//} + +class Type extends BaseCommand +{ + public function toBehatMink() + { + return $this->getElementByTarget($this->command['target']). + "\t\$element->setValue('{$this->command['value']}');\n\n"; + } +} + +class TypeAndWait extends BaseCommand +{ + public function toBehatMink() + { + return $this->getElementByTarget($this->command['target']). + "\t\$element->setValue('{$this->command['value']}');\n" + . "\t\$this->getSession()->wait(5000);\n\n"; + } +} + +class Click extends BaseCommand +{ + public function toBehatMink() + { + return $this->getElementByTarget($this->command['target']). + "\t\$element->click();\n\n"; + } +} + +class ClickAndWait extends BaseCommand +{ + public function toBehatMink() + { + return $this->getElementByTarget($this->command['target']) + ."\t\$element->click();\n" + . "\t\$this->getSession()->wait(5000);\n\n"; + } +} + +class Select extends BaseCommand +{ + public function toBehatMink() + { + $optionValueOrText = substr( + $this->command['value'], + strpos($this->command['value'], '=') + 1 + ); + return $this->getElementByTarget($this->command['target']) + . "\t\$element->selectOption('{$optionValueOrText}');\n\n"; + } +} + +class SelectAndWait extends BaseCommand +{ + public function toBehatMink() + { + $optionValueOrText = substr( + $this->command['value'], + strpos($this->command['value'], '=') + 1 + ); + return $this->getElementByTarget($this->command['target']) + . "\t\$element->selectOption('{$optionValueOrText}');\n" + . "\t\$this->getSession()->wait(5000);\n\n"; + } +} + +class SendKeys extends BaseCommand +{ + public function toBehatMink() + { + $selectorType = strstr($this->command['target'], '=', true); + $selector = substr( + $this->command['target'], + strpos($this->command['target'], '=') + 1 + ); + if ($selectorType === 'id' || $selectorType === 'css') { + return "\t\$this->getSession()->fillField('{$selector}', " + . "'{$this->command['value']}');\n\n"; + } + } +} + +class WaitForElementPresent extends BaseCommand +{ + public function toBehatMink() + { + $selectorType = strstr($this->command['target'], '=', true); + $selector = substr( + $this->command['target'], + strpos($this->command['target'], '=') + 1 + ); + $selector = str_replace('"','\"' , $selector); + $selector = str_replace("'","\'" , $selector); + if ($selectorType === 'id' || $selectorType === 'css') { + return "\t\$this->getSession()->wait(5000, 'document.getElementById" + . "(\"{$selector}\")');\n\n"; + } + } +} diff --git a/src/SeleniumFileParser.php b/src/SeleniumFileParser.php new file mode 100644 index 0000000..f5ed37d --- /dev/null +++ b/src/SeleniumFileParser.php @@ -0,0 +1,75 @@ +filePath = $filePath; + $this->xml = new DOMDocument('1.0', 'UTF-8'); + $this->xml->load($filePath); + } + + protected function getTestName() + { + $titleElements = $this->xml->getElementsByTagName('title'); + if ($titleElements->length == 0) { + throw new Exception("Wrong Selenium Ide file format.\n Test name absent.\n"); + } + return $titleElements->item(0)->nodeValue; + } + + protected function getBaseUrl() + { + $linkElements = $this->xml->getElementsByTagName('link'); + if ($linkElements->length == 0) { + throw new Exception("Wrong Selenium Ide file format.\n Base url absent.\n"); + } + return $linkElements->item(0)->getAttribute('href'); + } + + protected function getCommandsList() + { + $tableBodyElement = $this->xml->getElementsByTagName('tbody')->item(0); + if ($tableBodyElement == null) { + throw new Exception("Wrong Selenium Ide file format.\n Commands list absent.\n"); + } + $trElements = $tableBodyElement->getElementsByTagName('tr'); + if ($trElements->length == 0) { + throw new Exception("Wrong Selenium Ide file format.\n Commands list absent.\n"); + } + $commandsList = []; + for ($i = 0; $i < $trElements->length; ++$i) { + $tdElements = $trElements->item($i)->getElementsByTagName('td'); + if ($tdElements->length < 3) { + throw new Exception("Wrong Selenium Ide file format.\n Command isn't full."); + } + $commandsList[] = [ + 'name' => $tdElements->item(0)->nodeValue, + 'target' => $tdElements->item(1)->nodeValue, + 'value' => $tdElements->item(2)->nodeValue + ]; + } + return $commandsList; + } + + public function parse() + { + return [ + 'test_name' => $this->getTestName(), + 'base_url' => $this->getBaseUrl(), + 'commands_list' => $this->getCommandsList() + ]; + } +} diff --git a/src/SeleniumRCToBehatMinkFormatter.php b/src/SeleniumRCToBehatMinkFormatter.php new file mode 100644 index 0000000..da50ec3 --- /dev/null +++ b/src/SeleniumRCToBehatMinkFormatter.php @@ -0,0 +1,34 @@ +seleniumIdeTestData = $seleniumIdeTestData; + } + + protected function getCommandByName($command) + { + return CommandFactory::build($command['name'], $command); + } + + public function format() + { + $minkContext = ''; + $commandsList = $this->seleniumIdeTestData['commands_list']; + foreach ($commandsList as $command) { + $commandObj = $this->getCommandByName($command); + $minkContext .= $commandObj->toBehatMink(); + } + return $minkContext; + } +} diff --git a/test.php b/test.php new file mode 100644 index 0000000..8185afe --- /dev/null +++ b/test.php @@ -0,0 +1,15 @@ +generate(); \ No newline at end of file