* -------------------------------------------------------------------------
* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* -------------------------------------------------------------------------
*/
import { expect, test as baseTest, WebSocket } from '@playwright/test';
import { FrameworkPage, SourcePage } from '@/page-object';
import { clearAllData, importData, setupWebSocketListener } from '@/utils';
import { FilePath } from '@/utils/constants';
import { SelectHelpers } from '@/components';
interface TestFixtures {
sourcePage: SourcePage;
ws: Promise<WebSocket>;
}
const test = baseTest.extend<TestFixtures>({
sourcePage: async ({ page }, use) => {
const sourcePage = new SourcePage(page);
await use(sourcePage);
},
ws: async ({ page }, use) => {
const ws = setupWebSocketListener(page);
await use(ws);
},
});
const imgMap = {
loadDataSuccess: 'loadDataSuccess.png',
coreSelectChangeSuccess: 'coreSelectChangeSuccess.png',
codeTableInteractInsructionTableSuccess: 'CodeTable_interact_InstructionTable.png',
insructionTableInteractCodeTableSuccess: 'InstructionTable_interact_CodeTable.png',
switchChineseLanguageSuccess: 'Chinese_Language.png',
};
const inputMap = {
secondFileName: '/home/wangyunkai/code/samples/operator/ascendc/0_introduction/13_matmulleakyrelu_kernellaunch/MatmulLeakyReluInvocationAsync/matmul_leakyrelu_custom.cpp',
};
const resMap = {
secondFileContens:'#include "kernel_operator.h"',
};
test.describe('Source', () => {
test.beforeEach(async ({ page, sourcePage, ws }, testInfo) => {
await page.goto('/');
const filePath = FilePath.OP_SIMULATOR_BIN;
await importData(page, filePath);
await sourcePage.goto();
await page.mouse.move(0, 0);
const coreValue = sourcePage.sourceFrame.getByText('core0');
await expect(coreValue).toBeVisible();
});
test.afterEach(async ({ page, ws }) => {
await clearAllData(page, ws);
});
test('test_source_loadDataSuccess', async ({ page, sourcePage }) => {
const { mainContent } = sourcePage;
await page.mouse.move(0,0);
await expect(mainContent).toHaveScreenshot(imgMap.loadDataSuccess);
});
test('test_source_coreSelectChange', async ({ page, sourcePage }) => {
const { sourceFrame, coreSelector, mainContent } = sourcePage;
const coreSelect = new SelectHelpers(page, coreSelector, sourceFrame);
await coreSelect.open();
await coreSelect.selectOption('core0.veccore1');
await expect(mainContent).toHaveScreenshot(imgMap.coreSelectChangeSuccess);
});
test('test_source_sourceSelectChange', async ({ page, sourcePage }) => {
await sourcePage.goto();
const { sourceFrame, sourceSelector } = sourcePage;
const coreSelect = new SelectHelpers(page, sourceSelector, sourceFrame);
await coreSelect.open();
await coreSelect.selectOption(inputMap.secondFileName);
const codeTable = sourceFrame.locator('#CodeTable');
await expect(codeTable).toContainText(resMap.secondFileContens);
});
test('test_source_CodeTable_interact_InstructionTable', async ({ sourcePage }) => {
const { mainContent } = sourcePage;
const codeAttrTable = mainContent.locator('#CodeAttrTable');
const td = codeAttrTable.locator('td', { hasText: '16' }).first();
await td.click();
await expect(codeAttrTable.locator('tr.selected').first()).toBeVisible();
await sourcePage.mouseOut();
await expect(mainContent).toHaveScreenshot(imgMap.codeTableInteractInsructionTableSuccess);
});
test('test_source_InstructionTable_interact_CodeTable', async ({ sourcePage }) => {
const { mainContent } = sourcePage;
const instructionTable = mainContent.locator('#Instructions');
const tr = instructionTable.locator('tr', { hasText: '1' }).first();
await tr.click();
await expect(instructionTable.locator('tr.selected').first()).toBeVisible();
await sourcePage.mouseOut();
await expect(mainContent).toHaveScreenshot(imgMap.insructionTableInteractCodeTableSuccess);
});
test('test_source_Chinese_Language', async ({ page, sourcePage }) => {
const { mainContent } = sourcePage;
const frameworkPage = new FrameworkPage(page);
await frameworkPage.switchLanguageBtn.click();
await sourcePage.mouseOut();
await expect(mainContent).toHaveScreenshot(imgMap.switchChineseLanguageSuccess);
await frameworkPage.switchLanguageBtn.click();
});
});