energyaustralia-coding-test
Author Muhammad Imran Email: muhammadghouseimran.zahirudeen@cognizant.com
-
Importing Dependencies:
import { assert } from 'chai'; import { validateApiResponse } from '/Users/immi/Desktop/ea-tech-wdio-sample/src/test/api/api.ts';
- The code imports the
assert
module from the 'chai' library, which provides assertion functions for making test assertions. - It also imports the
validateApiResponse
function from the specified file ('/Users/immi/Desktop/ea-tech-wdio-sample/src/test/api/api.ts'
). This function likely contains the API response data that will be used for validation.
- The code imports the
-
Describe and Test Block:
describe('iOS App Test', () => { it('should validate the response in the iOS app', async () => { // Test logic goes here }); });
- This block uses the
describe
function from Mocha to define a test suite titled 'iOS App Test'. - Inside the test suite, the
it
function is used to define an individual test case titled 'should validate the response in the iOS app'. - The test case is an async function that contains the logic for validating the response in the iOS app.
- This block uses the
-
Locating Elements:
const bandsListEle = 'type == \"XCUIElementTypeCollectionView\"'; const bandsList = await $(`-ios predicate string:${bandsListEle}`); const displayedBandsEle = 'type == XCUIElementTypeCell'; const displayedBands = await $$(`-ios predicate string:${displayedBandsEle}`);
- The code defines two variables,
bandsListEle
anddisplayedBandsEle
, which represent the element locators. - The located elements are stored in
bandsList
anddisplayedBands
variables, respectively.
- The code defines two variables,
-
Validation:
// Validate the number of bands in the app assert.equal(displayedBands.length, validateApiResponse.length, 'Number of displayed bands should match the API response'); // Validate each band and its child item as a festival for (let i = 0; i < validateApiResponse.length; i++) { const band = validateApiResponse[i]; // Validate the band name assert.equal(bandName, band.name, 'Band name should match the API response'); // Validate the festival assert.equal(festival, 'Festival', 'Child item should be displayed as "Festival"'); }
- The code performs various validation checks using the
assert
module from chai. - First, it validates the number of displayed bands by comparing the length of
displayedBands
array with the length ofvalidateApiResponse
array. - Then, it enters a loop to validate each band and its child item as a festival.
- Inside the loop, it retrieves the band name and festival text using element locators and WebDriverIO's
getText()
method. - It compares the retrieved values with the corresponding values in the
validateApiResponse
array usingassert.equal
assertions.
- The code performs various validation checks using the