我有此类(DoctorRegistrationTest.java),并具有全局变量doctorCode,doctorFirstName,doctorFamilyName)

@BeforeMethod(groups = {"BVT", "Regression"})
public void loadRmsPage() {
    loadRmsProfile();
    softAssert = new SoftAssert();
    doctorRegistrationPage = new DoctorRegistrationPage(webDriver);
}

@Epic("RMS - Create Doctor")
@Feature("RMS - Create Doctor functionality")
@Story("AUT-688")
@Severity(SeverityLevel.BLOCKER)
@Test(description = "Positive : Doctor Creation  ", groups = {"BVT", "Regression"})
public void createDoctorTestMethod() {
    do {
        doctorCode = String.valueOf(generateRandomNumber(1000, 9999));
    } while (false && doctorRegistrationPage.verifyCreatedDoctor(doctorCode));

    setDoctorRegistrationInformation();
    createDoctor();
}

public void createDoctor() {
    doctorRegistrationPage.loadDoctorRegistrationPage();
    doctorRegistrationPage.fillDoctorNameInformation(doctorCode, doctorFirstName, doctorFamilyName, doctorFirstNameInArabic, doctorFamilyNameInArabic);
    doctorRegistrationPage.fillDoctorGeneralInformation(dateOfBirth, joinDate, identityNo, expiryDate, gender, doctorTitle, employmentType, identityType);
    doctorRegistrationPage.fillDoctorContactInformation(mobileNumber, companyEmail);
    doctorRegistrationPage.fillDoctorOtherInformation(doctorInformationEnglish, doctorInformationArabic);
    doctorRegistrationPage.fillDoctorTiming(followUpDays, slotDurationMinutes);
    doctorRegistrationPage.fillDoctorHospitalsAndClinics(hospital, clinics);
    doctorRegistrationPage.fillDoctorDefaultProcedure(defaultProcedur, consultationProcedure);
    boolean result = doctorRegistrationPage.verifyCreatedDoctor(doctorCode);
    LOG.info("Return value of verifyCreatedDoctor method " + result);
    softAssert.assertTrue(result, "TEST FAILED - CREATED DOCTOR NOT LISTING IN THE GRID");
    softAssert.assertAll();
    doctorRegistrationPage.logOutUser();
}

public void setDoctorRegistrationInformation() {
    readPropertiesFile();
    setNames();
    setNumberValues();
    setDate();
}

public void setNames() {
    doctorFirstName = "AUT DN " + getRandomStringName(4);
    doctorFamilyName = "AUT DFN " + getRandomStringName(4);
    companyEmail = getRandomStringName(5) + "@aut.com";
    doctorInformationEnglish = getRandomStringName(6);
}



public String getRandomStringName(int randomStringLength) {
    return RandomStringUtils.randomAlphabetic(randomStringLength).toLowerCase();
}

public int generateRandomNumber(int low, int high) {
    return (new Random()).nextInt(high - low) + low;
}


}

我还有另一个类(DoctorScheduleTest.java),需要将(DoctorRegistrationTest.java)的doctorCode,doctorFirstName,doctorFamilyName传递给doctorSchedulePage.selectDoctorDropdown(doctor);方法,而不是对细节进行硬编码。必须传递这样的值(“ doctorCode:doctorFirstName doctorFamilyName)

private String doctor =" 8938: AUT DN gvgl AUT DFN wnrn ";


@BeforeMethod(groups = {"BVT", "Regression"})
public void loadRmsPage()
{
    loadRmsProfile();
    softAssert = new SoftAssert();
    doctorSchedulePage = new DoctorSchedulePage(webDriver);
}

@Epic("RMS")
@Feature("RMS - Create Doctor Schedule functionality")
@Story("AUT-835")
@Severity(SeverityLevel.BLOCKER)
@Test(description = "Positive : Doctor Schedule Creation", groups = {"BVT", "Regression"})
public void doctorScheduleCreationTestMethod()
{
    setTemplateName();
    createInitialSchedule();
    setSchedule();
    saveTemplate();
    setTemplate();
    setDateRange();
    generateSchedule();
}

public void createInitialSchedule()
{
    doctorSchedulePage.loadDoctorScheduleDashboard();
    doctorSchedulePage.selectHospitalDropDown(hospital);
    doctorSchedulePage.selectClinicDropDown(clinic);
    doctorSchedulePage.selectDoctorDropdown(doctor);
    doctorSchedulePage.fillTemplate(scheduleTemplateName);
}

public void setSchedule()
{
    doctorSchedulePage.sundaySchedule(startHourTime,startMinuteTime,startSchedule,endHourTime,endMinuteTime,endSchedule);
    doctorSchedulePage.mondaySchedule(startHourTime,startMinuteTime,startSchedule,endHourTime,endMinuteTime,endSchedule);
    doctorSchedulePage.tuesdaySchedule(startHourTime,startMinuteTime,startSchedule,endHourTime,endMinuteTime,endSchedule);
    doctorSchedulePage.wednesdaySchedule(startHourTime,startMinuteTime,startSchedule,endHourTime,endMinuteTime,endSchedule);
    doctorSchedulePage.thursdaySchedule(startHourTime,startMinuteTime,startSchedule,endHourTime,endMinuteTime,endSchedule);
    doctorSchedulePage.fridaySchedule(startHourTime,startMinuteTime,startSchedule,endHourTime,endMinuteTime,endSchedule);
    doctorSchedulePage.saturdaySchedule(startHourTime,startMinuteTime,startSchedule,endHourTime,endMinuteTime,endSchedule);
}

public void saveTemplate()
{
    doctorSchedulePage.saveTemplate();
}

public void setTemplate()
{
    doctorSchedulePage.selectTemplateDropdown(scheduleTemplateName);
}

public void setDateRange()
{
    doctorSchedulePage.selectScheduleDate(scheduleStartDate,scheduleEndDate);
}

public void generateSchedule()
{
    doctorSchedulePage.generateSchedule();
}

public int generateRandomNumber(int low, int high)
{
    return (new Random()).nextInt(high - low) + low;
}

public void setTemplateName()
{
    scheduleTemplateName = "Template " + getRandomStringName(3);
}

public String getRandomStringName(int randomStringLength)
{
    return RandomStringUtils.randomAlphabetic(randomStringLength).toLowerCase();
}


}

DoctorSchedulePage.java(selectDoctorDropdown方法)

public void selectDoctorDropdown(String doctorcode)
{
    selectValueFromDropDown(doctorDropdown, doctorcode);
}


BasePage.java(selectValueFromDropDown方法)

受保护的void selectValueFromDropDown(WebElement元素,字符串值){
if(value!= null &&!value.isEmpty()){

        waitForElementToPresent(element);

        Select dropdown = new Select(element);

        LOG.info("Selected "+value);

        dropdown.selectByVisibleText(value);
    }


}

最佳答案

首先,您的问题表明,将测试数据传递到测试中存在问题。首先应该解决这个问题。

由于这是另一个主题(也是一个更大的主题),所以我建议使用单独的类并结合医生的数据来解决。

public static class Doctor{
 public static String FirstName;
 public static String FamilyName;


在设置中初始化数据,并在需要时使用。

正如我之前所说,这不是最佳解决方案,因为测试数据应保留在测试之外,但现在可能会有所帮助。

10-04 22:17
查看更多