genlitex 1 mese fa
parent
commit
17310f4c58
2 ha cambiato i file con 43 aggiunte e 61 eliminazioni
  1. 43 0
      automation_code/AutomationCodeGenerator.java
  2. 0 61
      generated_test_script.py

+ 43 - 0
automation_code/AutomationCodeGenerator.java

@@ -0,0 +1,43 @@
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+public class AutomationCodeGenerator {
+
+    public WebDriver fillFieldsOnOppCreatePage(WebDriver driver, String path, Logger logger, String oppName, String crID, String closeDt, String sellingCountryval, String localCurrencyVal, String IndustrySubSegmentValue) {
+        // Data Preparation
+        // Get input data from Excel
+        // Implement the logic for filling fields on the "Create Opportunity" page based on the pseudo code provided
+
+        // Step 1: Fill Opportunity Name
+        WebElement opportunityNameField = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("opportunityName")));
+        opportunityNameField.sendKeys(oppName);
+
+        // Step 2: Fill Customer Relationship
+        WebElement customerRelationshipField = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("customerRelationship")));
+        customerRelationshipField.sendKeys(crID);
+        customerRelationshipField.sendKeys(Keys.RETURN); // Trigger autocomplete or dropdown selection
+        new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeSelected(By.cssSelector("option[value='" + crID + "']")));
+
+        // Step 3: Fill Close Date
+        WebElement closeDateField = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("closeDate")));
+        closeDateField.sendKeys(closeDt);
+
+        // Step 4: Select Selling Country
+        ((JavascriptExecutor) driver).executeScript("document.querySelector('#sellingCountry').click();");
+        new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("option[value='" + sellingCountryval + "']"))).click();
+
+        // Step 5: Select Local Currency
+        ((JavascriptExecutor) driver).executeScript("document.querySelector('#localCurrency').click();");
+        new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("option[value='" + localCurrencyVal + "']"))).click();
+
+        // Step 6: Select Industry Sub Segment
+        ((JavascriptExecutor) driver).executeScript("document.querySelector('#industrySubSegment').click();");
+        new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("option[value='" + IndustrySubSegmentValue + "']"))).click();
+
+        // Return modified WebDriver instance
+        return driver;
+    }
+}

+ 0 - 61
generated_test_script.py

@@ -1,61 +0,0 @@
-from selenium import webdriver
-from selenium.webdriver.common.by import By
-from openpyxl import load_workbook
-import logging
-
-class RT_OppCreatePage:
-    def __init__(self):
-        self.driver = None
-
-    def fillFieldsOnOppCreatePage(self, driver, path, logger, oppName, crID, closeDt, sellingCountryval, localCurrencyVal, IndustrySubSegmentValue, excelName, sheetName, row):
-        self.driver = driver
-        wb = load_workbook(excelName)
-        ws = wb[sheetName]
-        
-        # Read data from Excel
-        opp_data = ws[f'{oppName}{row}'].value
-        crID_data = ws[f'{crID}{row}'].value
-        close_date_data = ws[f'{closeDt}{row}'].value
-        selling_country_data = ws[f'{sellingCountryval}{row}'].value
-        local_currency_data = ws[f'{localCurrencyVal}{row}'].value
-        industry_subsegment_data = ws[f'{IndustrySubSegmentValue}{row}'].value
-        
-        # Fill fields
-        self.driver.find_element(By.ID, 'opportunity-name').send_keys(opp_data)
-        self.driver.find_element(By.ID, 'customer-relationship').send_keys(crID_data)
-        self.driver.find_element(By.ID, 'close-date').send_keys(close_date_data)
-        self.driver.find_element(By.ID, 'sales-country').click()
-        self.driver.find_element(By.XPATH, f'//option[text()="{selling_country_data}"]').click()
-        self.driver.find_element(By.ID, 'local-currency').click()
-        self.driver.find_element(By.XPATH, f'//option[text()="{local_currency_data}"]').click()
-        self.driver.find_element(By.ID, 'industry-subsegment').click()
-        self.driver.find_element(By.XPATH, f'//option[text()="{industry_subsegment_data}"]').click()
-        
-        logger.info("Fields filled successfully.")
-        return self.driver
-
-    def createOppFromCR(self, driver, path, logger, oppName, closeDt, localCurrencyVal, IndustrySubSegmentValue, excelName, sheetName, row):
-        self.driver = driver
-        wb = load_workbook(excelName)
-        ws = wb[sheetName]
-        
-        # Read data from Excel
-        opp_data = ws[f'{oppName}{row}'].value
-        close_date_data = ws[f'{closeDt}{row}'].value
-        local_currency_data = ws[f'{localCurrencyVal}{row}'].value
-        industry_subsegment_data = ws[f'{IndustrySubSegmentValue}{row}'].value
-        
-        # Navigate to Opportunity Related List button
-        self.driver.find_element(By.ID, 'opportunity-related-list-button').click()
-        self.driver.find_element(By.ID, 'new-opportunity-button').click()
-        
-        # Fill opportunity form
-        self.driver.find_element(By.ID, 'opportunity-name').send_keys(opp_data)
-        self.driver.find_element(By.ID, 'local-currency').click()
-        self.driver.find_element(By.XPATH, f'//option[text()="{local_currency_data}"]').click()
-        self.driver.find_element(By.ID, 'close-date').send_keys(close_date_data)
-        self.driver.find_element(By.ID, 'sales-country').click()
-        self.driver.find_element(By.XPATH, f'//option[text()="{industry_subsegment_data}"]').click()
-        
-        logger.info("Opportunity created successfully.")
-        return self.driver