otp
Sat Nov 18 2023 09:37:14 GMT+0000 (Coordinated Universal Time)
Saved by @mehran
import {chromium, expect, test} from "@playwright/test"; test.describe('Hard Test', () => { //test Case otp test('login', async ({ page }) => { const browser = await chromium.launch() const context = await browser.newContext() await page.goto('https://pwa.mci.ir/'); await page.getByRole('button', { name: 'متوجه شدم' }).click(); const baseUrl = 'http://91.92.209.41:8090/api/v1/'; const assignEndpoint = 'assign'; const assignBodyTemplate = JSON.stringify({ operator: 'MCI', simType: 'CREDIT', appName: 'MY_MCI' }); const requestUrl = `${baseUrl}${assignEndpoint}`; const requestOptions: RequestInit = { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: assignBodyTemplate }; const response = await fetch(requestUrl, requestOptions); const jsonResponse = await response.json(); // Handle jsonResponse as needed console.log('Post'); console.log(jsonResponse); const idNumber: number = jsonResponse.number; console.log(idNumber); await page.getByPlaceholder('شماره مورد نظر را وارد کنید').fill(String(idNumber)); await page.waitForTimeout(1500); await page.getByPlaceholder('شماره مورد نظر را وارد کنید').click(); await page.getByRole('button', { name: 'دریافت رمز یک بار مصرف' }).click(); // Using the response for the first request const token1: number = jsonResponse.token; const watchUrl = `${baseUrl}watch?token=${String(token1)}`; const watchOptions: RequestInit = { method: 'GET', headers: { 'Content-Type': 'application/json' } }; // Making the GET request const watchResponse = await fetch(watchUrl, watchOptions); const watchJson = await watchResponse.json(); // Extracting the 'code' from the second response const code = watchJson.code; console.log('Code:', code); await page.getByRole('textbox').first().fill("" + code); await page.waitForTimeout(1000); await page.getByTestId('switchButton').click(); // Test }); test('Services', async ({ page }) => { await page.goto('https://pwa.mci.ir/'); await page.getByRole('button', { name: 'خدمات خدمات' }).click(); const Erore=page.locator('#search').getByLabel('خطا در برقراری ارتباط'); if(Erore == undefined){ await expect(page.getByTestId('status')).toHaveText('Fail'); }else{ } }); //Test Case Romming test('Romming', async ({ page }) => { await page.getByText('رومینگ').click(); test.setTimeout(16000) const text = await page.locator('label', { hasText: /(فعال|وضعیت: غیر فعال)/ }).innerText(); if (text === ("وضعیت: غیر فعال")) { await page.getByText('وضعیت: غیر فعال').click(); await page.getByText('عملیات با موفقیت انجام شد').click(); } else{ await page.getByText('وضعیت: فعال').click(); await page.getByText('عملیات با موفقیت انجام شد').click(); } }); });
Comments