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
In recent days, I faced a problem that our team have to mange lot of tickets with ServiceNow. also ServiceNow was provided a cli tools but anyway i didn't get that from service-now store. finally I write a automation scripts with puppeteer and show my little experience within this tutorial.
0x01 Intro
Puppeteer is a Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium. and It was useful to do automation, eg. form submission, UI testing, keyboard input, etc.
Puppeteer Basics
we can just install it with npm install -i puppeteer , and i list some basics options here.
Also you can setting Nexus 10 and Pixel 2 etc. The full device lists was here
cookie Operation
constcookies=awaitpage.cookies()fs.writeFile('cookie.json',JSON.stringify(cookies,null,2),function(err){if(err)throwerr;console.log('completed write of cookies');});
even we use the cookie, it may not able to reuse the same session. And we can use the userDataDir option to store the data
awaitpage.evaluate(()=>{// var aTags = document.getElementsByTagName("td");// var searchText = "\(empty\)";// var found;// for (var i = 0; i < aTags.length; i++) {// if (aTags[i].textContent == searchText) {// found = aTags[i];// found.click();// break;// }}});
Anti-Detection (This is can't be describe in shortly)
0x02 Scenario
There was two main operations from my side, The fist one is to assign ticket to each person, and the second one is to close tickets. i will show you how to use puppeteer to implement an automation tools. and this is part code of tools.
constpuppeteer=require('puppeteer-debug')constfs=require('fs');// const iPhone = puppeteer.devices['iPhone 6'];;(asyncfunction(){constbrowser=awaitpuppeteer.launch({// devtools: true,headless: false,userDataDir: './userdata'})constpage=awaitbrowser.newPage()// await page.emulate(iPhone);awaitpage.goto('https://paypal.service-now.com/sc_task_list.do?xxxxxxxxx&yyyyyyyy')awaitpage.waitForTimeout(50000)vararray=fs.readFileSync('owners').toString().split("\n");for(minarray){console.log("Assign ticket to "+array[m])awaitpage.evaluate(()=>{varaTags=document.getElementsByTagName("td");varsearchText="\(empty\)";varfound;for(vari=0;i<aTags.length;i++){if(aTags[i].textContent==searchText){found=aTags[i];found.click();break;}}});for(leti=0;i<20;i++){awaitpage.keyboard.press('Enter')awaitpage.waitForTimeout('2000')awaitpage.keyboard.type(array[m])awaitpage.waitForTimeout('2000')awaitpage.keyboard.press('ArrowDown')awaitpage.waitForTimeout('2000')awaitpage.keyboard.press('Enter')awaitpage.waitForTimeout('3000')if(i!=19){awaitpage.keyboard.press('ArrowDown')}}awaitpage.evaluate(()=>{document.getElementsByTagName("button")[4].click();});awaitpage.waitForTimeout(5000)}awaitpuppeteer.debug()// go to REPLawaitbrowser.close()})()
The code was not difficult, and here is some trick what i learned from that.
mobile site is more friendly for automation
If you can't get an element with dynamic selector , you can just use js code to find that in the page context or you can use keyboard operations if it was allowed in the page.
we should wait a selector before what we want do for that due to the response time was different even the same page.
if you need to login with accounts each time, try to save user data with the main site but search site.
Here is the final results:
test.mp4
0x03 Conclusion
In last year, we are under fastest growing and there was lot of works need to do. After period of testing , i have to say —— it's necessary to make something automation. especially In daily basis.
0x01 Intro
Puppeteer is a Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium. and It was useful to do automation, eg. form submission, UI testing, keyboard input, etc.
Puppeteer Basics
we can just install it with
npm install -i puppeteer
, and i list some basics options here.Puppeteer Advanced
0x02 Scenario
There was two main operations from my side, The fist one is to assign ticket to each person, and the second one is to close tickets. i will show you how to use puppeteer to implement an automation tools. and this is part code of tools.
The code was not difficult, and here is some trick what i learned from that.
Here is the final results:
test.mp4
0x03 Conclusion
In last year, we are under fastest growing and there was lot of works need to do. After period of testing , i have to say —— it's necessary to make something automation. especially In daily basis.
Resources
The text was updated successfully, but these errors were encountered: