簡體   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