{"id":1059,"date":"2017-06-02T10:51:39","date_gmt":"2017-06-02T17:51:39","guid":{"rendered":"http:\/\/www.keganv.com\/?p=1059"},"modified":"2017-06-02T10:51:39","modified_gmt":"2017-06-02T17:51:39","slug":"finding-dom-elements-codeception-acceptance-functional-testing","status":"publish","type":"post","link":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/","title":{"rendered":"Finding DOM Elements For Codeception Acceptance &#038; Functional Testing"},"content":{"rendered":"<p>When writing functional and acceptance tests for your PHP application I highly recommend <a href=\"http:\/\/codeception.com\/\" target=\"_blank\">Codeception<\/a>. The platform is incredible to get up and running for your test automation needs. That being said, I am far from an expert, but like everything, the more I use it, the more I am learning about it.<\/p>\n<p>I wanted to create this article in a fashion that will allow me to periodically update it with new methods and findings I learn about or create in order to keep track of them, and share with you!<\/p>\n<h3>Finding &#038;amp Filling In Dynamically Named &amp; Hidden Form Fields<\/h3>\n<p>If you have an application where the form fields&#8217; id and name attributes can change on each page load, writing a method using the xpath like <code>$I->fillField('\/\/input[@name=\"some_form_field\"]')<\/code> is not going to work. One page load the <code>name<\/code> attribute might be &#8220;some_form_field_12345&#8221; and the next page load it might be &#8220;some_form_field_54321&#8221;. That&#8217;s where <code>$I->executeJS()<\/code> comes in very handy. Now you can find and fill out the field using this method in an example shown below.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$I-&gt;executeJS('$(\\'input&#x5B;name*=&quot;some_form_field&quot;]\\').val(&quot;Your Value Here&quot;)');\r\n<\/pre>\n<p>To make this even better, I want to make it reusable, so I will add a custom method to my helper class.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n    \/**\r\n     * @param $selector\r\n     * @param $value\r\n     * @return mixed\r\n     *\/\r\n    public function fillInDynamicField($selector, $value)\r\n    {\r\n        $webDriver = $this-&gt;getModule('WebDriver');\r\n\r\n        return $webDriver-&gt;executeJS('$(' . $selector . ').val(' . $value . ')');\r\n    }\r\n<\/pre>\n<p>Now you can use it in all your tests like below.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">$I-&gt;fillInDynamicField('\\'input&#x5B;name*=&quot;clientSinceDate&quot;]\\'', &quot;06\/01\/2017&quot;);<\/pre>\n","protected":false},"excerpt":{"rendered":"When writing functional and acceptance tests for your PHP application I highly recommend Codeception. The platform is incredible to get up and running for your test automation needs. That being said, I am far from an expert, but like everything, the more I use it, the more I am learning about it. I wanted to &#8230; <br\/> <a class=\"view-article btn btn-primary flip pull-left\" href=\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/\"><span>View Article<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1059","post","type-post","status-publish","format-standard","hentry","category-coding-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Finding DOM Elements For Codeception Acceptance &amp; Functional Testing | KeganV<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Finding DOM Elements For Codeception Acceptance &amp; Functional Testing | KeganV\" \/>\n<meta property=\"og:description\" content=\"When writing functional and acceptance tests for your PHP application I highly recommend Codeception. The platform is incredible to get up and running for your test automation needs. That being said, I am far from an expert, but like everything, the more I use it, the more I am learning about it. I wanted to ... View Article\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/\" \/>\n<meta property=\"og:site_name\" content=\"KeganV\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-02T17:51:39+00:00\" \/>\n<meta name=\"author\" content=\"Kegan V.\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kegan V.\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/\"},\"author\":{\"name\":\"Kegan V.\",\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\"},\"headline\":\"Finding DOM Elements For Codeception Acceptance &#038; Functional Testing\",\"datePublished\":\"2017-06-02T17:51:39+00:00\",\"dateModified\":\"2017-06-02T17:51:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/\"},\"wordCount\":282,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\"},\"articleSection\":[\"Coding &amp; Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/\",\"url\":\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/\",\"name\":\"Finding DOM Elements For Codeception Acceptance & Functional Testing | KeganV\",\"isPartOf\":{\"@id\":\"https:\/\/www.keganv.com\/#website\"},\"datePublished\":\"2017-06-02T17:51:39+00:00\",\"dateModified\":\"2017-06-02T17:51:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.keganv.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Finding DOM Elements For Codeception Acceptance &#038; Functional Testing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.keganv.com\/#website\",\"url\":\"https:\/\/www.keganv.com\/\",\"name\":\"KeganV\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.keganv.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\",\"name\":\"Kegan V.\",\"logo\":{\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/www.keganv.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Finding DOM Elements For Codeception Acceptance & Functional Testing | KeganV","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/","og_locale":"en_US","og_type":"article","og_title":"Finding DOM Elements For Codeception Acceptance & Functional Testing | KeganV","og_description":"When writing functional and acceptance tests for your PHP application I highly recommend Codeception. The platform is incredible to get up and running for your test automation needs. That being said, I am far from an expert, but like everything, the more I use it, the more I am learning about it. I wanted to ... View Article","og_url":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/","og_site_name":"KeganV","article_published_time":"2017-06-02T17:51:39+00:00","author":"Kegan V.","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kegan V.","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/#article","isPartOf":{"@id":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/"},"author":{"name":"Kegan V.","@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276"},"headline":"Finding DOM Elements For Codeception Acceptance &#038; Functional Testing","datePublished":"2017-06-02T17:51:39+00:00","dateModified":"2017-06-02T17:51:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/"},"wordCount":282,"commentCount":0,"publisher":{"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276"},"articleSection":["Coding &amp; Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/","url":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/","name":"Finding DOM Elements For Codeception Acceptance & Functional Testing | KeganV","isPartOf":{"@id":"https:\/\/www.keganv.com\/#website"},"datePublished":"2017-06-02T17:51:39+00:00","dateModified":"2017-06-02T17:51:39+00:00","breadcrumb":{"@id":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.keganv.com\/finding-dom-elements-codeception-acceptance-functional-testing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.keganv.com\/"},{"@type":"ListItem","position":2,"name":"Finding DOM Elements For Codeception Acceptance &#038; Functional Testing"}]},{"@type":"WebSite","@id":"https:\/\/www.keganv.com\/#website","url":"https:\/\/www.keganv.com\/","name":"KeganV","description":"","publisher":{"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.keganv.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276","name":"Kegan V.","logo":{"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/www.keganv.com"]}]}},"_links":{"self":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts\/1059"}],"collection":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/comments?post=1059"}],"version-history":[{"count":7,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts\/1059\/revisions"}],"predecessor-version":[{"id":1066,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts\/1059\/revisions\/1066"}],"wp:attachment":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/media?parent=1059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/categories?post=1059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/tags?post=1059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}