When it comes to web monitoring, we normally use Curl to accomplish it. But things getting more complex such password protection, single sign-on using Microsoft ADFS, these new authentication requires some javascript integration which Curl is failed to do. I did some works with Sitespeed for end user monitoring. We use sitespeed docker to visit the website and collect browser metric. By the way, if you don’t know what sitespeed is , visit http://www.sitespeed.io
Sitespeed is doing pretty well in collecting the metrics, there is a very nice feature that Sitespeeds does is the ability writing our own selenium script. So imagine that , we need to visit a website, checking if it has some text we need, then visit filled in some information such as username and password, then submit, then check the result?
To make the post short, you can go to visit sitespeed.io to see how it works, how to use script.
I just want to share a script i wrote for our monitoring purpose. The script is simple, it go to google, check if it has “google” in the html page source , if yes, then submit our keyword and get the result.
Please note to the section “away driver.getPageSource()” , this is where we can get the html code.
module.exports = async function(context, commands)
{
const webdriver = context.selenium.webdriver;
const driver = context.selenium.driver;
step1="http://www.google.com";
step1_search_text="google"
try
{
await commands.measure.start(step1);
}catch (e)
{
console.log("An eror while opening url " + step1);
return 0;
}
pageSource=await driver.getPageSource();
if (pageSource.indexOf(step1_search_text)==-1)
{
console.log("["+ step1_search_text + "] is not found")
return 0;
}
console.log("["+ step1_search_text + "] is found")
search_keyword="i love sitespeed";
try
{
await commands.addText.byXpath( search_keyword,'//*[@id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input');
await commands.click.byXpath('//*[@id="tsf"]/div[2]/div[1]/div[3]/center/input[1]')
pageSource=await driver.getPageSource();
}catch(e)
{
console.log("An error has occurred");
//return 0;
}
console.log(pageSource)
};