0% found this document useful (0 votes)
6 views2 pages

Automating Upload/Download Tests

The document contains Python code that utilizes Selenium for web automation and OpenPyXL for Excel operations. It demonstrates how to navigate to a website, download a file, update an Excel sheet with new values, and upload the modified file back to the website. The code also includes assertions to verify that the updated value matches the expected output.

Uploaded by

Sai Kiran Gsix
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Automating Upload/Download Tests

The document contains Python code that utilizes Selenium for web automation and OpenPyXL for Excel operations. It demonstrates how to navigate to a website, download a file, update an Excel sheet with new values, and upload the modified file back to the website. The code also includes assertions to verify that the updated value matches the expected output.

Uploaded by

Sai Kiran Gsix
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

rks

Your progress
Share
code download
1. import time
2. from selenium import webdriver
3. driver = [Link]()
4.
5.
6. [Link]("[Link]
7. driver.maximize_window()
8. print([Link])
9. print(driver.current_url)
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30. [Link](2)

excel operations code


1. #from [Link] import webdriver
2. from selenium import webdriver
3. from [Link] import By
4. from [Link] import WebDriverWait
5. from [Link] import expected_conditions
6. import openpyxl
7.
8.
9. def update_excel_data(filePath, searchTerm, colName, new_value):
10. book = openpyxl.load_workbook(filePath)
11. sheet = [Link]
12. Dict = {}
13.
14. for i in range(1,sheet.max_column+ 1):
15. if [Link](row=1,column=i).value == colName:
16. Dict["col"] = i
17.
18. for i in range(1,sheet.max_row+1):
19. for j in range(1, sheet.max_column+1):
20. if [Link](row=i,column= j).value == searchTerm:
21. Dict["row"] = i
22.
23. [Link](row=Dict["row"], column=Dict["col"]).value = new_value
24. [Link](file_path)
25.
26.
27.
28.
29.
30.
31.
32.
33.
34. file_path = "/Users/rahulshetty/downloads/[Link]"
35. fruit_name = "Apple"
36. newValue = "990"
37. driver = [Link]()
38. driver.implicitly_wait(5)
39. [Link]("[Link]
40. driver.find_element([Link], "downloadButton").click()
41.
42. #edit the excel with updated value
43. update_excel_data(file_path, fruit_name, "price", newValue)
44.
45. #upload
46. file_input = driver.find_element(By.CSS_SELECTOR,"input[type='file']")
47. file_input.send_keys(file_path)
48.
49. wait = WebDriverWait(driver,5)
50. toast_locator = (By.CSS_SELECTOR,".Toastify__toast-body div:nth-child(2)")
51. [Link](expected_conditions.visibility_of_element_located(toast_locator))
52. print(driver.find_element(*toast_locator).text)
53. priceColumn = driver.find_element([Link],"//div[text()='Price']").get_attribute("data-
column-id")
54. actual_price = driver.find_element([Link],"//div[text()='"+fruit_name+"']/parent::div/
parent::div/div[@id='cell-"+priceColumn+"-undefined']").text
55. assert actual_price == newValue
56.
57.
58.
59.

You might also like