Join the webinar on 'Open source GenAI tools for Test Automation' on May 28th or May 30th.
close
Donating Holiday Cheer Using Appium

Donating Holiday Cheer Using Appium

December 26, 2018
 by 
 Jonathan Lipps Jonathan Lipps
Jonathan Lipps

As this is the last Appium Pro edition of 2018, I thought it appropriate to take a few moments and reflect on what we're all doing here. Whether you celebrate Christmas, Hanukkah, Kwanzaa, Festivus, the Winter Solstice, or nothing in particular, the fact that you're reading my online newsletter about mobile app testing probably means you have something to celebrate.

I'm not saying life is easy for any of us, and I'm not saying that end-of-year holidays are always filled with joy--they can certainly be filled with heartbreak too, no matter how well-off we are. But I am saying that it's worth reflecting on the opportunities open to us in virtue of our experience with software development and/or testing. I'm grateful that I can spend a portion of every week thinking about fun and interesting things to do with Appium, and I'm even more grateful that there are some of you out there in the world who find these little guides worth reading. When I stop and think about the reality of how I get to live my life, I'm overwhelmed by the truth that there's nothing particularly "fair" about it.

OK--this project is called "Appium Pro" and not "Philosophical Ethics Pro", so I won't belabor the point any further. I just wanted to give us all a brief moment to pause, detach from the technical details for a moment, think about what it means for us to be humans (even technologically-oriented humans), and have regard for those of our fellow human beings who are worried about much more urgent problems than how to solve the next automation challenge at work.

In that spirit, I offer you a different kind of code sample today, one that you could use to donate to a variety of charities. I've chosen to write this little script to donate to Raising the Roof, a homelessness solutions charity here where I live in Canada. (The script will work for any charity using gifttool.com's platform, though it was not easy to find a list of such organizations). But find your favorite charity and write your own donation script! I just ran mine and it gave me a little thrill of holiday cheer. Let me know if you do something similar and I'll give you a shoutout in 2019!

See you all next year.


import io.appium.java_client.ios.IOSDriver;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Edition049_Holidays_2018 {
    private IOSDriver driver;
    private WebDriverWait wait;

    private static String CHARITY_URL = "https://www.gifttool.com/donations/Donate?ID=1676&AID=1607";
    private static String DONATION_AMT = "25";
    private static String EMAIL = "your@email.com";
    private static String FIRST_NAME = "Your";
    private static String LAST_NAME = "Name";
    private static String STREET = "123 Main Street";
    private static String CITY = "Vancouver";
    private static String COUNTRY_CODE = "CA"; // 2-digit country code
    private static String STATE_CODE = "BC";
    private static String POSTAL_CODE = "V6K 123";
    private static String PHONE = "555-555-5555";
    private static String CARD_NAME = FIRST_NAME + " " + LAST_NAME;
    private static String CARD_NUMBER = "1234 5678 9012 3456";
    private static String CVV2 = "123";
    private static String CARD_TYPE = "Visa"; // 'Visa' or 'Mastercard'
    private static String CARD_MONTH = "01";  // 2-digit month
    private static String CARD_YEAR = "21";  // 2-digit year

    private static By donationAmt = By.id("ContributionAmount");
    private static By donorEmail = By.name("Email");
    private static By donorFirstName = By.name("FirstName");
    private static By donorLastName = By.name("LastName");
    private static By donorStreet = By.name("Street");
    private static By donorCity = By.name("City");
    private static By donorCountry = By.id("Country");
    private static By donorState = By.id("State");
    private static By donorPostalCode = By.name("ZipCode");
    private static By donorPhone = By.name("PhoneDay");
    private static By donorCardName = By.name("CardName");
    private static By donorCardNumber = By.name("CardNumber");
    private static By donorCVV2 = By.name("CVV2");
    private static By donorCardType = By.name("CardType");
    private static By donorCardMonth = By.name("ExpiryMonth");
    private static By donorCardYear = By.name("ExpiryYear");
    private static By submitDonation = By.id("gtSubmitButton");

    @Before
    public void setUp() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName", "iOS");
        capabilities.setCapability("platformVersion", "11.4");
        capabilities.setCapability("deviceName", "iPhone 6");
        capabilities.setCapability("browserName", "Safari");

        driver = new IOSDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
        wait = new WebDriverWait(driver, 10);
    }

    @After
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }

    @Test
    public void testHolidayCheer() {
        driver.get(CHARITY_URL);
        wait.until(ExpectedConditions.presenceOfElementLocated(donationAmt)).sendKeys(DONATION_AMT);
        driver.findElement(donorEmail).sendKeys(EMAIL);
        driver.findElement(donorFirstName).sendKeys(FIRST_NAME);
        driver.findElement(donorLastName).sendKeys(LAST_NAME);
        driver.findElement(donorStreet).sendKeys(STREET);
        driver.findElement(donorCity).sendKeys(CITY);
        new Select(driver.findElement(donorCountry)).selectByValue(COUNTRY_CODE);
        new Select(driver.findElement(donorState)).selectByValue(STATE_CODE);
        driver.findElement(donorPostalCode).sendKeys(POSTAL_CODE);
        driver.findElement(donorPhone).sendKeys(PHONE);
        driver.findElement(donorCardName).sendKeys(CARD_NAME);
        driver.findElement(donorCardNumber).sendKeys(CARD_NUMBER);
        driver.findElement(donorCVV2).sendKeys(CVV2);
        new Select(driver.findElement(donorCardType)).selectByValue(CARD_TYPE);
        new Select(driver.findElement(donorCardMonth)).selectByValue(CARD_MONTH);
        new Select(driver.findElement(donorCardYear)).selectByValue(CARD_YEAR);
        driver.findElement(submitDonation).click();
    }
}

Donating Holiday Cheer Using Appium

4 Parts

Close

Perfect Digital Experiences with Data Science Capabilities

Utilize HeadSpin's advanced capabilities to proactively improve performance and launch apps with confidence
popup image