AppD Archive

Scripts for Browser Synthetic Monitoring

CommunityUser
Splunk Employee
Splunk Employee

Dear All,

Could someone help me with a script to create a new job in browser synthetic monitoring in Saas Controller.

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

Hi,

This link should be a good start up point.

You can use Selenium IDE add-on in Firfox or any other browser to record your selenium steps

and then select File > Export Test Case As > Python 2/ Unittest/ Webdriver. You can use that script and develop/edit from there.

For more on selenium python: http://selenium-python.readthedocs.io/

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

Hello,

I've used the Selium add on to create a script that logs in to our site.  I get a screenshot that our page loaded through the job, but then it times out after 60 seconds.  It seems like it is loading the site, but then not continuing with the rest of the steps.  I've tried adjusting the wait time in the script, but that's just the timeout.  I don't see any indication of what the script is waiting on?  The script I'm trying to use is below.

# -*- coding: utf-8 -*-
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains
import time, unittest

def is_alert_present(wd):
    try:
        wd.switch_to_alert().text
        return True
    except:
        return False

class LSOL_Login_Loads(unittest.TestCase):
    def setUp(self):
        self.wd = WebDriver()
        self.wd.implicitly_wait(30)
    
    def test_LSOL_Login_Loads(self):
        success = True
        wd = self.wd
        wd.get("http://www.landstaronline.com/Public/Login.aspx")
        wd.find_element_by_id("USER").click()
        wd.find_element_by_id("USER").clear()
        wd.find_element_by_id("USER").send_keys("USERID")
        wd.find_element_by_id("PASSWORD").click()
        wd.find_element_by_id("PASSWORD").clear()
        wd.find_element_by_id("PASSWORD").send_keys("PASSWORD")
        wd.find_element_by_id("Submit").click()
        self.assertTrue(success)
    
    def tearDown(self):
        self.wd.quit()

if __name__ == '__main__':
    unittest.main()

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

Try to use XPath instead of id as well. XPath can give you much exact definition for objects in DOM model. We had the same problem with css-selector because there was 2 or more css-selectors with same name

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

I did look at the script output, and all it tells me is that it's "Executing a WebDriver script" and then times out 30 seconds (or whatever timeout I set) later.  this leads me to believe it's not even trying the next step.  I would assume if it couldn't find an element on the page, I would get an error.

I created the script using Selenium builder for Firefox, not sure how I would get the Xpath id's from this setup?  I haven't tested the script outside of AppDynamics either...I will look into doing that and see where that get's me.

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

Ok, so here is the latest script I have:

try:
    driver.get("http://www.landstaronline.com/Public/Login.aspx")
    driver.find_element_by_id("USER").click()
    driver.find_element_by_id("USER").clear()
    driver.find_element_by_id("USER").send_keys("USERID")
    driver.find_element_by_id("PASSWORD").click()
    driver.find_element_by_id("PASSWORD").clear()
    driver.find_element_by_id("PASSWORD").send_keys("PASSWORD")
    driver.find_element_by_id("Submit").click()
    if driver.title != "LandstarOnline Home Page":
        success = False
        print("verifyTitle failed")
finally:
    driver.quit()
    if not success:
        raise Exception("Test failed.")

It runs, and has a visual load time of .9 seconds, so it is kicking off the first step of getting the URL, but I get no other errors, and the screenshot shows a fully loaded page with nothing entered into the text boxes.  I have also run this script throug Sauce OnDemand and it works as it should.  I had to rename the driver from wd=webdriver to just use driver, but other than that the same script works fine in Sauce.  Script output is below as well.

0.00s   [INFO]  Starting measurement [161012_MR_27ZB]
0.25s   [INFO]  Executing WebDriver script
20.25s  [ERROR] Script timed out after 20 seconds

Mayuresh_Kshirs
Path Finder

Are you still facing the issue? I created a job with the same script and a timeout of 100 and it fails in verification:

0.00s   [INFO]  Starting measurement [161116_RQ_5BTS]
0.15s   [INFO]  Executing WebDriver script
14.90s  [INFO]  verifyTitle failed
14.90s  [ERROR] Exception: Test failed.
Traceback (most recent call last):
Line 16, in <synthetic script>
	raise Exception("Test failed.")
0 Karma

CommunityUser
Splunk Employee
Splunk Employee

I'm sort of still having this issue.  The script failed for you because the username and password in the script I posted here are not valid.  

Support has responded to my ticket and acknowledged there is a bug right now with how our site scripting operates and how the synthetic job emulates IE 10 and 11.  The script works fine using Firefox or Chrome, so that's what we've done for now.  I was told that a bug was created and would be resolved in a future release.

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

Hi,

I am wondering if the script is unable to find a element by id or something else. because the script looks quite simple and stright, unless its stuck unable to execute a statement it should not take long..

Also, I wonder if you have checked the error log within AppDynamics controller? (USer Experiance > Sessions > open a failed script from the list > Show script output)

Alternatively, have you tried to execute the scipt outside of AppDynamics? like say Firfox..

0 Karma
Get Updates on the Splunk Community!

Celebrating Fast Lane: 2025 Authorized Learning Partner of the Year

At .conf25, Splunk proudly recognized Fast Lane as the 2025 Authorized Learning Partner of the Year. This ...

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...