import moment from 'moment'; import { Button, Input, Label, WebElement } from '@contour/fet/lib/elements/index'; import { ContourBasePage } from '../../base/basePage'; import { ContourDatePicker } from '../../elements/contourDatePicker'; import { ContourFileUpload } from '../../elements/contourFileUpload'; import { ContourNumbericInput } from '../../elements/contourNumbericInput'; import { ContourSelect } from '../../elements/contourSelect'; import SHIPMENT_DATE_OR_PERIOD from '../../enum/shipmentDateOrPeriod'; import scenarioContext from '../../util/scenarioContext'; import locator from './dcForm.locator'; import * as contourFileUpload_1 from '../../elements/contourFileUpload'; import path from 'path'; import { ContourRadioGroup } from '../../elements/contourRadioGroup'; export default class DcForm extends ContourBasePage { constructor(url?: string) { super(locator, url); } getBackButton() { return new Button(this.getLocatorAsString('backButton')); } getApplicant() { return new Input(this.getLocatorAsString('applicant')); } getApplicantAddress() { return new Input(this.getLocatorAsString('applicantAddressInput')); } getBeneficiary() { return new ContourSelect(this.locators.beneficiary); } getBeneficiaryAddress() { return new Input(this.getLocatorAsString('beneficiaryAddressInput')); } getIssuingBank() { return new ContourSelect(this.getLocatorAsString('issuingBank')); } getIssuingBankAddress() { return new Input(this.getLocatorAsString('issuingBankAddress')); } getWaiverCheckBox() { return new WebElement(this.getLocatorAsString('waiverCheckBox')); } getPaymentAtSightCheckbox() { return new WebElement(this.getLocatorAsString('paymentAtSightCheckbox')); } getAdvisingBank() { return new ContourSelect(this.getLocatorAsString('advisingBank')); } getAdvisingBankAddress() { return new Input(this.getLocatorAsString('advisingBankAddressInput')); } getConfirmationInstructions() { return new ContourSelect(this.getLocatorAsString('confirmationInstructions')); } getConfirmingBank() { return new ContourSelect(this.getLocatorAsString('confirmingBank')); } getConfirmingBankAddress() { return new Input(this.getLocatorAsString('confirmingBankAddress')); } getAvailableByPaymentAtSightCheckBox() { return new Input(this.getLocatorAsString('availableByPaymentAtSightCheckBox')); } getAvailableByDeferredPaymentCheckBox() { return new Input(this.getLocatorAsString('availableByDeferredPaymentCheckBox')); } getDeferredPaymentDetailsInput() { return new Input(this.getLocatorAsString('deferredPaymentDetailsInput')); } getAvailableByAcceptanceCheckBox() { return new Input(this.getLocatorAsString('availableAcceptanceCheckBox')); } getAcceptanceDraftsAtInput() { return new Input(this.getLocatorAsString('acceptanceDraftsAtInput')); } getAcceptanceDraweeBankDropdown() { return new ContourSelect(this.getLocatorAsString('acceptanceDraweeBankDropdown')); } getAcceptanceDraweeBankAddressInput() { return new Input(this.getLocatorAsString('acceptanceDraweeBankAddressInput')); } getAvailableNegotiationCheckBox() { return new Button(this.getLocatorAsString('availableNegotiationCheckBox')); } getNegotiationPaymentDetailsCheckbox() { return new Button(this.getLocatorAsString('negotiationPaymentDetailsCheckbox')); } getNegotiationPaymentDetailsInput() { return new Input(this.getLocatorAsString('negotiationPaymentDetailsInput')); } getNegotiationDraftAtCheckbox() { return new Button(this.getLocatorAsString('negotiationDraftAtCheckbox')); } getNegotiationDraftsAtInput() { return new Input(this.getLocatorAsString('negotiationDraftsAtInput')); } getNegotiationDraweeBankDropdown() { return new ContourSelect(this.getLocatorAsString('negotiationDraweeBankDropdown')); } getNegotiationDraweeBankAddressInput() { return new Input(this.getLocatorAsString('negotiationDraweeBankAddressInput')); } getAvailableByPaymentConditions() { return new Input(this.getLocatorAsString('availableByPaymentConditions')); } getCreditAvailableWith() { return new ContourSelect(this.getLocatorAsString('creditAvailableWith')); } getNominatedBankAddress() { return new Input(this.getLocatorAsString('nominatedBankAddressInput')); } getApplicableRules() { return new ContourSelect(this.getLocatorAsString('applicableRules')); } getDescriptionOfApplicableRules() { return new Input(this.getLocatorAsString('descriptionOfApplicableRules')); } getAmountCurrency() { return new ContourSelect(this.getLocatorAsString('amountCurrency')); } getAmountInput() { return new ContourNumbericInput(this.getLocatorAsString('amountInput')); } getMaxTolerenceInput() { return new ContourNumbericInput(this.getLocatorAsString('maxTolerenceInput')); } getMinTolerenceInput() { return new ContourNumbericInput(this.getLocatorAsString('minTolerenceInput')); } getAdditionalAmountCoveredInput() { return new Input(this.getLocatorAsString('additionalAmountCoveredInput')); } getExpiryDate() { return new ContourDatePicker(this.getLocatorAsString('expiryDate')); } getIssuedDate() { return new WebElement(this.getLocatorAsString('issuedDate')); } getExpiryPlaceInput() { return new Input(this.getLocatorAsString('expiryPlaceInput')); } getPartialShipment() { return new ContourSelect(this.getLocatorAsString('partialShipments')); } getTranshipment() { return new ContourSelect(this.getLocatorAsString('transhipment')); } getLatestShipmentDate() { return new ContourDatePicker(this.getLocatorAsString('latestShipmentDate')); } getShipmentPeriodInput() { return new Input(this.getLocatorAsString('shipmentPeriodInput')); } getDescriptionOfGoodsAndServicesInput() { return new Input(this.getLocatorAsString('descriptionOfGoodsAndServicesInput')); } getPeriodOfPresentationInput() { return new Input(this.getLocatorAsString('periodOfPresentationInput')); } getTypeOfPresentationInput() { return new Input(this.getLocatorAsString('typeOfPresentationInput')); } getPlaceOfTakingInChargeInput() { return new Input(this.getLocatorAsString('placeOfTakingInChargeInput')); } getPortOfLoadingInput() { return new Input(this.getLocatorAsString('portOfLoadingInput')); } getPortOfDischarge() { return new Input(this.getLocatorAsString('portOfDischargeInput')); } getPlaceOfFinalDestinationInput() { return new Input(this.getLocatorAsString('placeOfFinalDestinationInput')); } getDocumentRequiredInvoiceCheckbox() { return new WebElement(this.getLocatorAsString('documentRequiredInvoiceCheckbox')); } getDocumentRequiredInvoiceDescription() { return new Input(this.getLocatorAsString('documentRequiredInvoiceDescriptionInput')); } getDocumentRequiredTransportDocumentCheckbox() { return new WebElement(this.getLocatorAsString('documentRequiredTransportDocumentCheckbox')); } getDocumentRequiredTransportType() { return new ContourSelect(this.getLocatorAsString('documentRequiredTransportType')); } getDocumentRequiredTransportSubtypeInput() { return new Input(this.getLocatorAsString('documentRequiredTransportSubtypeInput')); } getDocumentRequiredTransportDocumentDescription() { return new Input(this.getLocatorAsString('documentRequiredTransportDocumentDescriptionInput')); } getDocumentRequiredCertificateOfOriginCheckbox() { return new WebElement(this.getLocatorAsString('documentRequiredCertificateOfOriginCheckbox')); } getDocumentRequiredCertificateOfOriginInput() { return new Input(this.getLocatorAsString('documentRequiredCertificateOfOriginDescriptionInput')); } getDocumentRequiredPackingListCheckbox() { return new WebElement(this.getLocatorAsString('documentRequiredPackingListCheckbox')); } getDocumentRequiredPackingListDescription() { return new Input(this.getLocatorAsString('documentRequiredPackingListDescriptionInput')); } getDocumentRequiredAddOtherDocumentsButton() { return new Button(this.getLocatorAsString('documentRequiredAddOtherDocumentButton')); } getDocumentRequiredOtherDocumentsRequiredInput(rowNum: number) { return new Input( this.getLocatorAsString('doucmentRequiredOtherDocumentsRequiredInput').replace('#ROW#', rowNum.toString()) ); } getDocumentRequiredOtherDocumentsRequiredDescriptionInput(rowNum: number) { return new Input( this.getLocatorAsString('documentRequiredOtherDocumentsRequiredDescriptionInput').replace( '#ROW#', rowNum.toString() ) ); } getDocumentRequiredOtherDocumentRequiredRemoveButton(rowNum: number) { return new Button( this.getLocatorAsString('documentRequiredRemoveOtherDocumentsButton').replace('#ROW_NUM#', rowNum.toString()) ); } getDetailsOfChargesInput() { return new Input(this.getLocatorAsString('detailsOfChargesInput')); } getAdditionConditionsInput() { return new Input(this.getLocatorAsString('additionalConditionsInput')); } getattachmentUpload() { return new ContourFileUpload(this.getLocatorAsString('attachmentUpload')); } getAttachmentFileName(rowNum: number) { return new Label(this.getLocatorAsString('attachmentFileName').replace('#ROW_NUM#', rowNum.toString())); } getAttachmentRemoveButton(rowNum: number) { return new Button(this.getLocatorAsString('attachmentRemoveButton').replace('#ROW_NUM#', rowNum.toString())); } async checkRequiredFieldErrorCount(errorCount: number) { await new WebElement(this.getLocatorAsString('requiredFieldRow')).checkElementCount(errorCount); } async checkRequiredErrorFieldContainsError(errorMsg: string) { await new WebElement(this.locators.requiredFieldMsg.replace('#Message#', errorMsg)).checkIsDisplayed(); } async fill(data: IDCData, saveDc: boolean): Promise { await this.fillCorporateSection(data); await this.fillBanksSection(data); await this.fillKeyTermsSection(data); await this.fillShipmentDetailsSection(data); await this.uploadFiles(data); if (saveDc) { await new WebElement(this.locators.saveTemplate).clickElement(); } } async fillCorporateSection(data: IDCData): Promise { await this.getApplicantAddress().scroll(); data.APPLICANT_ADDRESS && (await this.getApplicantAddress().setInputField(data.APPLICANT_ADDRESS)); data.BENEFICIARY && (await this.getBeneficiary().selectOptionByVisibleText(data.BENEFICIARY)); data.BENEFICIARY_ADDRESS && (await this.getBeneficiaryAddress().setInputField(data.BENEFICIARY_ADDRESS)); } async fillBanksSection(data: IDCData): Promise { await this.getIssuingBank().scroll(); data.ISSUING_BANK && (await this.getIssuingBank().selectOptionByVisibleText(data.ISSUING_BANK, false)); data.ISSUING_BANK_ADDRESS && (await this.getIssuingBankAddress().setInputField(data.ISSUING_BANK_ADDRESS)); data.ADVISING_BANK && (await this.getAdvisingBank().selectOptionByVisibleText(data.ADVISING_BANK)); data.ADVISING_BANK_ADDRESS && (await this.getAdvisingBankAddress().setInputField(data.ADVISING_BANK_ADDRESS)); data.NEW_ADVISING_BANK && (await this.getAdvisingBank().selectOptionByVisibleText(data.NEW_ADVISING_BANK)); data.NEW_ADVISING_BANK_ADDRESS && (await this.getAdvisingBankAddress().setInputField(data.NEW_ADVISING_BANK_ADDRESS)); data.ALLOW_ISSUE_BANK_MAKE_CHANGES_DIRECTLY && (await this.getWaiverCheckBox().clickElement()); data.CONFIRMATION_INSTRUCTION && (await new ContourRadioGroup().clickOptionByLabel(data.CONFIRMATION_INSTRUCTION)); if (data.CONFIRMATION_INSTRUCTION != 'Without') { data.CONFIRMING_BANK && (await this.getConfirmingBank().selectOptionByVisibleText(data.CONFIRMING_BANK)); data.CONFIRMING_BANK_ADDRESS && (await this.getConfirmingBankAddress().setInputField(data.CONFIRMING_BANK_ADDRESS)); data.NEW_CONFIRMING_BANK && (await this.getConfirmingBank().selectOptionByVisibleText(data.NEW_CONFIRMING_BANK)); data.NEW_CONFIRMING_BANK_ADDRESS && (await this.getConfirmingBankAddress().setInputField(data.NEW_CONFIRMING_BANK_ADDRESS)); } // Available by data.AVAIABLE_BY_PAYMENT_AT_SIGHT && (await new ContourRadioGroup().clickOptionByLabel('Available at sight')); if (data.AVAIABLE_BY_DEFERRED_PAYMENT) { await new ContourRadioGroup().clickOptionByLabel('Deferred payment'); data.DEFERRED_PAYMENT_DETAILS && (await this.getDeferredPaymentDetailsInput().setInputField(data.DEFERRED_PAYMENT_DETAILS)); } if (data.AVAIABLE_BY_ACCEPTANCE) { await new ContourRadioGroup().clickOptionByLabel('Acceptance'); data.ACCEPTANCE_DRAFT_AT && (await this.getAcceptanceDraftsAtInput().setInputField(data.ACCEPTANCE_DRAFT_AT)); data.ACCEPTANCE_DRAWEE_BANK && (await this.getAcceptanceDraweeBankDropdown().selectOptionByVisibleText(data.ACCEPTANCE_DRAWEE_BANK)); data.ACCEPTANCE_DRAWEE_BANK_ADDRESS && (await this.getAcceptanceDraweeBankAddressInput().setInputField(data.ACCEPTANCE_DRAWEE_BANK_ADDRESS)); } if (data.AVAIABLE_BY_NEGOTIATION) { await new ContourRadioGroup().clickOptionByLabel('Negotiation'); if (data.NEGOTIATION_PAYMENT_DETAILS_CHECK) { await new ContourRadioGroup().clickOptionByLabel('Negotiation payment details'); data.NEGOTIATION_PAYMENT_DETAILS && (await this.getNegotiationPaymentDetailsInput().setInputField(data.NEGOTIATION_PAYMENT_DETAILS)); } else if (data.NEGOTIATION_DRAFT_AT_CHECK) { await new ContourRadioGroup().clickOptionByLabel('Draft at'); data.NEGOTIATION_DRAFTS_AT && (await this.getNegotiationDraftsAtInput().setInputField(data.NEGOTIATION_DRAFTS_AT)); data.NEGOTIATION_DRAWEE_BANK && (await this.getNegotiationDraweeBankDropdown().selectOptionByVisibleText(data.NEGOTIATION_DRAWEE_BANK)); data.NEGOTIATION_DRAWEE_BANK_ADDRESS && (await this.getNegotiationDraweeBankAddressInput().setInputField(data.NEGOTIATION_DRAWEE_BANK_ADDRESS)); } } data.AVAIABLE_BY_PAYMENT_CONDITIONS && (await this.getAvailableByPaymentConditions().setInputField(data.AVAIABLE_BY_PAYMENT_CONDITIONS)); data.AVAIABLE_WITH_BANK && (await this.getCreditAvailableWith().selectOptionByVisibleText(data.AVAIABLE_WITH_BANK)); if (data.AVAIABLE_WITH_BANK != 'Any bank' && data.AVAIABLE_WITH_BANK_ADDRESS) { await this.getNominatedBankAddress().setInputField(data.AVAIABLE_WITH_BANK_ADDRESS); } } async fillKeyTermsSection(data: IDCData): Promise { await this.getApplicableRules().scroll(); data.APPLIABLE_RULES && (await this.getApplicableRules().selectOptionByVisibleText(data.APPLIABLE_RULES)); data.DESCRIPTION_OF_APPLICABLE_RULES && (await this.getDescriptionOfApplicableRules().setInputField(data.DESCRIPTION_OF_APPLICABLE_RULES)); data.SELECTED_CURRENCY && (await this.getAmountCurrency().selectOptionByVisibleText(data.SELECTED_CURRENCY)); data.AMOUNT && (await this.getAmountInput().setInputField(data.AMOUNT)); data.MAX_TOLERANCE && (await this.getMaxTolerenceInput().setInputField(data.MAX_TOLERANCE)); data.MIN_TOLERANCE && (await this.getMinTolerenceInput().setInputField(data.MIN_TOLERANCE)); data.ADDITIONAL_AMOUNT_COVERED && (await this.getAdditionalAmountCoveredInput().setInputField(data.ADDITIONAL_AMOUNT_COVERED)); const ranDate = scenarioContext().dc.randomDate; if (data.EXPIRY_DATE_YYMMDD) { if (data.EXPIRY_DATE_YYMMDD == '#RANDOM_DATE#') { await this.getExpiryDate().selectDate(moment(ranDate, 'YYYY-MM-DD')); } else { await this.getExpiryDate().selectDate( moment(data.EXPIRY_DATE_YYMMDD, 'YYYY-MM-DD'), moment(await this.getExpiryDate().getText(), 'YY/MM/DD').format('YYYY-MM-DD') ); } } data.EXPIRY_PLACE && (await this.getExpiryPlaceInput().setInputField(data.EXPIRY_PLACE)); } async fillShipmentDetailsSection(data: IDCData): Promise { await this.getPartialShipment().scroll(); data.PARTIAL_SHIPMENTS && (await this.getPartialShipment().selectOptionByVisibleText(data.PARTIAL_SHIPMENTS, false)); data.TRANSHIPMENT && (await this.getTranshipment().selectOptionByVisibleText(data.TRANSHIPMENT, false)); data.SHIPMENT_DATE_PERIOD && (await new ContourRadioGroup().clickOptionByLabel(data.SHIPMENT_DATE_PERIOD)); if (data.SHIPMENT_DATE_PERIOD == SHIPMENT_DATE_OR_PERIOD.LATEST_DATE_OF_SHIPMENT) { await this.getLatestShipmentDate().selectDate(moment(data.LATEST_DATE_OF_SHIPMENT, 'YYYY-MM-DD')); } else if (data.SHIPMENT_DATE_PERIOD == SHIPMENT_DATE_OR_PERIOD.SHIPMENT_PERIOD) { await this.getShipmentPeriodInput().setInputField(data.SHIPMENT_PERIOD); } data.DESCRIPTION_OF_GOODS_SERVICES && (await this.getDescriptionOfGoodsAndServicesInput().setInputField(data.DESCRIPTION_OF_GOODS_SERVICES)); data.PERIOD_OF_PRESENTATION && (await this.getPeriodOfPresentationInput().setInputField(data.PERIOD_OF_PRESENTATION)); data.TYPE_OF_PRESENTATION && (await this.getTypeOfPresentationInput().setInputField(data.TYPE_OF_PRESENTATION)); data.PLACE_OF_TAKING && (await this.getPlaceOfTakingInChargeInput().setInputField(data.PLACE_OF_TAKING)); data.PORT_OF_LOADING && (await this.getPortOfLoadingInput().setInputField(data.PORT_OF_LOADING)); data.PORT_OF_DISCHARGE && (await this.getPortOfDischarge().setInputField(data.PORT_OF_DISCHARGE)); data.PLACE_OF_FINAL_DESTINATION && (await this.getPlaceOfFinalDestinationInput().setInputField(data.PLACE_OF_FINAL_DESTINATION)); } async fillDocumentSource(dataTable: any): Promise { const data = dataTable.rowsHash(); if (data['Tick - Invoice'] != '') { await new ContourRadioGroup().clickOptionByLabel('Invoice'); await this.getDocumentRequiredInvoiceDescription().setInputField(data['Invoice Description']); if (data['Tick - Transport Document'] != '') { await new ContourRadioGroup().clickOptionByLabel('Transport document'); await this.getDocumentRequiredTransportType().selectOptionByVisibleText( data['Select Transport Document'], false ); if (data['Select Transport Document'] == 'Other') { await this.getDocumentRequiredTransportSubtypeInput().setInputField(data['Other Transport Document']); } await this.getDocumentRequiredTransportDocumentDescription().setInputField( data['Transport Document Description'] ); } if (data['Tick - Certificate of Origin'] != '') { await new ContourRadioGroup().clickOptionByLabel('Certificate of origin'); await this.getDocumentRequiredCertificateOfOriginInput().setInputField( data['Certificate of Origin Description'] ); } if (data['Tick - Packing List'] != '') { await new ContourRadioGroup().clickOptionByLabel('Packing list'); await this.getDocumentRequiredPackingListDescription().setInputField(data['Packing List Description']); } for (let i = 0; i < data['Other Required Document Count']; i++) { await this.getDocumentRequiredAddOtherDocumentsButton().clickElement(); const otherDocName = data['Other Required Document Names'].split(','); const otherDocDesc = data['Other Required Document Descriptions'].split(','); await this.getDocumentRequiredOtherDocumentsRequiredInput(i).setInputField(otherDocName[i]); await this.getDocumentRequiredOtherDocumentsRequiredDescriptionInput(i).setInputField(otherDocDesc[i]); } } } async fillAvailableBy(dataTable: any) { const data = dataTable.rowsHash(); if (data['Tick - Payment at sight'] != '') { await this.getPaymentAtSightCheckbox().clickElement(); } } async uploadFiles(data: IDCData): Promise { if (data.ATTACHMENTS) { const fullPath = path.join(process.cwd() + '/test/resources', data.ATTACHMENTS); const contourFileUpload = new contourFileUpload_1.ContourFileUpload(this.locators.attachmentUpload); const remoteFilePath = await browser.uploadFile(fullPath); await contourFileUpload.uploadFile(remoteFilePath); } } }