import puppeteer from 'puppeteer';
/**
* 自动登录
* -----
* @param {*} page
*/
const autoLogin = async (page) => {
try {
await page.waitForSelector('.ant-modal-confirm-btns .ant-btn-primary');
} catch (error) {
console.log(error, "没有等到弹窗")
}
page.waitFor(320)
await page.click('.ant-modal-confirm-btns .ant-btn-primary');
await page.waitForSelector('.ant-input-affix-wrapper #contact_phone');
try {
await page.type('.ant-input-affix-wrapper #contact_phone', '17700000000');
await page.type('.ant-input-affix-wrapper #password', 'qingxie');
await page.click('.ant-form-item-children .ant-btn');
} catch (error) {
// console.log(error)
}
}
const addProduct = async (page, index) => {
try {
await page.waitForSelector('.ant-form-item-control > .ant-form-item-children > .ant-select > .ant-select-selection > .ant-select-selection__rendered')
const selectBtn = await page.$('.ant-form-item-control > .ant-form-item-children > .ant-select > .ant-select-selection > .ant-select-selection__rendered')
await selectBtn.click()
await page.waitForSelector('div > .ant-select-dropdown .ant-select-dropdown-menu > .ant-select-dropdown-menu-item')
const list = await page.$$('div > .ant-select-dropdown .ant-select-dropdown-menu > .ant-select-dropdown-menu-item')
await list[(index % list.length)].click()
await page.waitFor(200)
await page.type('.ant-form-item-children #b_product_name', `${index}___自动测试产品名称${index}`);
await page.type('.ant-form-item-children #b_product_intro', `${index}___自动测试产品介绍content:loremloremloremloremloremloremlorem`);
await page.type('.ant-form-item-children .ant-input-number-input', "100");
await page.click('.ant-form-item-children .ant-btn')
} catch (error) {
// console.log(error)
}
}
jest.retryTimes(1200000);
describe('产品线', () => {
it('添加产品~~~', async () => {
const browser = await puppeteer.launch({
// 是否不显示浏览器, 为true则不显示
// headless: false,
headless: true,
defaultViewport: null,
timeout: 0,
});
const page = await browser.newPage();
await page.goto('http://localhost:8000/productlinelist/addproduct');
await autoLogin(page)
for (let i = 0; i < 1000; i++) {
await addProduct(page, i)
await page.waitFor(300)
}
// await page.close();
// browser.close();
}, 1200000);
});
https://zhaoqize.github.io/puppeteer-api-zh_CN/
https://blog.csdn.net/weixin_30273501/article/details/96225521
https://www.cnblogs.com/paris-test/p/9713782.html