SSO With Okta
The article explains how to test single sign-on (SSO) login with Okta in Pricefx. It provides two examples of Cypress tests for testing SSO login using Okta's embed app link and Okta dashboard. Okta is a customizable, secure, and drop-in solution to add authentication and authorization services to your applications.
NOTE: To set up SSO with Okta, follow instructions in here.
After Okta account is connected to Pricefx, there will be two ways to test SSO login:
Okta will provide “Embed app link” which you can use to directly login to Pricefx. Example of Cypress test:
it('Login to Price f(x) trough OKTA embed app link', () => { const embedAppLink = "https://trial-7507976.okta.com/home/trial-7507976_pricefx_2/0oa16ptwcfEfr2hrU697/aln16pujzfCtc94xi697" cy.visit(embedAppLink); cy.url().should('contain', 'pricefx'); //Asserting that we are in Pricefx page cy.get('#input28').type(username + '{enter}'); //Filling Okta username cy.get('#input59').type(password + '{enter}'); //Filling Okta password cy.waitForSpinner(); cy.log(`ASSERT THAT WE ARE LOGGED INTO PRICEFX IN ${partition} PARTITION`); cy.url().should('contain', 'pricefx.com'); cy.url().should('contain', `partition=${partition}`); });
CODE REVIEW: code snippet written in JavaScript, using Cypress, which is an end-to-end testing framework. The purpose of this code is to automate the process of logging into a service called Pricefx through an Okta embedded app link.
Here is a breakdown of what the code does:
Line 3 sets a constant
embedAppLink
to a URL, which is the Okta embedded app link for Pricefx.Line 4 uses
cy.visit()
to navigate to theembedAppLink
.Line 5 checks that the current URL contains the string 'pricefx', asserting that the navigation has led to the Pricefx page.
Lines 7 and 8 use
cy.get()
to retrieve elements with IDs#input28
and#input59
, which are presumed to be the username and password input fields. It then types the username and password into these fields, appending{enter}
to simulate pressing the Enter key after each input.Line 9 calls
cy.waitForSpinner()
, which is likely a custom Cypress command that waits for a loading spinner animation to disappear, indicating that the page has loaded or the login process is complete.Line 11 logs a message to assert that the user is logged into Pricefx in a specific partition (though the variable
partition
is not shown in this snippet).Line 12 checks that the current URL contains 'http://pricefx.com '.
Line 13 checks that the current URL contains a partition parameter equal to the value of the variable
partition
.
NOTE: This test script could be part of a larger suite, as it references variables such as username
, password
, and partition
that are not defined within this snippet. Also, there are some syntax errors in the comments and code, such as (enter}
which should be {enter}
and $ (partition}
which should be ${partition}
. These errors would need to be corrected for the script to work properly.
Login into Okta, where you will have installed Pricefx button (which will redirect you to Pricefx). Example of Cypress test:
it('Login to Price f(x) trough OKTA dashboard', () => {
const oktalink = "https://trial-7507976.okta.com/app/UserHome"
cy.log('Login in into Okta dashobard first, and then from dashboard entering Pricefx app');
cy.visit(oktalink);
cy.get('#input28').type(username + '{enter}'); //Filling Okta Username
cy.get('#input59').type(password + '{enter}'); //Filling Okta password
cy.url().should('contain', 'UserHome');
cy.contains('Price f(x)').invoke('attr', 'href').then(myLink => {
cy.visit(myLink);
}) //Making sure that we don't open website in new tab in Chrome (because Cypress can't work in new tab)
cy.waitForSpinner();
cy.log(`ASSERT THAT WE ARE LOGGED INTO PRICEFX IN ${partition} PARTITION`);
cy.url().should('contain', 'pricefx.com');
cy.url().should('contain', `partition=${partition}`);
});
CODE REVIEW: a snippet of code from an automated test script written for Cypress, that outlines a test case for logging into an application called "Price f(x)" through the Okta dashboard.
Here's a breakdown of what the script is doing:
The test case is named "Login to Price f(x) through OKTA dashboard".
It defines a constant
oktalink
that stores the URL to the Okta dashboard login page.The script logs a message indicating the start of the login process into the Okta dashboard.
It uses the
cy.visit()
command to navigate to the Okta login page.The script then fills in the Okta username and password fields using the
cy.get().type()
command, appending{enter}
to submit each form field.It asserts that the current URL should contain 'UserHome', ensuring that the login was successful and the user is redirected to the Okta User Home page.
The script searches for a link containing the text 'Price f(x)', retrieves its
href
attribute, and then navigates to that link usingcy.visit()
.A comment in the code explains that this step ensures the website doesn't open in a new tab in Chrome, as Cypress cannot interact with new tabs.
The script includes a placeholder for a command
cy.waitForSpinner()
, which suggests there might be a loading spinner that needs to be waited on, but the actual command is not visible in the snippet.Finally, the script logs a message to assert that the user is logged into the Price f(x) application in a specific partition, and it checks that the URL contains 'http://pricefx.com ' and the correct partition information.
NOTE: The ${partition}
in the URL assertions indicates that the partition is a variable that will be replaced with the actual partition value during test execution.
NOTE: This test case is a good example of how Cypress can be used to automate the login process, navigate through a series of web pages, and validate that the correct pages are loaded. It demonstrates the use of Cypress commands for visiting URLs, selecting elements, typing into fields, and asserting conditions about the state of the application under test.