print.SLNonDomesticTest.java Source code

Java tutorial

Introduction

Here is the source code for print.SLNonDomesticTest.java

Source

package print;

import com.stamps.print.shipto.CountryEnum;
import com.stamps.print.helpers.beans.CustomsAddItemBean;
import com.stamps.print.helpers.beans.CustomsInformationBean;
import com.stamps.print.helpers.beans.ShippingLabelBean;
import com.stamps.print.printon.PrintOnEnum;
import com.stamps.print.sl.ShippingLabelModule;
import com.stamps.print.customs.PackageContents;
import com.stamps.print.sl.enums.SLPrintOnSideEnum;
import com.stamps.print.sl.enums.SLServiceEnum;
import org.openqa.selenium.Keys;
import org.testng.Assert;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

/**
 * Stamps.com Automated Test Framework
 * Created by Robert Cruz
 * Username: rcruz
 * Date:  01/05/2015.
 */
public class SLNonDomesticTest extends PrintBaseTest {

    @Parameters({ "browser", "printURL", "username", "password" })
    public SLNonDomesticTest(String browser, String url, String username, String password) {
        super(browser, url, username, password);
    }

    @Test(groups = { "regression" })
    public void _APO_Test() {
        boolean pass = true;
        testHelper.beginTest();
        try {
            printHelper.getWebPostagePage().ensureUserIsSignedIn();
            // test parameters
            String sendToStreetNumberAndName = "Unit 15324";
            String sendToCityStateZip = "APO, AP 96205-5324";
            String addressStr = sendToInfo + Keys.ENTER + sendToStreetNumberAndName + Keys.ENTER
                    + sendToCityStateZip;

            ShippingLabelBean paramBean = new ShippingLabelBean();
            paramBean.setPrintOn(PrintOnEnum.SHIPPING_LABEL_8X11.toString());
            paramBean.setShippingLabelService(SLServiceEnum.PM_PACKAGE.toString());
            paramBean.setPrintOnPaperSide(SLPrintOnSideEnum.RIGHT.toString());
            paramBean.setRecipientInfo(sendToInfo);
            paramBean.setAddress(addressStr);
            paramBean.setPounds(0);
            // total ounces needs to add up with each add item ounces.
            paramBean.setOunces(2);
            //paramBean.setTracking(ShippingLabelTracking.USPS_TRACKING.toString());
            // paramBean.setStampsInsuranceAmount(150);
            paramBean.setCheckHidePostageValue(false);
            paramBean.setPrintReceiptCheckbox(true);
            paramBean.setPrintReferenceNumberCheckbox(true);
            paramBean.setReferenceNumber(testHelper.getTestName());

            CustomsInformationBean customsInformationBean = new CustomsInformationBean();
            customsInformationBean.setPackageContents(PackageContents.COMMERCIAL_SAMPLE.toString());
            customsInformationBean.setLicenseNumber("LIC12345");
            customsInformationBean.setCertificateNumber("CERT12345");
            customsInformationBean.setInvoiceNumber("INV123455");
            customsInformationBean.setMoreInfo(sendToInfo);
            customsInformationBean.setiAgreeToTheUSPSPrivacyActStatement(true);

            CustomsAddItemBean addItemBean = new CustomsAddItemBean();
            addItemBean.setDescription(sendToInfo);
            addItemBean.setPounds(0);
            addItemBean.setOunces(1);
            addItemBean.setQuantity(1);
            addItemBean.setValue(1);
            addItemBean.setHsTariff("US Tariff");

            CustomsAddItemBean addItemBean2 = new CustomsAddItemBean();
            addItemBean2.setDescription(sendToInfo);
            addItemBean2.setPounds(0);
            addItemBean2.setOunces(1);
            addItemBean2.setQuantity(1);
            addItemBean2.setValue(1);
            addItemBean2.setHsTariff("US Tariff");

            printHelper.setShippingLabelForm(paramBean, customsInformationBean, addItemBean, addItemBean2);

            printHelper.printPostage(paramBean);

        } catch (Exception e) {
            testHelper.logErrorTagStart();
            errorMessage = e.getMessage();
            pass = false;
            testHelper.logError(errorMessage);
            captureScreenShot(String.format("%s_FAIL_%s", testHelper.getTestName(), errorMessage));
            e.printStackTrace();
            testHelper.logErrorTagEnd();
        }

        //set delivery country back to US
        try {
            ShippingLabelModule printForm = printHelper.getWebPostagePage().getPrintModule().printOn()
                    .shippingLabel8x11();
            printForm.setShipToCountry(CountryEnum.UNITED_STATES);
        } catch (Exception e) {
            //do nothing...
        }

        Assert.assertTrue(pass, String.format("%s: %s ", testHelper.getTestName(), errorMessage));
        testHelper.endTest();
    }

