Wir laden zukünftige Studenten des Java QA Automation Engineer- Kurses ein , an einer offenen Lektion zum Thema "HTTP. Postbote, Newman, Geiger (Charles), Curl, SOAP. SOAPUI" teilzunehmen.
Und jetzt empfehlen wir Ihnen, sich mit der Übersetzung von nützlichem Material vertraut zu machen.
Das Speichern von Testdaten erfordert normalerweise einen Datentyp, der:
ermöglicht die Deklaration mehrerer Eigenschaften;
hat minimales oder kein Verhalten;
Ermöglicht das einfache Erstellen mehrerer identischer Entitäten.
Die Objekte erfüllen fast diese Anforderungen. Um dann mehrere Entitäten zu erstellen, müssten jedoch mehrere Objekte mit wenigen Eigenschaften und minimalem Verhalten (oder gar keinem) erstellt werden. Mit minimalem Verhalten meine ich eine kleine Anzahl von Methoden. Grundsätzlich müssten Sie für jede Entität, die Sie benötigen, ein neues Objekt erstellen, was eine Verschwendung von Ressourcen darstellt. Stattdessen können Sie Enum
einen speziellen Objekttyp verwenden.
Enum
, , , . Enum
, . GitHub, . Enum
.
enum- Java :
, . : , , — , . .
, . , : , . , . Enum
. (), : AT, EE ES.
Enum
:
public enum Country {
AT("Austria", Arrays.asList("Vienna", "Salzburg", "Innsbruck"), 43),
EE("Estonia", Arrays.asList("Tallinn", "Haapsalu", "Tartu"), 372),
ES("Spain", Arrays.asList("Malaga","Madrid","Valencia","Corralejo"), 34);
public final String label;
public final List<String> cities;
public int phoneNumberPrefix;
Country(String label, List<String> cities, int phoneNumberPrefix) {
this.label = label;
this.cities = cities;
this.phoneNumberPrefix = phoneNumberPrefix;
}
}
, , . , label
, cities
phoneNumberPrefix
. : String
, List<String>
int
.
Enum
. , , AT
, : label
«», cities
(), : «», «» «», phoneNumberPrefix
«43».
, Enum
, : Country..
. : Country.AT.label
«». , Country
.
, , .
Page
:
@FindBy(css = "#country") private WebElement countryDropdown;
@FindBy(css = "#city") private WebElement cityDropdown;
@FindBy(css = "#phone") public WebElement phoneNumberField;
@FindBy(css = "[type='submit']") public WebElement submitButton;
public Select countrySelect() {
return new Select(countryDropdown);
}
public Select citySelect() {
return new Select(cityDropdown);
}
countrySelect()
Select
. citySelect()
Select
. WebElement phoneNumberField
.
, , - . GitHub, .
1.
, . , , 10 . :
, :
@Test
void selectCountryCityAndTypePhoneNumber() {
}
. , label
ES Enum
. : Country.ES.label
. :
page.countrySelect().selectByVisibleText(Country.ES.label);
, . : Country.ES.cities
. , ( ), : Country.ES.cities.get(2)
. :
page.citySelect().selectByVisibleText(Country.ES.cities.get(2));
, . Enum
: Country.ES.phoneNumberPrefix
. , 10 : Country.ES.phoneNumberPrefix + randomNumeric(8)
.
randomNumeric
, Apache Commons :
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
, . Maven pom.xml
( ):
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
:
@Test
void selectCountryCityAndTypePhoneNumber() {
page.countrySelect().selectByVisibleText(Country.ES.label);
page.citySelect().selectByVisibleText(Country.ES.cities.get(2));
page.phoneNumberField.sendKeys(Country.ES.phoneNumberPrefix + randomNumeric(8));
}
2.
, . : ( ), , . , - .
. , Enum
label
. , . , .
. , . , .
, Enum
. , , .
2, . (expected) . , label
Enum
, , . , - Selenium, , (String), . -, , . .
List<String> expectedCountries = new ArrayList<>();
expectedCountries.add("");
label
, Enum
. Enum
label
. Enum
, Country.values()
.
for (Country country : Country.values()) {
expectedCountries.add(country.label);
}
: «», «», «», «».
- (actual) . Select
, WebElements
, Select
. getText()
(option) .
List<String> actualCountries = new ArrayList<>();
for (WebElement option : page.countrySelect().getOptions()) {
actualCountries.add(option.getText());
}
, , , Enum . , .
Collections.sort(expectedCountries); Collections.sort(actualCountries); assertEquals(expectedCountries, actualCountries);
:
@Test
void checkCountries() {
List<String> expectedCountries = new ArrayList<>();
expectedCountries.add("");
for (Country country : Country.values()) {
expectedCountries.add(country.label);
}
List<String> actualCountries = new ArrayList<>();
for (WebElement option : page.countrySelect().getOptions()) {
actualCountries.add(option.getText());
}
Collections.sort(expectedCountries);
Collections.sort(actualCountries);
assertEquals(expectedCountries, actualCountries);
}
3.
. , . JavaScript, .
Enum
:
for (Country country : Country.values()) {
, for
, label
Enum
:
page.countrySelect().selectByVisibleText(country.label);
, , , . , , (actual) . -:
List<String> actualCities = new ArrayList<>();
for (WebElement option : page.citySelect().getOptions()) {
actualCities.add(option.getText());
}
. Enum List<String> cities
. , . addAll()
cities
.
List<String> expectedCities = new ArrayList<>();
expectedCities.add(0, "");
expectedCities.addAll(country.cities);
. , .
Collections.sort(expectedCities); Collections.sort(actualCities); assertEquals(expectedCities, actualCities);
, , , . . , . :
@Test
void checkCities() {
for (Country country : Country.values()) {
page.countrySelect().selectByVisibleText(country.label);
List<String> actualCities = new ArrayList<>();
for (WebElement option : page.citySelect().getOptions()) {
actualCities.add(option.getText());
}
List<String> expectedCities = new ArrayList<>();
expectedCities.add(0, "");
expectedCities.addAll(country.cities);
Collections.sort(expectedCities);
Collections.sort(actualCities);
assertEquals(expectedCities, actualCities);
}
}
, Enum
. GitHub:
!
"Java QA Automation Engineer".
"HTTP. Postman, newman, fiddler (charles), curl, SOAP. SOAPUI".