You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// snowflake-connection.tsimport*assnowflakefrom'snowflake-sdk';importdotenvfrom'dotenv';dotenv.config();interfaceSnowflakeConfig{account: string;username: string;password: string;warehouse?: string;database?: string;schema?: string;role?: string;}exportclassSnowflakeClient{privateconnection: snowflake.Connection|null=null;privateconfig: SnowflakeConfig;constructor(config?: SnowflakeConfig){this.config=config||{account: process.env.SNOWFLAKE_ACCOUNT!,username: process.env.SNOWFLAKE_USER!,password: process.env.SNOWFLAKE_PASSWORD!,warehouse: process.env.SNOWFLAKE_WAREHOUSE,database: process.env.SNOWFLAKE_DATABASE,schema: process.env.SNOWFLAKE_SCHEMA,role: process.env.SNOWFLAKE_ROLE};}asyncconnect(): Promise<void>{returnnewPromise((resolve,reject)=>{this.connection=snowflake.createConnection(this.config);this.connection.connect((err,conn)=>{if(err){console.error('Unable to connect: '+err.message);reject(err);}else{console.log('Successfully connected to Snowflake');resolve();}});});}asyncexecuteQuery<T=any>(query: string): Promise<T[]>{returnnewPromise((resolve,reject)=>{if(!this.connection){reject(newError('Not connected to Snowflake'));return;}this.connection.execute({sqlText: query,complete: (err,stmt,rows)=>{if(err){console.error('Failed to execute statement: '+err.message);reject(err);}else{resolve(rowsasT[]);}}});});}asyncdisconnect(): Promise<void>{returnnewPromise((resolve)=>{if(this.connection){this.connection.destroy((err)=>{if(err){console.error('Error disconnecting: '+err.message);}resolve();});}else{resolve();}});}}
3. Tích hợp với Playwright Test
// tests/snowflake-playwright.spec.tsimport{test,expect,Page}from'@playwright/test';import{SnowflakeClient}from'../snowflake-connection';interfaceTestData{id: number;name: string;email: string;status: string;}test.describe('Snowflake + Playwright Tests',()=>{letsnowflakeClient: SnowflakeClient;lettestData: TestData[];test.beforeAll(async()=>{// Kết nối Snowflake và lấy datasnowflakeClient=newSnowflakeClient();awaitsnowflakeClient.connect();// Lấy test data từ SnowflaketestData=awaitsnowflakeClient.executeQuery<TestData>('SELECT id, name, email, status FROM users_table LIMIT 10');});test.afterAll(async()=>{awaitsnowflakeClient.disconnect();});test('Verify data from Snowflake displays correctly on UI',async({ page })=>{awaitpage.goto('https://your-app.com/users');// Verify từng recordfor(constrecordoftestData){constrow=page.locator(`tr[data-id="${record.id}"]`);awaitexpect(row).toBeVisible();// Verify các fieldsawaitexpect(row.locator('.name-cell')).toContainText(record.name);awaitexpect(row.locator('.email-cell')).toContainText(record.email);awaitexpect(row.locator('.status-cell')).toContainText(record.status);}});test('Submit form with Snowflake data',async({ page })=>{awaitpage.goto('https://your-app.com/form');// Sử dụng data từ Snowflake để điền formconstfirstRecord=testData[0];awaitpage.fill('#name',firstRecord.name);awaitpage.fill('#email',firstRecord.email);awaitpage.selectOption('#status',firstRecord.status);awaitpage.click('button[type="submit"]');// Verify submissionawaitexpect(page.locator('.success-message')).toBeVisible();});});