{"id":1060,"date":"2021-07-31T18:28:24","date_gmt":"2021-07-31T18:28:24","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/07\/31\/advance-cypress-interview-questions-part-3\/"},"modified":"2021-07-31T18:28:24","modified_gmt":"2021-07-31T18:28:24","slug":"advance-cypress-interview-questions-part-3","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/07\/31\/advance-cypress-interview-questions-part-3\/","title":{"rendered":"Advance Cypress Interview Questions \u2013 Part 3"},"content":{"rendered":"<p><html><body><\/p>\n<section class=\"tcb-post-content tcb-shortcode thrv_wrapper\" data-css=\"tve-u-16ec5d248bb\">\n<div class=\"tve_flt tcb-style-wrap\" id=\"tve_flt\">\n<div class=\"tve_shortcode_editor tar-main-content\" data-post-id=\"1060\" id=\"tve_editor\">\n<div class=\"thrv_wrapper tve-toc tve-elem-scroll tve-toc-expandable tcb-local-vars-root\" data-animation=\"slide\" data-animation-speed=\"fast\" data-bullet-style='{\"0\":\"tve-u-17399ffbddd\",\"1\":\"tve-u-1739a0466e5\",\"2\":\"tve-u-1739a04a2bb\"}' data-columns=\"1\" data-columns-d=\"1\" data-css=\"tve-u-17afdc5fc84\" data-ct=\"toc-60671\" data-ct-name=\"Table of Contents 03\" data-element-name=\"Table of Contents\" data-headers=\"h1,h3,h5\" data-heading-style='{\"0\":\"tve-u-17afdc5fc89\",\"1\":\"tve-u-17afdc5fc8b\",\"2\":\"tve-u-17afdc5fc8c\"}' data-highlight=\"section\" data-number-style='{\"0\":\"tve-u-17afdc5fc8a\",\"1\":\"tve-u-173dc888a58\",\"2\":\"tve-u-173dc8891dc\"}' data-numbering=\"basic\" data-state-default=\"expanded\" data-state-default-m=\"collapsed\" data-transition=\"fade\" style=\"\">\n<div class=\"thrive-colors-palette-config\" style=\"display: none !important\"><\/div>\n<div class=\"tve-toc-divider\" style=\"position: absolute; width: 0; height: 0; overflow: hidden;\">\n<div class=\"thrv_wrapper thrv-divider tve-vert-divider\" data-color-d=\"rgba(0, 0, 0, 0)\" data-css=\"tve-u-17afdc5fc85\" data-style=\"tve_sep-1\" data-thickness-d=\"1\">\n<hr class=\"tve_sep tve_sep-1\" style=\"\"\/><\/div>\n<\/div>\n<p><svg class=\"toc-icons\" style=\"position: absolute; width: 0; height: 0; overflow: hidden;\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><symbol data-id=\"icon-circle-outlined\" id=\"toc-bullet-0\" viewbox=\"0 0 512 512\"><path d=\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z\"><\/path><\/symbol><symbol data-id=\"icon-circle-outlined\" id=\"toc-bullet-1\" viewbox=\"0 0 512 512\"><path d=\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z\"><\/path><\/symbol><symbol data-id=\"icon-circle-outlined\" id=\"toc-bullet-2\" viewbox=\"0 0 512 512\"><path d=\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z\"><\/path><\/symbol><\/svg><\/p>\n<div class=\"tve-content-box-background\" data-css=\"tve-u-17afdc5fc86\" style=\"\"><\/div>\n<div class=\"thrv_wrapper tve-toc-title show-icon tcb-icon-display tve-no-dropzone tve-prevent-content-edit\" data-css=\"tve-u-17afdc5fc87\" style=\"\">\n<div class=\"tve-content-box-background\"><\/div>\n<div class=\"tve-cb\" style=\"\">\n<div class=\"tve-toc-title-icon\" data-icon-code=\"icon-arrow-circle-down-solid\" style=\"\"><svg class=\"tcb-icon\" data-id=\"icon-arrow-circle-down-solid\" data-name=\"\" viewbox=\"0 0 512 512\"><path d=\"M504 256c0 137-111 248-248 248S8 393 8 256 119 8 256 8s248 111 248 248zm-143.6-28.9L288 302.6V120c0-13.3-10.7-24-24-24h-16c-13.3 0-24 10.7-24 24v182.6l-72.4-75.5c-9.3-9.7-24.8-9.9-34.3-.4l-10.9 11c-9.4 9.4-9.4 24.6 0 33.9L239 404.3c9.4 9.4 24.6 9.4 33.9 0l132.7-132.7c9.4-9.4 9.4-24.6 0-33.9l-10.9-11c-9.5-9.5-25-9.3-34.3.4z\"><\/path><\/svg><\/div>\n<div class=\"thrv_wrapper thrv_text_element tve_no_icons\">\n<div class=\"tcb-plain-text\" style=\"\">Table of Contents<\/div>\n<\/p><\/div>\n<\/div>\n<\/div>\n<div class=\"tve-cb tve-toc-content tve-prevent-content-edit\" style=\"\">\n<div class=\"thrv_wrapper tve-toc-list tcb-no-delete tcb-no-save tcb-no-clone tve-no-dropzone\" data-css=\"tve-u-17afdc5fc88\" style=\"\">\n<div class=\"tve-content-box-background\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"tve_ct_content tve_clearfix\">\n<div class=\"ct_column\">\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137190\" jump-animation=\"smooth\">19. What is after:run event in cypress?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137191\" jump-animation=\"smooth\">20. What is cy.task() functions in Cypress?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137192\" jump-animation=\"smooth\">21. What is cy.exec() function in cypress?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137193\" jump-animation=\"smooth\">22. How can I read file in Cypress?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137194\" jump-animation=\"smooth\">23. How can I write a file in cypress?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137195\" jump-animation=\"smooth\">24. How can I run the tests \/ test suites only on specific browser without doing configuration file Changes?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137196\" jump-animation=\"smooth\">25. What are the reporters cypress supports?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137197\" jump-animation=\"smooth\">26. What is retry in cypress? How can I change the behaviour?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137198\" jump-animation=\"smooth\">27. How can I run the tests in headless mode?<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17afdc5fc8b\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1627755137199\" jump-animation=\"smooth\">28. How can I debug in Cypress?<\/a><\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv-divider tve-vert-divider\" data-color-d=\"rgba(0, 0, 0, 0)\" data-css=\"tve-u-17afdc5fc85\" data-style=\"tve_sep-1\" data-thickness-d=\"1\">\n<hr class=\"tve_sep tve_sep-1\" style=\"\"\/><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>This post is a continuation of\u00a0<a class=\"tve-froala fr-basic\" href=\"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/07\/31\/advance-cypress-interview-questions-part-2\/\" style=\"outline: none;\" target=\"_blank\">Advance Cypress Interview Questions \u2013 Part 2\u00a0<\/a>for any QA Automation interview.\u00a0<\/p>\n<div class=\"code-block code-block-2\" style=\"margin: 8px auto; text-align: center; display: block; clear: both;\">\n<p><!-- horizontal responsive 2 --><br \/>\n<ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-3231318496783163\" data-ad-format=\"auto\" data-ad-slot=\"2788468763\" data-full-width-responsive=\"true\" style=\"display:block\"><\/ins>\n<\/div>\n<h3 class=\"\" id=\"t-1627755137190\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910878\" style=\"outline: none;\">19. What is after:run event in cypress?<\/a><\/h3>\n<p><strong>after:run<\/strong> event is executed after all the test completed in cypress, This is very useful when you want to generate reports or collate\/merge the reports. This <strong>after:run<\/strong> typically used in plugin files.<\/p>\n<p><strong>Example: <\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdc753d8\" style=\"\">\n<p data-css=\"tve-u-17afdc76f63\" style=\"\">module.exports = (on, config) =&gt; {<\/p>\n<p data-css=\"tve-u-17afdc76f66\" style=\"\">on(&#8216;after:run&#8217;, async () =&gt; {<\/p>\n<p data-css=\"tve-u-17afdc76f68\" style=\"\">await exec(&#8220;npx jrm .\/cypress\/reports\/junitreport.xml .\/cypress\/reports\/junit\/*.xml&#8221;);<\/p>\n<p data-css=\"tve-u-17afdc76f69\" style=\"\">});<\/p>\n<p data-css=\"tve-u-17afdc76f6b\" style=\"\">}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1627755137191\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910879\" style=\"outline: none;\">20. What is cy.task() functions in Cypress?<\/a><\/h3>\n<p><strong>cy.task()<\/strong> is the powerful command in cypress which helps to create some set of actions outside the scope of cypress. You can execute any node commands using the task. There are lot of things we can do with the <strong>cy.task()<\/strong> below is just one example.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p><strong>Problem: cy.log()<\/strong> doesn\u2019t work if you are running cypress <strong>CLI<\/strong>, we can\u2019t use <strong>console.log()<\/strong> directly on our cypress framework to fix this issue we can take a help of task.<\/p>\n<p>Inside plugin\/index.js you can write some code like below.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdc7ce54\" style=\"\">\n<p data-css=\"tve-u-17afdc7f9b8\" style=\"\">on(&#8216;task&#8217;, {<\/p>\n<p data-css=\"tve-u-17afdc7f9ba\" style=\"\">log (message) {<\/p>\n<p data-css=\"tve-u-17afdc7f9bc\" style=\"\">console.log(message)<\/p>\n<p data-css=\"tve-u-17afdc7f9bd\" style=\"\">return null<\/p>\n<p data-css=\"tve-u-17afdc7f9be\" style=\"\">}<\/p>\n<p data-css=\"tve-u-17afdc7f9bf\" style=\"\">})<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>And once you write the above code you can call this in your script like below.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdc83159\" style=\"\">\n<p data-css=\"tve-u-17afdc86c21\" style=\"\">describe(&#8216;Demo&#8217;, () =&gt; {<\/p>\n<p data-css=\"tve-u-17afdc86c22\" style=\"\">it(&#8216;HTML DOM&#8217;, () =&gt; {<\/p>\n<p data-css=\"tve-u-17afdc86c24\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cy.task(&#8216;log&#8217;, &#8216;This will be output to the terminal&#8217;);<\/p>\n<p data-css=\"tve-u-17afdc86c25\" style=\"\">});<\/p>\n<p data-css=\"tve-u-17afdc86c26\" style=\"\">});<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1627755137192\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910880\" style=\"outline: none;\">21. What is cy.exec() function in cypress?<\/a><\/h3>\n<p><strong>cy.exec ()<\/strong> is used to run the system command.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdc90f8e\" style=\"\">\n<p data-css=\"tve-u-17afdc931cc\" style=\"\">cy.exec(&#8216;npm run build&#8217;)<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1627755137193\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910881\" style=\"outline: none;\">22. How can I read file in Cypress?<\/a><\/h3>\n<p>Cypress provides inbuild readfile capability cy.readFile() can be used for this purpose<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p><strong>Consider I have .json file like this<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdc99e5f\" style=\"\">\n<p data-css=\"tve-u-17afdc9e523\" style=\"\">{<\/p>\n<p data-css=\"tve-u-17afdc9e525\" style=\"\">\u00a0 &#8220;name&#8221;:&#8221;somename&#8221;<\/p>\n<p data-css=\"tve-u-17afdc9e527\" style=\"\">}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><strong>I can read the above file in cypress like below<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdca42a1\" style=\"\">\n<p data-css=\"tve-u-17afdca71cb\" style=\"\">cy.readFile(&#8216;data.json&#8217;).then((d)=&gt;{<\/p>\n<p data-css=\"tve-u-17afdca71cd\" style=\"\">cy.log(d.name); \/\/prints somename<\/p>\n<p data-css=\"tve-u-17afdca71cf\" style=\"\">})<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Cypress supports types if line including text, json, yaml, mp3 etc.<\/p>\n<h3 class=\"\" id=\"t-1627755137194\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910882\" style=\"outline: none;\">23. How can I write a file in cypress?<\/a><\/h3>\n<p>Cypress provides inbuild writefile capability cy.writeFile() can be used for this purpose<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdcb0deb\" style=\"\">\n<p data-css=\"tve-u-17afdcb2a81\" style=\"\">cy.writeFile(&#8216;data.json&#8217;, { fname: &#8216;something&#8217;, lname: &#8216;example&#8217; })<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>after execution of above command data.json will have below entry:<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdcb681f\" style=\"\">\n<p data-css=\"tve-u-17afdcb986c\" style=\"\">{<\/p>\n<p data-css=\"tve-u-17afdcb986e\" style=\"\">&#8220;fname&#8221;: &#8220;something&#8221;,<\/p>\n<p data-css=\"tve-u-17afdcb986f\" style=\"\">&#8220;lname&#8221;: &#8220;example&#8221;<\/p>\n<p data-css=\"tve-u-17afdcb9870\" style=\"\">}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1627755137195\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910883\" style=\"outline: none;\">24. How can I run the tests \/ test suites only on specific browser without doing configuration file Changes?<\/a><\/h3>\n<p>Cypress provides option to specify the browser name on test suites or testcase level.<\/p>\n<p><strong>There are two options:<\/strong><\/p>\n<ol>\n<li>Using {browser: &#8216;&lt;browser_name&gt;&#8217;}<\/li>\n<li>Using Cypress.isBrowser(&#8216;&lt;browser_name&gt;&#8217;))<\/li>\n<\/ol>\n<p><strong>Option 1:<\/strong> {browser:&lt;browser_name&gt;} option can be used to execute the test cases or testuites at browser level<\/p>\n<p><strong>Example: Run test suite if its only chrome<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdcce50e\" style=\"\">\n<p data-css=\"tve-u-17afdcd00e8\" style=\"\">describe(&#8216;Google Navigation&#8217;, { browser: &#8216;chrome&#8217; }, () =&gt; {<\/p>\n<p data-css=\"tve-u-17afdcd00ea\" style=\"\">it(&#8216;Google Search&#8217;, () =&gt; {<\/p>\n<p data-css=\"tve-u-17afdcd00ec\" style=\"\">\/\/some code<\/p>\n<p data-css=\"tve-u-17afdcd00ed\" style=\"\">})<\/p>\n<p data-css=\"tve-u-17afdcd00ee\" style=\"\">})<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><strong>Example: Run Test cases if its any browser except firefox<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdcd4eda\" style=\"\">\n<p data-css=\"tve-u-17afdcd68d5\" style=\"\">describe(&#8216;Google Navigation&#8217;, () =&gt; {<\/p>\n<p data-css=\"tve-u-17afdcd68d7\" style=\"\">it(&#8216;Google Search&#8217;, { browser: &#8216;!firefox&#8217; }, () =&gt; {<\/p>\n<p data-css=\"tve-u-17afdcd68d9\" style=\"\">\/\/some code<\/p>\n<p data-css=\"tve-u-17afdcd68da\" style=\"\">})<\/p>\n<p data-css=\"tve-u-17afdcd68db\" style=\"\">})<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><strong>Option 2:<\/strong> Using Cypress.isBrowser(&#8216;&lt;browser_name&gt;&#8217;))<\/p>\n<p><strong>Example<\/strong>: Run if its Firefox<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdcda5ff\" style=\"\">\n<p data-css=\"tve-u-17afdcdceec\" style=\"\">it(&#8216;Example&#8217;, () =&gt; {<\/p>\n<p data-css=\"tve-u-17afdcdceed\" style=\"\">if (Cypress.isBrowser(&#8216;firefox&#8217;)) {<\/p>\n<p data-css=\"tve-u-17afdcdceef\" style=\"\">\u00a0\u00a0\u00a0 \/\/Some code<\/p>\n<p data-css=\"tve-u-17afdcdcef0\" style=\"\">\u00a0 }<\/p>\n<p data-css=\"tve-u-17afdcdcef1\" style=\"\">)}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><strong>Example: <\/strong>If its other than chrome<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdce1918\" style=\"\">\n<p data-css=\"tve-u-17afdce4706\" style=\"\">it(&#8216;Example&#8217;, () =&gt; {<\/p>\n<p data-css=\"tve-u-17afdce4708\" style=\"\">\u00a0 \/\/ true when running in Firefox, etc&#8230;<\/p>\n<p data-css=\"tve-u-17afdce470a\" style=\"\">\u00a0 if (Cypress.isBrowser(&#8216;!chrome&#8217;)) {<\/p>\n<p data-css=\"tve-u-17afdce470b\" style=\"\">\u00a0\u00a0 \/\/some code<\/p>\n<p data-css=\"tve-u-17afdce470c\" style=\"\">\u00a0 }<\/p>\n<p data-css=\"tve-u-17afdce470d\" style=\"\">})<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1627755137196\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910884\" style=\"outline: none;\">25. What are the reporters cypress supports?<\/a><\/h3>\n<p>By default, Cypress uses the spec reporter to output information to STDOUT. However since cypress built on mocha we can use all available mocha reporters including Junit, Teamcity etc.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910885\" style=\"outline: none;\">26. What is retry in cypress? How can I change the behaviour?<\/a><\/h3>\n<p>Cypress automatically retries all the command which will query the DOM element for 4 seconds.<\/p>\n<p>If we want to increase re-try timeout then we need to configure <strong>defaultCommandTimeout<\/strong> parameter either in cypress.json or should pass it in cypress CLI<\/p>\n<p><strong>Example: <\/strong><\/p>\n<p><strong>cypress.json<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdcfacb4\" style=\"\">\n<p data-css=\"tve-u-17afdcfc87f\" style=\"\">{<\/p>\n<p data-css=\"tve-u-17afdcfc881\" style=\"\">&#8220;defaultCommandTimeout&#8221;:30000,<\/p>\n<p data-css=\"tve-u-17afdcfc883\" style=\"\">}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><strong>Command line:<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdcff8ff\" style=\"\">\n<p data-css=\"tve-u-17afdd02925\" style=\"\">cypress run &#8211;config defaultCommandTimeout=10000<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910886\" style=\"outline: none;\">27. How can I run the tests in headless mode?<\/a><\/h3>\n<p>Cypress support headless mode, we can pass it as command line parameter<\/p>\n<p><strong>Example:<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdd0d185\" style=\"\">\n<p data-css=\"tve-u-17afdd10b01\" style=\"\">cypress run &#8211;headless &#8211;browser chrome<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\"><a class=\"tve-froala fr-basic\" name=\"_Toc76910887\" style=\"outline: none;\">28. How can I debug in Cypress?<\/a><\/h3>\n<p>Cypress provides two way to debug the tests.<\/p>\n<p>Using cy.pause()<\/p>\n<p>Using .debug<\/p>\n<p><strong>Option 1:<\/strong> Using cy.pause<\/p>\n<p>When we use the cy.pause()\u00a0 to pause the execute, we can do intended action\u00a0 manually and we can continue next<\/p>\n<p><strong>Example:<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdd18029\" style=\"\">\n<p data-css=\"tve-u-17afdd19da6\" style=\"\">cy.visit(&#8216;https:\/\/www.google.com&#8217;)<\/p>\n<p data-css=\"tve-u-17afdd19da8\" style=\"\">cy.pause() \/\/pauses the execution here<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>we can also use pause command by chaining off with other command<\/p>\n<p><strong>Example:<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdd26742\" style=\"\">\n<p data-css=\"tve-u-17afdd29689\" style=\"\">cy.get(&#8216;nav&#8217;).pause()<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><strong>Option 2:<\/strong> Using .debug<\/p>\n<p>To use this command we need to open the developer tools, This will set at debug point and it will pause the execution in that point<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdd2da74\" style=\"\">\n<p data-css=\"tve-u-17afdd302af\" style=\"\">cy.visit(&#8216;https:\/\/www.google.com&#8217;)<\/p>\n<p data-css=\"tve-u-17afdd302b0\" style=\"\">cy.debug() \/\/pauses the execution here<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>we can also use debug command by chaining off with other commands<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17afdd35a92\" style=\"\">\n<p data-css=\"tve-u-17afdd37d8e\" style=\"\">cy.get(&#8216;nav&#8217;).debug ()<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"tcb_flag\" style=\"display: none\"><\/div>\n<\/section>\n<p><\/body><\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents 19. What is after:run event in cypress? 20. What is cy.task() functions in Cypress? 21. What is cy.exec() function in cypress? 22. How can I read file in Cypress? 23. How can I write a file in cypress? 24. How can I run the tests \/ test suites only on specific browser [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,4],"tags":[],"class_list":["post-1060","post","type-post","status-publish","format-standard","hentry","category-cypress","category-interview-questions","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1060"}],"version-history":[{"count":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1060\/revisions"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}