    @Test(groups = { "regression" })
    public void _DPO_Test() {
        boolean pass = true;
        testHelper.beginTest();
        try {
            printHelper.getWebPostagePage().ensureUserIsSignedIn();
            // test parameters
            String sendToStreetNumberAndName = "Unit 8400, Box 0000";
            String sendToCityStateZip = "DPO AE 09498-9997";
            String addressStr = sendToInfo + Keys.ENTER + sendToStreetNumberAndName + Keys.ENTER
                    + sendToCityStateZip;

            ShippingLabelBean paramBean = new ShippingLabelBean();
            paramBean.setPrintOn(PrintOnEnum.SHIPPING_LABEL_8X11.toString());
            paramBean.setShippingLabelService(SLServiceEnum.PM_PACKAGE.toString());
            paramBean.setPrintOnPaperSide(SLPrintOnSideEnum.RIGHT.toString());
            paramBean.setRecipientInfo(sendToInfo);
            paramBean.setAddress(addressStr);
            paramBean.setPounds(0);
            paramBean.setOunces(1);
            //paramBean.setTracking(ShippingLabelTracking.USPS_TRACKING.toString());
            // paramBean.setStampsInsuranceAmount(150);
            paramBean.setCheckHidePostageValue(false);
            paramBean.setPrintReceiptCheckbox(true);
            paramBean.setPrintReferenceNumberCheckbox(true);
            paramBean.setReferenceNumber(testHelper.getTestName());

            CustomsInformationBean customsInformationBean = new CustomsInformationBean();
            customsInformationBean.setPackageContents(PackageContents.MERCHANDISE.toString());
            customsInformationBean.setMoreInfo(sendToInfo);
            customsInformationBean.setiAgreeToTheUSPSPrivacyActStatement(true);

            CustomsAddItemBean addItemBean = new CustomsAddItemBean();
            addItemBean.setDescription(sendToInfo);
            addItemBean.setPounds(0);
            addItemBean.setOunces(1);
            addItemBean.setQuantity(1);
            addItemBean.setValue(1);
            addItemBean.setHsTariff("US Tariff");

            printHelper.setShippingLabelForm(paramBean, customsInformationBean, addItemBean);

            printHelper.printPostage(paramBean);

        } catch (Exception e) {
            testHelper.logErrorTagStart();
            errorMessage = e.getMessage();
            pass = false;
            testHelper.logError(errorMessage);
            captureScreenShot(String.format("%s_FAIL_%s", testHelper.getTestName(), errorMessage));
            e.printStackTrace();
            testHelper.logErrorTagEnd();
        }

        //set delivery country back to US
        try {
            ShippingLabelModule printForm = printHelper.getWebPostagePage().getPrintModule().printOn()
                    .shippingLabel8x11();
            printForm.setShipToCountry(CountryEnum.UNITED_STATES);
        } catch (Exception e) {
            //do nothing...
        }

        Assert.assertTrue(pass, String.format("%s: %s ", testHelper.getTestName(), errorMessage));
        testHelper.endTest();
    }

    @Test(groups = { "regression" })
    public void _FPO_Test() {
        boolean pass = true;
        testHelper.beginTest();
        try {
            printHelper.getWebPostagePage().ensureUserIsSignedIn();
            // test parameters
            String sendToStreetNumberAndName = "USS Mason";
            String sendToCityStateZip = "FPO, AE 09578-1302";
            String addressStr = sendToInfo + Keys.ENTER + sendToStreetNumberAndName + Keys.ENTER
                    + sendToCityStateZip;

            ShippingLabelBean paramBean = new ShippingLabelBean();
            paramBean.setPrintOn(PrintOnEnum.SHIPPING_LABEL_8X11.toString());
            paramBean.setShippingLabelService(SLServiceEnum.PME_FLAT_RATE_ENVELOPE.toString());
            paramBean.setPrintOnPaperSide(SLPrintOnSideEnum.RIGHT.toString());
            paramBean.setRecipientInfo(sendToInfo);
            paramBean.setAddress(addressStr);
            paramBean.setPounds(0);
            paramBean.setOunces(1);
            //paramBean.setTracking(ShippingLabelTracking.USPS_TRACKING.toString());
            // paramBean.setStampsInsuranceAmount(150);
            paramBean.setCheckHidePostageValue(false);
            paramBean.setPrintReceiptCheckbox(true);
            paramBean.setPrintReferenceNumberCheckbox(true);
            paramBean.setReferenceNumber(testHelper.getTestName());

            CustomsInformationBean customsInformationBean = new CustomsInformationBean();
            customsInformationBean.setPackageContents(PackageContents.OTHER.toString());
            customsInformationBean.setMoreInfo(sendToInfo);
            customsInformationBean.setiAgreeToTheUSPSPrivacyActStatement(true);

            CustomsAddItemBean addItemBean = new CustomsAddItemBean();
            addItemBean.setDescription(sendToInfo);
            addItemBean.setPounds(0);
            addItemBean.setOunces(1);
            addItemBean.setQuantity(1);
            addItemBean.setValue(1);
            addItemBean.setHsTariff("US Tariff");

            printHelper.setShippingLabelForm(paramBean, customsInformationBean, addItemBean);

            printHelper.printPostage(paramBean);

        } catch (Exception e) {
            testHelper.logErrorTagStart();
            errorMessage = e.getMessage();
            pass = false;
            testHelper.logError(errorMessage);
            captureScreenShot(String.format("%s_FAIL_%s", testHelper.getTestName(), errorMessage));
            e.printStackTrace();
            testHelper.logErrorTagEnd();
        }

        //set delivery country back to US
        try {
            ShippingLabelModule printForm = printHelper.getWebPostagePage().getPrintModule().printOn()
                    .shippingLabel8x11();
            printForm.setShipToCountry(CountryEnum.UNITED_STATES);
        } catch (Exception e) {
            //do nothing...
        }

        Assert.assertTrue(pass, String.format("%s: %s ", testHelper.getTestName(), errorMessage));
        testHelper.endTest();
    }

