{"id":145,"date":"2018-10-22T10:17:34","date_gmt":"2018-10-22T10:17:34","guid":{"rendered":"https:\/\/citrusleaf.in\/blog\/?p=145"},"modified":"2018-10-22T10:17:42","modified_gmt":"2018-10-22T10:17:42","slug":"acceptance-testing-with-codeception","status":"publish","type":"post","link":"https:\/\/citrusleaf.in\/blog\/acceptance-testing-with-codeception\/","title":{"rendered":"Acceptance Testing with CodeCeption"},"content":{"rendered":"<p><strong>Introduction<\/strong><\/p>\n<p>At CitrusLeaf, we always believe that testing is as important as development in a software&#8217;s lifecycle. That&#8217;s why we start every project by writing test-cases before we start its development. As soon each module gets completed, we start writing it&#8217;s unit test cases using CodeCeption. More recently, we upped our game by writing Acceptance Test Cases using CodeCeption. Acceptance or user acceptance testing (UAT) is a type of testing which ensures that the application requirements meet business needs. Although a time-consuming process, it increases the overall quality of the software and makes sure that it&#8217;s behaving like it should in real-world.<\/p>\n<p><strong>Meet CodeCeption<br \/><\/strong><\/p>\n<p>It is a simple, efficient yet powerful testing framework which can perform API, Unit, Functional and Acceptance testing. Based on the popular unit testing tool PHPUnit, it enables user-centric testing and\u00a0Behavior Driven Development. Codeception collects and shares best practices and solutions for testing PHP web applications. With a flexible set of included modules, tests are easy to write, easy to use and easy to maintain. Codeception encourages developers and QA engineers to concentrate on testing and not on building the test suite.<\/p>\n<p><strong>Requirements<br \/><\/strong><\/p>\n<ul>\n<li>PHP 5.4+<\/li>\n<li>cURL with it&#8217;s PHP extension<\/li>\n<li>Composer for dependency management<\/li>\n<\/ul>\n<p><strong>Additional Requisite<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/chromedriver.chromium.org\/downloads\">ChromeDriver<\/a><\/li>\n<li><a href=\"http:\/\/docs.seleniumhq.org\/download\/\">Selenium Standalone Server<\/a><\/li>\n<\/ul>\n<p><strong>Installation<\/strong><\/p>\n<p>You can install CodeCeption either by using Git, Composer or by installing the PHAR globally. Following are the installation steps using Git:<\/p>\n<p>Composer installation-<\/p>\n<ul>\n<li>Run the following command in a new directory, after installing Composer (globally)-<code><br \/>\n$composer require codeception\/codeception --dev<\/code><\/li>\n<li>Initialize the testing environment-<\/li>\n<\/ul>\n<p style=\"padding-left: 30px;\">\u00a0<code>$php vendor\/bin\/codecept bootstrap<code><\/code><\/code><\/p>\n<p style=\"padding-left: 30px;\">or if installed globally by composer<\/p>\n<p style=\"padding-left: 30px;\"><code>$codecept bootstrap<\/code><\/p>\n<p>This command will generate the configuration file \u2018codeception.yml\u2019 and default test-suits (acceptance, unit and functional test-cases folder).<\/p>\n<p><strong>Commands<\/strong><\/p>\n<p>Before starting with CodeCeption, let\u2019s have a quick glance at some of the useful commands-<\/p>\n<ul>\n<li>$codecept run &#8211; Runs all the tests which include acceptance, unit and functional test-cases.<\/li>\n<li>$codecept run acceptance &#8211;steps &#8211; Runs all acceptance tests and print step by step execution.<\/li>\n<li>$codecept run acceptance MyCept &#8211; Runs only MyCept Acceptance test<\/li>\n<li>$codecept run tests\/acceptance\/MyCest.php:^logint$ &#8211;debug &#8211; This will run only \u2018login\u2019 method of \u2018MyCest\u2019 class.<\/li>\n<li>$codecept generate:cept suite Login &#8211; Generates acceptance test class for Login test case<\/li>\n<\/ul>\n<p>Further, CodeCeption&#8217;s test methods are divided into 4 groups:<\/p>\n<ul>\n<li>Interaction with page: fillField(), selectOption(), submitForm(), click() etc.<\/li>\n<li>Assertions. see(), seeElement(), seeInCurrentUrl(), seeCheckboxIsChecked() etc. \u00a0You can add a suffix to all these methods and use it when you need it.<\/li>\n<li>Cookie methods: dontSeeCookie().<\/li>\n<li>Comment and description of test scenarios: \u00a0wantTo()<\/li>\n<\/ul>\n<p><strong>Writing acceptance test<\/strong><\/p>\n<ul>\n<li>First, let&#8217;s start the selenium server with Chrome Drive with the command-<br \/><code>$java -Dwebdriver.chrome.driver=.\/\/chromedriver -jar.\/selenium-server-standalone-3.14.0.jar<\/code><\/li>\n<li>Open your favourite text editor and open the project&#8217;s directory.<\/li>\n<li>Edit the <b>acceptance.suite.yml <\/b>file and set the URL, and browser details. For example-<code><\/code><\/li>\n<\/ul>\n<p style=\"padding-left: 60px;\"><code>actor: AcceptanceTester<br \/>\nmodules:<br \/>\nenabled:<br \/>\n- PhpBrowser:<br \/>\nurl: http:\/\/www.example.com\/<br \/>\n- \\Helper\\Acceptance<br \/>\n<\/code><\/p>\n<ul>\n<li>Below is a simple Login Acceptance Test in PHP:<\/li>\n<\/ul>\n<p style=\"padding-left: 60px;\"><code>Class LoginCest {<br \/>\n<\/code><\/p>\n<p style=\"padding-left: 60px;\"><code>public\u00a0function login(AcceptanceTester\u00a0$I) {<br \/>\n$I-&gt;amOnPage('\/login');<br \/>\n$I-&gt;fillField('username',\u00a0'User');<br \/>\n$I-&gt;fillField('password',\u00a0'qwerty');<br \/>\n$I-&gt;click('LOGIN');<br \/>\n$I-&gt;see('Welcome, User!');<br \/>\n}<\/code><\/p>\n<p style=\"padding-left: 60px;\"><code><br \/>\n}<\/code><\/p>\n<ul>\n<li>Running the test: <code>$codecept run acceptance LoginCest<\/code><\/li>\n<\/ul>\n<p>As soon as you run the test, you&#8217;ll see the browser automatically opening http:\/\/example.com\/login, filling out the form, confirming that it sees &#8220;Welcome, User!&#8221; and exits. If there&#8217;s any failure in this assertion, the test will fail and the terminal will show the appropriate line number to fix.<\/p>\n<p>All in all, we&#8217;re are enjoying CodeCeption at CitrusLeaf. CodeCeption has made it really easy to write better software by taking up the major hard work in generating test suits.<\/p>\n<p>This marks the end of part 1 of the Codeception series of articles. More blog posts are coming up. Stay tuned!<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction At CitrusLeaf, we always believe that testing is as important as development in a software&#8217;s lifecycle. That&#8217;s why we start every project by writing test-cases before we start its development. As soon each module&hellip; <\/p>\n","protected":false},"author":2,"featured_media":152,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[14],"tags":[15,16],"class_list":["post-145","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-testing","tag-codeception","tag-testing"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/citrusleaf.in\/blog\/wp-content\/uploads\/2018\/10\/featured_image-6.png?fit=1024%2C600&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pei5Vv-2l","_links":{"self":[{"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/posts\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/comments?post=145"}],"version-history":[{"count":9,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/posts\/145\/revisions"}],"predecessor-version":[{"id":166,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/posts\/145\/revisions\/166"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/media\/152"}],"wp:attachment":[{"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/media?parent=145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/categories?post=145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/tags?post=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}