繁体   English   中英

如何将全局变量从一个测试类传递到另一个测试类并在 selenium 的下拉列表中选择该值?

[英]How to pass the global variable from one Test class to another test class and select that value in a dropdown in selenium?

我有这个类( 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 ) 并且需要将 doctorCode 、 doctorFirstName 、 doctorFamilyName 从 (DoctorRegistrationTest.java ) 传递给 doctorSchedulePage.selectDoctorDropdown(doctor); 方法,而不是硬编码细节。 必须像这样传递值(“doctorCode:doctorFirstNamedoctorFamilyName)

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 方法)

protected void selectValueFromDropDown(WebElement element, String value) { 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;

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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