Topic 3: Basic Scripting for Test Automation


Assignment: Turning pseudo-code into functions 


Objective:

In this assignment, you will practice turning pseudo-code into actual functions. You will use the example pseudo-code we showed you in the lesson to create functions for each step of the test case. The goal is to convert the pseudo-code into executable functions that can be used in your test automation script.

Example Pseudo-Code:

“`javascript

launchApplication()

enterUsername(“validUsername”)

enterPassword(“validPassword”)

clickLoginButton()

verifyLoginSuccess()

“`

Your Role:

Open VS Code. Create a new file in your Playground project folder and name it something appropriate, like “login_spec.cy.js”.

Step 1: Launch the application: Create a function called `launchApplication()`. This function should open the specified URL of the test website in a browser.

Step 2: Enter valid username: Create a function called `enterUsername(username)`. This function should locate the username input field on the page and enter the provided username.

Example Solution:

“`javascript

function launchApplication() {

  cy.visit(‘https://demo.applitools.com/’);

}

“`

Step 3: Enter valid password: Create a function called `enterPassword(password)`. This function should locate the password input field on the page and enter the provided password.

Step 4: Click the “Login” button: Create a function called `clickLoginButton()`. This function should locate the login button on the page and click it.

Step 5: Verify successful login: Create a function called `verifyLoginSuccess()`. This function should assert that the user has successfully signed in.

Note: Remember to use appropriate Cypress commands and assertions in your functions to interact with the website and verify the expected behavior.

Variables:

Don’t forget about variables. You can set the `validUsername` and `validPassword` variables and any others at the beginning of your script to hold the username and password values you want to use for testing.

For example:

“`javascript

const validUsername = ‘yourUsername’;

const validPassword = ‘yourPassword’;

“`

Activity Completion:

Once you have created functions for each step of the pseudo-code and set the necessary variables, execute your test script to validate that the functions perform the desired actions and assertions.

Submission:

Take a screenshot of the test results and upload the screenshot and the test spec file below.

Note: If you encounter any issues or have questions during the activity, refer to the Cypress documentation or ask for assistance from one of your Senseis via Slack or Calendly.

Skip to content