Как передать глобальную переменную из одного тестового класса в другой тестовый класс и выбрать это значение в раскрывающемся списке в селене?

У меня есть этот класс ( 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); вместо жесткого кодирования деталей. Должно передаваться такое значение ("docCode: 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)

protected void selectValueFromDropDown (элемент WebElement, строковое значение) { if (value != null && !value.isEmpty()) {

        waitForElementToPresent(element);

        Select dropdown = new Select(element);

        LOG.info("Selected "+value);

        dropdown.selectByVisibleText(value);   
    }

}


person Hanish    schedule 02.01.2020    source источник


Ответы (1)


Прежде всего, ваш вопрос указывает на то, что у вас есть проблема с передачей тестовых данных в тесты. Это надо решать в первую очередь.

Поскольку это другая тема (и гораздо большая), я бы порекомендовал обходной путь, используя отдельный класс с данными врача.

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

Инициализируйте данные в настройках и используйте их, когда вам нужно.

Как я уже говорил, это не лучшее решение, поскольку данные тестирования должны храниться вне тестов, но сейчас это может быть полезно.

person Jonah    schedule 02.01.2020
comment
Есть ли способ передать значения (FirstName, FamilyName) из DoctorRegistrationTest.java в метод выбора DoctorScheduleTest.java, кроме создания нового класса - person Hanish; 03.01.2020
comment
Если вы храните имя и фамилию в полях класса DoctorRegistrationTest, то вы можете получить их с помощью геттеров. - person Jonah; 04.01.2020