generated_test_script.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from openpyxl import load_workbook
  4. import logging
  5. class RT_OppCreatePage:
  6. def __init__(self):
  7. self.driver = None
  8. def fillFieldsOnOppCreatePage(self, driver, path, logger, oppName, crID, closeDt, sellingCountryval, localCurrencyVal, IndustrySubSegmentValue, excelName, sheetName, row):
  9. self.driver = driver
  10. wb = load_workbook(excelName)
  11. ws = wb[sheetName]
  12. # Read data from Excel
  13. opp_data = ws[f'{oppName}{row}'].value
  14. crID_data = ws[f'{crID}{row}'].value
  15. close_date_data = ws[f'{closeDt}{row}'].value
  16. selling_country_data = ws[f'{sellingCountryval}{row}'].value
  17. local_currency_data = ws[f'{localCurrencyVal}{row}'].value
  18. industry_subsegment_data = ws[f'{IndustrySubSegmentValue}{row}'].value
  19. # Fill fields
  20. self.driver.find_element(By.ID, 'opportunity-name').send_keys(opp_data)
  21. self.driver.find_element(By.ID, 'customer-relationship').send_keys(crID_data)
  22. self.driver.find_element(By.ID, 'close-date').send_keys(close_date_data)
  23. self.driver.find_element(By.ID, 'sales-country').click()
  24. self.driver.find_element(By.XPATH, f'//option[text()="{selling_country_data}"]').click()
  25. self.driver.find_element(By.ID, 'local-currency').click()
  26. self.driver.find_element(By.XPATH, f'//option[text()="{local_currency_data}"]').click()
  27. self.driver.find_element(By.ID, 'industry-subsegment').click()
  28. self.driver.find_element(By.XPATH, f'//option[text()="{industry_subsegment_data}"]').click()
  29. logger.info("Fields filled successfully.")
  30. return self.driver
  31. def createOppFromCR(self, driver, path, logger, oppName, closeDt, localCurrencyVal, IndustrySubSegmentValue, excelName, sheetName, row):
  32. self.driver = driver
  33. wb = load_workbook(excelName)
  34. ws = wb[sheetName]
  35. # Read data from Excel
  36. opp_data = ws[f'{oppName}{row}'].value
  37. close_date_data = ws[f'{closeDt}{row}'].value
  38. local_currency_data = ws[f'{localCurrencyVal}{row}'].value
  39. industry_subsegment_data = ws[f'{IndustrySubSegmentValue}{row}'].value
  40. # Navigate to Opportunity Related List button
  41. self.driver.find_element(By.ID, 'opportunity-related-list-button').click()
  42. self.driver.find_element(By.ID, 'new-opportunity-button').click()
  43. # Fill opportunity form
  44. self.driver.find_element(By.ID, 'opportunity-name').send_keys(opp_data)
  45. self.driver.find_element(By.ID, 'local-currency').click()
  46. self.driver.find_element(By.XPATH, f'//option[text()="{local_currency_data}"]').click()
  47. self.driver.find_element(By.ID, 'close-date').send_keys(close_date_data)
  48. self.driver.find_element(By.ID, 'sales-country').click()
  49. self.driver.find_element(By.XPATH, f'//option[text()="{industry_subsegment_data}"]').click()
  50. logger.info("Opportunity created successfully.")
  51. return self.driver