简体   繁体   中英

Performanance.timing values not changing for multiple requests in same page for page load time using python selenium

I am trying to get the page load times using python & selenium by executing javascript command performanance.timing

I am able to get the values properly when Navigate to another page but If I am doing a trnasaction/action from the same page whch will take me to another tab in the same page, the performanance.timing does not change.

Note: I am able to get the values changed if I reload the page

Can someone advise me on how I will get the load times of each step I do in my web app.

python selenium script:

from selenium import webdriver




driver = webdriver.Firefox()
driver.implicitly_wait(40)

########### Home Page #################
driver.get("http://app.edulastic.com")

navigationStart = driver.execute_script("return window.performance.timing.navigationStart")    
responseStart = driver.execute_script("return window.performance.timing.responseStart")
domComplete = driver.execute_script("return window.performance.timing.domComplete")


loadStart = driver.execute_script("return window.performance.timing.domInteractive")
loadend = driver.execute_script("return window.performance.timing.navigationStart")

backendPerformance = responseStart - navigationStart
frontendPerformance = domComplete - responseStart
loadingTime=loadStart-loadend

print ("Back End Homepage: %s" % backendPerformance)
print ("Front End Homepage: %s" % frontendPerformance)
print("loading time : %s" %loadingTime)

#################### Dashboard ##################

driver.find_element_by_id('login-email').send_keys("*****@gmail.com")
driver.find_element_by_id("login-password").send_keys("******")
driver.find_element_by_id("signIn").click()

driver.find_element_by_link_text("Create New Assignment")

navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")
domComplete = driver.execute_script("return window.performance.timing.domComplete")
domLoading = driver.execute_script("return window.performance.timing.domLoading")

loadStart = driver.execute_script("return window.performance.timing.domInteractive")
loadend = driver.execute_script("return window.performance.timing.navigationStart")


backendPerformance = responseStart - navigationStart
frontendPerformance = domComplete - responseStart
loadingTime=loadStart-loadend


#print("time converted ... %s" %time.strftime("%SSSS", time.gmtime(domLoading)))

print ("Back End Dashboard: %s" % backendPerformance)
print ("Front End Dashboard: %s" % frontendPerformance)
print("loading time : %s" %loadingTime)
#print("dom laoding time :%s" %domLoading)


########## create new assignment #########
driver.find_element_by_link_text("Create New Assignment").click()

print(driver.find_element_by_id("create-assessment-with-val").is_displayed())

loadStart = driver.execute_script("return window.performance.timing.domInteractive")
loadend = driver.execute_script("return window.performance.timing.navigationStart")

loadingTime = loadStart-loadend
print("loading time : %s" %loadingTime)


driver.quit()

create new Assignment section navigates to another tab on the side of the page but timing values doesn't change.

Image --

left side icons render another content when clicked

I know it's 5 years from the question but I just found out what the problem was when doing it today.

the "return window.performance.timing" function gets its information from the browser console. If you use the same function twice in the same window it will return the same numbers every time because it's the same widnow that is still open.

If you want to get new performance timing every time, you just refresh the window beforehands with driver.refresh()

After refresh just start with

navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")

and then continue with the code like you did before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM