com.isocket.gui.advertisers.PropertyProfilePage.java Source code

Java tutorial

Introduction

Here is the source code for com.isocket.gui.advertisers.PropertyProfilePage.java

Source

/*
 * Copyright 2013 QAPROSOFT (http://qaprosoft.com/).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.isocket.gui.advertisers;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.FindBy;
import org.testng.Assert;

import com.isocket.model.Campaign;
import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;

public class PropertyProfilePage extends BasePage {
    @FindBy(xpath = "//tr[child::td[@class='location']]")
    public List<ExtendedWebElement> locationRows;

    @FindBy(linkText = "New Campaign")
    public ExtendedWebElement newCampaignButton;

    @FindBy(id = "campaign_manager_select")
    public ExtendedWebElement campaignManagerSelect;

    @FindBy(id = "campaign_advertiser_select")
    public ExtendedWebElement campaignAdvertiserSelect;

    @FindBy(id = "campaign_name")
    public ExtendedWebElement campaignNameTextField;

    @FindBy(id = "campaign_start_date")
    public ExtendedWebElement campaignStartDateTextField;

    @FindBy(id = "campaign_end_date")
    public ExtendedWebElement campaignEndDateTextField;

    @FindBy(id = "campaign_internal_notes")
    public ExtendedWebElement campaignInternalNotesTextField;

    @FindBy(xpath = "//button[contains(., 'Create Campaign and Add Product')]")
    public ExtendedWebElement createCampaignButton;

    public PropertyProfilePage(WebDriver driver) {
        super(driver);
    }

    public void assertLocationPresent(String name) {
        boolean isFound = false;
        for (ExtendedWebElement location : locationRows) {
            if (location.getText().contains(name)) {
                isFound = true;
            }
        }
        Assert.assertTrue(isFound, String.format("Location '%s' not found", name));
    }

    public CampaignPage createCampaignForLocation(String name, Campaign campaign) {
        boolean isFound = false;
        for (ExtendedWebElement location : locationRows) {
            if (location.getText().contains(name)) {
                click("addCampaignButton", location.getElement().findElement(By.tagName("button")));
                isFound = true;
            }
        }
        Assert.assertTrue(isFound, String.format("Location '%s' not found", name));

        click(newCampaignButton);
        populateCampaign(campaign);
        click(createCampaignButton);

        return new CampaignPage(driver);
    }

    private void populateCampaign(Campaign campaign) {
        select(campaignManagerSelect, campaign.getManager());
        select(campaignAdvertiserSelect, campaign.getAdvertiser());
        type(campaignNameTextField, campaign.getName());
        type(campaignStartDateTextField, campaign.getStartDate());
        type(campaignEndDateTextField, campaign.getEndDate());
        type(campaignInternalNotesTextField, campaign.getInternalNotes());
    }
}