<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: kadir</title>
    <description>The latest articles on DEV Community by kadir (@aktibaba).</description>
    <link>https://dev.to/aktibaba</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F874003%2F9fca7a23-ae78-4520-b137-995b26b38252.jpeg</url>
      <title>DEV Community: kadir</title>
      <link>https://dev.to/aktibaba</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aktibaba"/>
    <language>en</language>
    <item>
      <title>E2E Testing with Cypress and Typescript</title>
      <dc:creator>kadir</dc:creator>
      <pubDate>Mon, 26 Sep 2022 13:24:42 +0000</pubDate>
      <link>https://dev.to/aktibaba/e2e-testing-with-cypress-and-typescript-3l16</link>
      <guid>https://dev.to/aktibaba/e2e-testing-with-cypress-and-typescript-3l16</guid>
      <description>&lt;p&gt;This post will show you how to install and configure Cypress with Typescript to test simple Form.io forms.&lt;/p&gt;

&lt;p&gt;I used &lt;a href="https://formio.github.io/angular-demo/#/"&gt;formio angular demo application&lt;/a&gt; to perform e2e test against. Here is the testing project &lt;a href="https://github.com/aktibaba/cypress-ts-framework"&gt;github-repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After creating a project folder and navigating project root directory, as a first step, we need to install Cypress with this command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npm install cypress --save-dev&lt;/code&gt; &lt;br&gt;
then  we need to install typescript with this command :&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npm install --save-dev typescript&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After installing Cypress, we need to start Cypress in open mode with &lt;code&gt;npx cypress open&lt;/code&gt; to configure it. Starting Cypress will create cypress.config file and other folders.  Inside Cypress folder &lt;br&gt;
we need top add tsconfig.json file like below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I4gcauCH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xbmgnpthr05yskq7vjo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I4gcauCH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xbmgnpthr05yskq7vjo.png" alt="tsconfig" width="880" height="480"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es5", "dom"],
    "types": ["cypress", "node"]
  },
  "include": ["**/*.ts"]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that we can change all js file to ts file and ad our first testing file to run &lt;/p&gt;

&lt;p&gt;command to run test in headless mode:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;npx cypress run &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;command to run test in open mode:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;npx cypress open &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cypress</category>
      <category>typescript</category>
      <category>e2e</category>
      <category>formio</category>
    </item>
    <item>
      <title>E2E Testing Framework with Cypress 10+ and Cucumber by using POM to test Forms</title>
      <dc:creator>kadir</dc:creator>
      <pubDate>Sun, 25 Sep 2022 02:14:32 +0000</pubDate>
      <link>https://dev.to/aktibaba/e2e-testing-framework-with-cypress-10-and-cucumber-by-using-pom-to-test-formio-forms-23a8</link>
      <guid>https://dev.to/aktibaba/e2e-testing-framework-with-cypress-10-and-cucumber-by-using-pom-to-test-formio-forms-23a8</guid>
      <description>&lt;p&gt;This post will show you how to create testing framework based on page object model by using Cypress 10+ and Cucumber to test simple &lt;a href="https://www.form.io/"&gt;Form.io&lt;/a&gt; forms.&lt;/p&gt;

&lt;p&gt;I used &lt;a href="https://formio.github.io/angular-demo/#/"&gt;formio angular demo application&lt;/a&gt; to perform e2e test against. Here is the project &lt;a href="https://github.com/aktibaba/cypress-cucumber-framework"&gt;github-repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After creating a project folder and navigating project root directory, as a first step, we need to install Cypress with this command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;npm install cypress --save-dev&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then starting Cypress  with &lt;code&gt;npx cypress open&lt;/code&gt; command will start Cypress in open mode. E2E Testing steps will help you with basic Cypress configuration. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jBE2dOeU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5bbfbochzsp4p8dy5rs8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jBE2dOeU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5bbfbochzsp4p8dy5rs8.png" alt="cypress in open mode" width="880" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far it was a basic Cypress instillation and configuration. To add Cucumber we need to install Cucumber Preprocessor and browserify-preprocessor with the following commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;npm install @badeball/cypress-cucumber-preprocessor&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;npm install --save-dev @cypress/browserify-preprocessor&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then we need to rearrange cypress.config.js file to add a node event and base url , like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const {
  defineConfig
} = require("cypress");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const browserify = require("@badeball/cypress-cucumber-preprocessor/browserify");

async function setupNodeEvents(on, config) {
  // This is required for the preprocessor to be able to generate JSON reports after each run, and more,
  await preprocessor.addCucumberPreprocessorPlugin(on, config);

  on("file:preprocessor", browserify.default(config));

  // Make sure to return the config object as it might have been modified by the plugin.
  return config;
}
module.exports = defineConfig({

  e2e: {
    baseUrl: "https://formio.github.io/angular-demo/#/",
    setupNodeEvents,
    specPattern: "cypress/e2e/**/*.{feature,features}",
  },
  // excludeSpecPattern: "**/others/*",

});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the e2e folder, I created another folder and named as a formio-basic-form. In that folder, I created a step definition js file and object js file to apply POM, and I created a feature file with the same name but out of formio-basic-form folder in the e2e folder. The image of folder structure and feature file is given below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_NaOkx2y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vzbmpsnx1qh8lmtcf2g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_NaOkx2y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vzbmpsnx1qh8lmtcf2g.png" alt="feature file and folder structure " width="880" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created a class in the object js file and write all cypress codes here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class formiobasicform {

    static navigatingFormioAngularDemoApp() {
        //since we define base url in config , it will directly go application
        cy.visit('/')

    }
    static fillingBasicForm() {

        cy.get("input[placeholder='Enter your first name']").type("firstname")
        cy.get("input[placeholder='Enter your first name']").type("lastname")
        cy.get("input[placeholder='Enter your email address']").type("firstname@g.com")
        cy.get("input[name='data[phoneNumber]']").type(1233451223)
        cy.get("[name='data[survey][howWouldYouRateTheFormIoPlatform]']").eq(0).click()
        cy.get("[name='data[survey][howWasCustomerSupport]']").eq(0).click()
        cy.get("[name='data[survey][overallExperience]']").eq(0).click()
        cy.get("canvas.signature-pad-canvas").click({
            which: 1
        })
        cy.get("button[name='data[submit]']").click()
    }
    static verifyingSubmission() {
        cy.get("formio-alerts .alert-success").should("be.exist")
    }

}
export default formiobasicform;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then, I wrote the step definitions in the step js file like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const {
    Given,
    When,
    Then,

} = require("@badeball/cypress-cucumber-preprocessor");
import formiobasicform from "./formio-basic-form-object";

//Scenario: verifying filling simple formio form 
Given("user navigate formio", () =&amp;gt; {
    formiobasicform.navigatingFormioAngularDemoApp()
})
When("user fill the form", () =&amp;gt; {
    formiobasicform.fillingBasicForm()
})
Then("user verify form submission", () =&amp;gt; {
    formiobasicform.verifyingSubmission()

})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After creating these files, our first test scenario is ready to&lt;br&gt;
to run e2e test.&lt;br&gt;
  command to run test in headless mode:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;npx cypress run &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;command to run test in open mode:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;npx cypress open &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>formio</category>
      <category>cucumber</category>
      <category>cypress10</category>
      <category>testingforms</category>
    </item>
  </channel>
</rss>
