Saturday 10 February 2018

config and testng xml

package com.spa.sfautomation.browser;

import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

import com.spa.sfautomation.page.AddDocumentURLPage;
import com.spa.sfautomation.page.AdminDefaultPage;
import com.spa.sfautomation.page.HomePage;
import com.spa.sfautomation.page.KPIMetricPage;
import com.spa.sfautomation.page.LoginPage;
import com.spa.sfautomation.page.popup.DeleteRowPopUp;
import com.spa.sfautomation.page.popup.ManageCustomModulesPopUp;
import com.spa.sfautomation.page.popup.ManageMetricCategoriesPopUp;
import com.spa.sfautomation.page.popup.ManageMetricDimensionsPopUp;
import com.spa.sfautomation.page.popup.ManageMetricTemplatesPopUp;
import com.spa.sfautomation.page.popup.ManageMetricUnitsPopUp;
import com.spa.sfautomation.page.popup.ManageMetricsPopUp;
import com.spa.sfautomation.util.ConfigReader;

public abstract class InitDriver {

enum DriverType {
IE, Chrome
}
public WebDriver driver;
public ConfigReader appProp;
public String baseURL;
public String adminUserId;
public String adminPassword;

@BeforeClass
@Parameters({"driverType"})
public void beforeMainClass(String driverType){
// TODO: some config xml file
if (DriverType.Chrome.toString().equals(driverType)) {
System.setProperty("webdriver.chrome.driver",".\\src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
}else if(DriverType.IE.toString().equals(driverType)){
System.setProperty("webdriver.ie.driver",".\\src\\main\\resources\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
else {
System.out.println("Driver type is not defined in testng.xml file, Please specify browser (IE or Chrome)");
}
//driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
loadApplicationProperties();
this.beforeClass();
}

@AfterClass
public void afterMainClass() {
this.afterClass();
driver.quit();
}

@BeforeMethod
public void beforeMainMethod() {
this.beforeMethod();
}

@AfterMethod
public void afterMainMethod() {
this.afterMethod();
}

@BeforeTest
public void beforeMainTest() {
this.beforeTest();
}

@AfterTest
public void afterMainTest() {
this.afterTest();
}

public abstract void beforeMethod();

public abstract void afterMethod();

public abstract void beforeClass();

public abstract void afterClass();

public abstract void beforeTest();

public abstract void afterTest();

//Page references
public LoginPage loginPage;
public HomePage homePage;
public AdminDefaultPage adminDefaultPage;
public KPIMetricPage kpiMetricPage;
public ManageMetricCategoriesPopUp manageMetricCategoriesPopUp;
public DeleteRowPopUp deleteRowPopUp;
public ManageMetricUnitsPopUp manageMetricUnitsPopUp;
public ManageMetricDimensionsPopUp manageMetricDimensionsPopUp;
public AddDocumentURLPage addDocumentURLPage;
public ManageMetricTemplatesPopUp manageMetricTemplatesPopUp;
public ManageCustomModulesPopUp manageCustomModulesPopUp;
public ManageMetricsPopUp manageMetricsPopUp;

//data variables
public List <String> categoryDataList = new ArrayList<String>(0);
public List <String> unitDataList = new ArrayList<String>(0);
public List <String> dimensionDataList = new ArrayList<String>(0);
public List <String> templateDataList = new ArrayList<String>(0);
public List <String> customModuleDataList = new ArrayList<String>(0);
public List <String> metricDataList = new ArrayList<String>(0);

//get application configuration setting.
public void loadApplicationProperties(){
ConfigReader appProp = new Config Reader();
baseURL = appProp.readKeyValue("BASE_URL");
adminUserId = appProp.readKeyValue("ADMIN_USERID");
adminPassword = appProp.readKeyValue("ADMIN_PASSWORD");
}

//load landing page
public void openURL(){
driver.get(baseURL+"/login.aspx");
}

}
==========================
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="KPI Marics Suite" parallel="false">
<!-- dtiverType = IE, Chrome -->
<parameter name="driverType" value="Chrome"></parameter>

  <test name="Verify adding a new category">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.AddCategory"/>
</classes>
</test>
<test name="Verify by clicking on close, category is not added">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.NotAddCategory"/>
</classes>
</test>
<test name="Verify Editing an existing category">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.EditCategory"/>
</classes>
</test>
<test name="Verify by clicking on cancel, category is not Edited">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.NotEditCategory"/>
</classes>
</test>
<test name="Verify validation message for category field on adding category">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.ValidationMessageOnAddCategory"/>
</classes>
</test>
<test name="Verify validation message for category field on editing category">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.ValidationMessageOnEditCategory"/>
</classes>
</test>
<test name="Verify deleting a category">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.DeleteCategory"/>
</classes>
</test>
<test name="Verify adding a new unit">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.AddUnit"/>
</classes>
</test>
<test name="Verify by clicking on close, unit is not added">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.NotAddUnit"/>
</classes>
</test>
<test name="Verify Editing an existing unit">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.EditUnit"/>
</classes>
</test>
<test name="Verify by clicking on cancel, unit is not Edited">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.NotEditUnit"/>
</classes>
</test>
<test name="Verify validation message for unit name and symbol fields on adding unit">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.ValidationMessageOnAddUnit"/>
</classes>
</test>
<test name="Verify validation message for unit name and symbol fields on editing unit">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.ValidationMessageOnEditUnit"/>
</classes>
</test>
<test name="Verify deleting an unit">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.DeleteUnit"/>
</classes>
</test>
<test name="Verify adding a new basic dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.AddBasicDimension"/>
</classes>
</test>
<test name="Verify adding a new absolute tolerance dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.AddToleranceAbsoluteDimension"/>
</classes>
</test>
<test name="Verify adding a new percentage tolerance dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.AddTolerancePercentageDimension"/>
</classes>
</test>
<test name="Verify adding a new variation dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.AddVariationDimension"/>
</classes>
</test>
<test name="Verify with same base dimensions, new variation dimension is not added">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.NotAddVariationDimension"/>
</classes>
</test>
<test name="Verify by clicking on close, dimension is not added">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.NotAddDimension"/>
</classes>
</test>
<test name="Verify Editing a basic dimension to tolerance dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.EditBasicDimensionToTolerance"/>
</classes>
</test>
<test name="Verify Editing a tolerance dimension to variation dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.EditToleranceDimensionToVariation"/>
</classes>
</test>
<test name="Verify Editing a variation dimension to basic dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.EditVariationDimensionToBasic"/>
</classes>
</test>
<test name="Verify with same base dimensions, variation dimension is not edited">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.NotEditVariationDimension"/>
</classes>
</test>
<test name="Verify by clicking on cancel, dimension is not Edited">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.NotEditDimension"/>
</classes>
</test>
<test name="Verify validation message for name, display name and symbol fields on adding dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.ValidationMessageOnAddDimension"/>
</classes>
</test>
<test name="Verify validation message for name, display name and symbol fields on editing dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.ValidationMessageOnEditDimension"/>
</classes>
</test>
<test name="Verify deleting a dimension">
<classes>
<class name="com.spa.sfautomation.test.kpi.basic.DeleteDimension"/>
</classes>
</test>
</suite>

ui maps

package com.spa.c3dna.ui;
import org.openqa.selenium.By;
public class UIMap
{
public static By userName = By.id("username");
public static By password = By.id("password");
public static By ipurl = By.id("ipurl");
public static By loinClick = By.id("loginvalid");

/*............Apache----------*/
public static By webserviceLink = By.xpath("//ul[@class='menu']/li[4]/ul/li[2]/a");
public static By virtualHostName = By.id("logicName");
public static By actionApache = By.id("operation");
public static By workFlowname = By.id("apacheoperation");
public static By platformIDApache = By.id("platformID");
public static By browseApache = By.xpath("//*[@id='fluploader']/div[1]/img");
public static By saveApache = By.id("updateApacheLampStack");

/*............Single Step Execution----------*/

public static By singleStepLink = By.xpath("//ul[@class='menu']/li[2]/ul/li[3]/a");
public static By sName = By.xpath("//*[@id='name']");
public static By sComand = By.xpath("//*[@id='command']");
public static By sFilechouse = By.xpath("//*[@id='fileId']");
public static By Sadd = By.xpath("//*[@id='addTaskbtn']");
public static By Sedit = By.xpath("//*[@id='table-list']/tbody/tr[2]/td[2]/a/img");
public static By SDelete = By.xpath("//*[@id='table-list']/tbody/tr[2]/td[1]/a");

/*............Application Association---------*/
public static By associationLink = By.xpath("//ul[@class='menu']/li[1]/ul/li[3]/a");
public static By assName = By.id("name");
public static By configurationLink = By.xpath("//ul[@class='accodianList']/li[2]/a");
public static By configurationCheckbox = By.xpath("//*[@id='config-list']/tbody/tr[3]/td[1]/div/span");
public static By configurationSave = By.id("appAssocbutton");
public static By comboPclick = By.xpath("//*[@id='selectplatFormID']/div/div[1]");
public static By comboSelectValuesclick = By.xpath("//*[@id='selectplatFormID']/div/div[2]/ul/li[3]/a");
public static By editApplication = By.xpath("//*[@id='serviceC']/tbody/tr[2]/td[2]/a/img");
public static By deleteApplication = By.xpath("//*[@id='serviceC']/tbody/tr[2]/td[1]/a/img");

}
=============
package com.spa.c3dna.test;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.spa.c3dna.action.ActionBot;
import com.spa.c3dna.ui.UIMap;

public class applicationAssociationAdd extends Login
{
@Test
public void applicationAssociationsAdd()
{
ActionBot action = new ActionBot(driver);
action.click(UIMap.associationLink);
action.type(UIMap.assName, "FiveMin"+action.randomNumber()+"Asso");
action.click(UIMap.comboPclick);
action.click(UIMap.comboSelectValuesclick);
List<WebElement> offers = driver.findElements(By.cssSelector("span.checkbox")); //.offer is
    String requiredLabel = "5MinituesTask";
   for(WebElement offer : offers)
   {
       String label = offer.findElement(By.tagName("input")).getAttribute("value");
           
       String [] SplitArr=label.split("@");
                int x1=0;
                String y=SplitArr[x1];
               
       if(requiredLabel.equalsIgnoreCase(y))
       {
   
           offer.click();
           break;

       }
   }
action.click(UIMap.configurationLink);
action.click(UIMap.configurationCheckbox);
action.click(UIMap.configurationSave);
Assert.assertEquals(action.alertgetText(),"Data saved successfully.");
action.alertAccept();
}
}