|
1 | 1 | import Page from '../page.js'; |
2 | | -import apiHelper from '../../helper/api-helper'; |
| 2 | +import apiHelper from '../../../helper/api-helper.js'; |
3 | 3 |
|
4 | 4 | class FormPage extends Page { |
5 | 5 |
|
6 | 6 | get openHomeButton(){ return $(`//button[normalize-space()='Open Home Page']`) }; |
7 | 7 |
|
8 | 8 |
|
9 | | - async clickOpenHomeButton(){ |
10 | | - const elmOpenHomeButton = await this.openHomeButton; |
11 | | - await this.click(elmOpenHomeButton); |
12 | | - } |
| 9 | + |
13 | 10 |
|
14 | | - RANDOM_USER_API_URL="https://random-data-api.com" |
15 | | -RANDOM_USER_API_ENDPOINT="/api/users/random_user" |
16 | 11 | userInfo = apiHelper.GET(process.env.RANDOM_USER_API_URL, process.env.RANDOM_USER_API_ENDPOINT, '', {}) |
17 | | - friendlyName = '' |
18 | 12 | firstName = '' |
19 | 13 | lastName = '' |
20 | | - birthDate = '' |
21 | | - gender = '' |
22 | | - maritalStatus = '' |
23 | | - phoneCountryCode = '' |
24 | | - phoneNumber = '' |
25 | 14 | email = '' |
| 15 | + phoneCountry = '' |
| 16 | + phoneNumber = '' |
26 | 17 | addressLine1 = '' |
27 | | - country = '' |
28 | | - province = '' |
29 | | - city = '' |
| 18 | + addressLine2 = '' |
| 19 | + state = '' |
30 | 20 | postalCode = '' |
31 | | - workAvailability = '' |
32 | | - currentSalaryCurrency = '' |
33 | | - currentSalary = '' |
34 | | - expectedSalaryCurrency = '' |
35 | | - expectedSalary = '' |
| 21 | + country = '' |
| 22 | + birthDate = '' |
| 23 | + gender = '' |
36 | 24 |
|
37 | 25 | async initializeRandomData() { |
38 | 26 | const apiRawResult = await this.userInfo; |
39 | 27 | const apiResult = apiRawResult.body; |
40 | | - this.friendlyName = 'Auto' + apiResult.first_name + this.randomString(5); |
41 | | - this.firstName = apiResult.first_name |
42 | | - this.lastName = 'Automation' |
43 | | - this.birthDate = apiResult.date_of_birth |
44 | | - this.gender = 'Male' |
45 | | - this.maritalStatus = 'Single' |
46 | | - this.phoneCountryCode = '+63' |
47 | | - this.phoneNumber = '' + await this.getRandomInt(9000000000, 9999999999) |
| 28 | + //for dates we can use moment.js but for this case we will use browser keys so random int is used |
| 29 | + const randomMonth = await this.getRandomInt(1, 11); |
| 30 | + const randomDay = await this.getRandomInt(1, 27); |
| 31 | + const randomYear = await this.getRandomInt(1960, 2010); |
| 32 | + |
| 33 | + this.firstName = apiResult.first_name; |
| 34 | + this.lastName = apiResult.last_name; |
| 35 | + this.birthDate = ''+randomMonth+randomDay+randomYear; |
| 36 | + this.gender = 'Male'; |
| 37 | + this.phoneCountry = 'PH'; |
| 38 | + this.phoneNumber = '' + await this.getRandomInt(9000000000, 9999999999); |
48 | 39 | this.email = apiResult.username + await this.getRandomInt(1000, 9999) + '@email.com'; |
49 | | - this.addressLine1 = apiResult.address.street_address |
50 | | - this.country = 'Philippines' |
51 | | - this.province = 'Pampanga' |
52 | | - this.city = 'Angeles City' |
53 | | - this.postalCode = '1234' |
54 | | - this.workAvailability = 'Immediate' |
55 | | - this.currentSalaryCurrency = 'PHP' |
56 | | - this.currentSalary = '30000' |
57 | | - this.expectedSalaryCurrency = 'PHP' |
58 | | - this.expectedSalary = '60000' |
| 40 | + this.addressLine1 = apiResult.address.street_address; |
| 41 | + this.addressLine2 = apiResult.address.street_name; |
| 42 | + this.country = apiResult.country; |
| 43 | + this.state = apiResult.address.state; |
| 44 | + this.postalCode = '' + await this.getRandomInt(1000, 9999); |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + get firstNameInput(){ return $(`//input[@id='firstname']`) }; |
| 49 | + get lastNameInput(){ return $(`//input[@id='lasttname']`) }; |
| 50 | + get emailInput(){ return $(`//input[@id='email']`) }; |
| 51 | + get countryCodeSelect(){ return $(`//div[@class='select']//select`) }; |
| 52 | + get phoneNumberInput(){ return $(`//input[@id='Phno']`) }; |
| 53 | + get addressLine1Input(){ return $(`//input[@id='Addl1']`) }; |
| 54 | + get addressLine2Input(){ return $(`//input[@id='Addl2']`) }; |
| 55 | + get stateInput(){ return $(`//input[@id='state']`) }; |
| 56 | + get postalCodeInput(){ return $(`//input[@id='postalcode']`) }; |
| 57 | + get countrySelect(){ return $(`//label[normalize-space()='Country']//following-sibling::div//select`) }; |
| 58 | + get dateOfBirthInput(){ return $(`//input[@id='Date']`) }; |
| 59 | + get genderRadio(){ return $(`//input[@id='male']`) }; |
| 60 | + get checkTerms(){ return $(`//input[@type='checkbox']`) }; |
| 61 | + get submitButton(){ return $(`//input[@type='submit']`) }; |
| 62 | + |
| 63 | + async inputFirstName(){ |
| 64 | + const elmFirstNameInput = await this.firstNameInput; |
| 65 | + await this.inputText(elmFirstNameInput,this.firstName); |
| 66 | + } |
| 67 | + |
| 68 | + async inputLastName(){ |
| 69 | + const elmLastNameInput = await this.lastNameInput; |
| 70 | + await this.inputText(elmLastNameInput,this.lastName); |
| 71 | + } |
| 72 | + |
| 73 | + async inputEmail(){ |
| 74 | + const elmEmailInput = await this.emailInput; |
| 75 | + await elmEmailInput.clearValue(); |
| 76 | + await this.inputText(elmEmailInput,this.email); |
| 77 | + } |
| 78 | + |
| 79 | + async selectCountryCode(){ |
| 80 | + const elmCountryCodeSelect = await this.countryCodeSelect; |
| 81 | + await this.click(elmCountryCodeSelect); |
| 82 | + await browser.keys(this.phoneCountry); |
| 83 | + await browser.keys('Enter') |
| 84 | + } |
| 85 | + |
| 86 | + async inputPhoneNumber(){ |
| 87 | + const elmPhoneNumberInput = await this.phoneNumberInput; |
| 88 | + await this.inputText(elmPhoneNumberInput,this.phoneNumber); |
| 89 | + } |
| 90 | + |
| 91 | + async inputAddressLine1(){ |
| 92 | + const elmAddressLine1Input = await this.addressLine1Input; |
| 93 | + await this.inputText(elmAddressLine1Input,this.addressLine1); |
| 94 | + } |
| 95 | + |
| 96 | + async inputAddressLine2(){ |
| 97 | + const elmAddressLine2Input = await this.addressLine2Input; |
| 98 | + await this.inputText(elmAddressLine2Input,this.addressLine2); |
| 99 | + } |
| 100 | + |
| 101 | + async inputState(){ |
| 102 | + const elmStateInput = await this.stateInput; |
| 103 | + await this.inputText(elmStateInput,this.state); |
| 104 | + } |
| 105 | + |
| 106 | + async inputPostalCode(){ |
| 107 | + const elmPostalCodeInput = await this.postalCodeInput; |
| 108 | + await this.inputText(elmPostalCodeInput,this.postalCode); |
| 109 | + } |
| 110 | + |
| 111 | + async selectCountry(){ |
| 112 | + const elmCountrySelect = await this.countrySelect; |
| 113 | + await elmCountrySelect.selectByVisibleText('Philippines'); |
| 114 | + } |
| 115 | + |
| 116 | + async inputDateOfBirth(){ |
| 117 | + const elmDateOfBirthInput = await this.dateOfBirthInput; |
| 118 | + await this.click(elmDateOfBirthInput); |
| 119 | + await browser.keys(this.birthDate); |
| 120 | + } |
| 121 | + |
| 122 | + async selectGender(){ |
| 123 | + const elmGenderRadio = await this.genderRadio; |
| 124 | + await this.click(elmGenderRadio); |
| 125 | + } |
| 126 | + |
| 127 | + async selectTermsAndConditions(){ |
| 128 | + const elmcheckTerms = await this.checkTerms; |
| 129 | + await this.click(elmcheckTerms); |
| 130 | + } |
| 131 | + |
| 132 | + async clickSubmit(){ |
| 133 | + const elmSubmitButton = await this.submitButton; |
| 134 | + await this.click(elmSubmitButton); |
59 | 135 | } |
60 | 136 |
|
61 | 137 | } |
|
0 commit comments