VSeed, an elegant data composer, transforming complexity into simplicity.
!!!###!!!title=Use Midscene.js to simplify testing with AI——VisActor/VTable tutorial documents!!!###!!!!!!###!!!description=[Midscene.js](https://midscenejs.com/) is an automation tool powered by multimodal AI that makes UI automation test scripts easier to write and maintain.<div style="width: 40%; text-align: center;"> <video src="https://midscenejs.com/introduction/Midscene.mp4" controls style="width: 100%"></video></div>When using VisActor products, you can quickly complete UI test cases using the action capabilities provided by Midscene.js. The query and assert functionalities provided by Midscene.js also make it more convenient to write test cases.!!!###!!!
Using Midscene.js to Simplify Testing with AI
Midscene.js is an automation tool powered by multimodal AI that makes UI automation test scripts easier to write and maintain.
When using VisActor products, you can quickly complete UI test cases using the action capabilities provided by Midscene.js. The query and assert functionalities provided by Midscene.js also make it more convenient to write test cases.
Refer to the documentation to configure model parameters: https://midscenejs.com/en/model-provider.html (UI-TARS or Qwen-2.5-VL models are recommended since VisActor components are implemented based on canvas, so the gpt-4o model cannot be used)
Clone the repository and run pnpm install to install dependencies
Create a .env file and configure the large language model
# replace by your own, example(qwen):
OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
OPENAI_API_KEY="YOUR_TOKEN"
MIDSCENE_MODEL_NAME="qwen-vl-max-latest"
MIDSCENE_USE_QWEN_VL=1
Run the tests
# run vchart demo
pnpm run start-test-vchart
# run vtable demo
pnpm run start-test-vtable
Example Code Explanation
Test code is in test/vtable-test.ts
Create browser & page, open test URL
const browser = await puppeteer.launch({
headless: false, // 'true' means we can't see the browser window
args: ['--no-sandbox', '--disable-setuid-sandbox']
});const page = await browser.newPage();await page.setViewport({
width: 1280,
height: 768,
deviceScaleFactor: os.platform() === 'darwin' ? 2 : 1 // this is used to avoid flashing on UI Mode when doing screenshot on Mac
});await page.goto(URL);
// init Midscene agentconst agent = newPuppeteerAgent(page);
// Get the content of the first row in the first columnconst items = await agent.aiQuery('Get thecontentofthefirstrowinthefirstcolumn');
console.log('Content of first row in first column:', items);
// Click the sort button on the right side of Order ID in the first columnawait agent.aiAction('Click thesortbuttonontherightsideof Order ID inthefirstcolumn');
// Assert that the content of the second row in the first column is CA-2015-105417. Returns a Promise that resolves to void when assertion succeeds; throws an error with errorMsg and AI-generated reason if assertion failsawait agent.aiAssert('The contentofthesecondrowinthefirstcolumnis CA-2015-105417');
Take screenshot and compare with standard image
const screenshot = await page.screenshot();
// Compare with standard imageawait diffImage('./test/images/vtable-test.png', screenshot, 'vtable-diff');