    @Test(groups = { "regression" })
    public void _FAST_Test() {
        boolean pass = true;
        testHelper.beginTest();
        try {
            printHelper.getWebPostagePage().ensureUserIsSignedIn();
            // test parameters
            String sendToStreetNumberAndName = "800 Pale San Vitores Road";
            String sendToCityStateZip = "Tumon, Guam 96913";
            String addressStr = sendToInfo + Keys.ENTER + sendToStreetNumberAndName + Keys.ENTER
                    + sendToCityStateZip;

            ShippingLabelBean paramBean = new ShippingLabelBean();
            paramBean.setPrintOn(PrintOnEnum.SHIPPING_LABEL_8X11.toString());
            paramBean.setShippingLabelService(SLServiceEnum.PM_PACKAGE.toString());
            paramBean.setPrintOnPaperSide(SLPrintOnSideEnum.RIGHT.toString());
            paramBean.setRecipientInfo(sendToInfo);
            paramBean.setAddress(addressStr);
            paramBean.setPounds(0);
            paramBean.setOunces(3);
            //paramBean.setTracking(ShippingLabelTracking.USPS_TRACKING.toString());
            // paramBean.setStampsInsuranceAmount(150);
            paramBean.setCheckHidePostageValue(false);
            paramBean.setPrintReceiptCheckbox(true);
            paramBean.setPrintReferenceNumberCheckbox(true);
            paramBean.setReferenceNumber(testHelper.getTestName());

            CustomsInformationBean customsInformationBean = new CustomsInformationBean();
            customsInformationBean.setPackageContents(PackageContents.GIFTS.toString());
            customsInformationBean.setMoreInfo(sendToInfo);
            customsInformationBean.setiAgreeToTheUSPSPrivacyActStatement(true);

            CustomsAddItemBean addItemBean1 = new CustomsAddItemBean();
            addItemBean1.setDescription("First Item");
            addItemBean1.setPounds(0);
            addItemBean1.setOunces(1);
            addItemBean1.setQuantity(1);
            addItemBean1.setValue(1);
            addItemBean1.setHsTariff("US Tariff");

            CustomsAddItemBean addItemBean2 = new CustomsAddItemBean();
            addItemBean2.setDescription("Second Item");
            addItemBean2.setPounds(0);
            addItemBean2.setOunces(1);
            addItemBean2.setQuantity(1);
            addItemBean2.setValue(1);
            addItemBean2.setHsTariff("US Tariff");

            CustomsAddItemBean addItemBean3 = new CustomsAddItemBean();
            addItemBean3.setDescription("Third Item");
            addItemBean3.setPounds(0);
            addItemBean3.setOunces(1);
            addItemBean3.setQuantity(1);
            addItemBean3.setValue(1);
            addItemBean3.setHsTariff("US Tariff");

            printHelper.setShippingLabelForm(paramBean, customsInformationBean, addItemBean1, addItemBean2,
                    addItemBean3);

            printHelper.printPostage(paramBean);

        } catch (Exception e) {
            testHelper.logErrorTagStart();
            errorMessage = e.getMessage();
            pass = false;
            testHelper.logError(errorMessage);
            captureScreenShot(String.format("%s_FAIL_%s", testHelper.getTestName(), errorMessage));
            e.printStackTrace();
            testHelper.logErrorTagEnd();
        }

        //set delivery country back to US
        try {
            ShippingLabelModule printForm = printHelper.getWebPostagePage().getPrintModule().printOn()
                    .shippingLabel8x11();
            printForm.setShipToCountry(CountryEnum.UNITED_STATES);
        } catch (Exception e) {
            //do nothing...
        }

        Assert.assertTrue(pass, String.format("%s: %s ", testHelper.getTestName(), errorMessage));
        testHelper.endTest();
    }
}