Kami mengundang siswa masa depan kursus Java QA Automation Engineer untuk mengambil bagian dalam pelajaran terbuka dengan topik "HTTP. Postman, newman, fiddler (charles), curl, SOAP. SOAPUI".
Dan sekarang kami menyarankan agar Anda membiasakan diri dengan terjemahan materi yang bermanfaat.
Menyimpan data pengujian biasanya membutuhkan tipe data yang:
memungkinkan beberapa properti untuk dideklarasikan;
memiliki perilaku minimal atau tidak sama sekali;
memungkinkan Anda membuat beberapa entitas identik dengan mudah.
Benda-benda tersebut hampir memenuhi persyaratan ini. Tetapi kemudian, untuk membuat beberapa entitas, perlu untuk membuat beberapa objek dengan sejumlah kecil properti dan perilaku minimal (atau tidak sama sekali). Yang saya maksud dengan perilaku minimal adalah sejumlah kecil metode. Pada dasarnya, untuk setiap entitas yang Anda butuhkan, Anda harus membuat objek baru, yang membuang-buang sumber daya. Sebagai gantinya, Anda dapat menggunakan Enum
objek dengan tipe khusus.
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".