Sunday

Selenium 2- SZ - Code of Configuration and some of DSL package

package uk.co.shopzilla.qa.regression.configuration;

import com.google.inject.internal.ImmutableMap;
import org.apache.log4j.Logger;
import uk.co.shopzilla.qa.regression.dsl.FooterLink;
import uk.co.shopzilla.qa.regression.dsl.Link;
import uk.co.shopzilla.qa.regression.dsl.PageRequest;
import uk.co.shopzilla.qa.regression.dsl.PageRequestImpl;
import uk.co.shopzilla.qa.regression.framework.WebDriverFactory;

import java.util.Map;

public class Configuration {
private static final Logger LOG = Logger.getLogger(Configuration.class);

private final String baseUrl;
private final WebDriverFactory webDriverFactory;
private final Map pages;
private final int defaultItemCount;
private final Map footerPodData;
private final Map footerPodDatalink;
private final Map texts;

public Configuration(String baseUrl, WebDriverFactory webDriverFactory, Map pages, int defaultItemCount, Map footerPodData, Map texts) {
this.baseUrl = baseUrl;
this.webDriverFactory = webDriverFactory;
this.pages = pages;
this.defaultItemCount = defaultItemCount;
this.footerPodData = footerPodData;
this.footerPodDatalink= footerPodData;
this.texts = texts;
}
public PageInfo getPageDetails(final PageIdentifier pageIdentifier){
final SubdomainAndPath page = pages.get(pageIdentifier);
return page.getPageinfo();
}

public PageRequest getPageRequest(final PageIdentifier pageIdentifier) {
final SubdomainAndPath page = pages.get(pageIdentifier);

if (page == null) {
LOG.warn("No page with identifier: " + pageIdentifier + " for configuration: " + this + " - returning dummy");

return PageRequest.NONE;
}


System.out.println("This is the Base URL == " + baseUrl);
System.out.println("This is the full URL == " + "http://" + page.getSubdomain()+ "." + baseUrl + page.getPath());


/**
* Code has been modified from return new PageRequestImpl(webDriverFactory.createDriver(), baseUrl + page.getPath());
* to return new PageRequestImpl(webDriverFactory.createDriver(),"http://" + page.getSubdomain()+ "." + baseUrl + page.getPath());
*Previously we were not able to get the subdomain but this will handle the subdomain part .
*also from the Configuration.class returing the http://www. string as base url so to update that file to just return base url.
* @author Krishan Shukla
* @since Mar 23, 2011
*/


return new PageRequestImpl(webDriverFactory.createDriver(),"http://" + page.getSubdomain()+ "." + baseUrl + page.getPath());

// if (baseUrl.equalsIgnoreCase("bizrate.co.uk") || baseUrl.equalsIgnoreCase("stage.bizrate.co.uk") )
// {
// // return new PageRequestImpl(webDriverFactory.createDriver(), baseUrl + page.getPath());
// return new PageRequestImpl(webDriverFactory.createDriver(),"http://" + page.getSubdomain()+ "." + baseUrl + page.getPath());
// }
//
// else
//
// return new PageRequestImpl(webDriverFactory.createDriver(),"http://" + page.getSubdomain()+ "." + baseUrl + page.getPath());
//

}


@Override
public String toString() {
return "Configuration{" +
"webDriverFactory=" + webDriverFactory +
", baseUrl='" + baseUrl + '\'' +
'}';
}

public String getText(TextIdentifier textIdentifier) {
return texts.get(textIdentifier);
}

public int getDefaultItemCount() {
return defaultItemCount;
}

public Map getFooterPodData() {
return footerPodData;
}


//This code is not completed -
public void getFooterPodLinks() {

Map footerPodDatalink;

footerPodDatalink=getFooterPodData();

int sizeOffooter=footerPodDatalink.size();

for (int i=0;i pages;
private int defaultItemCount = 20; // Matches the default item count in the search command - used for SZ sites
private Map footerPodData;
private Map texts;

public Builder baseUrl(String baseUrl) {
this.baseUrl = baseUrl;

return this;
}

public Builder pages(Map pages) {
this.pages = ImmutableMap.copyOf(pages);
return this;
}

public Builder driverFactory(WebDriverFactory driverFactory) {
this.webDriverFactory = driverFactory;
return this;
}

public Builder texts(Map texts) {
this.texts = ImmutableMap.copyOf(texts);
return this;
}


public Builder itemCount(int itemCount) {
this.defaultItemCount = itemCount;
return this;
}

public Builder footerData(Map footerPodData) {
this.footerPodData = footerPodData;
return this;
}



public Configuration build() {
// TODO consistency checks either here or in the ctor

return new Configuration(baseUrl, webDriverFactory, pages, defaultItemCount, footerPodData, texts);
}

}
}




package uk.co.shopzilla.qa.regression.configuration;

public enum Environment {
STAGE("stage."),
MASTER("master."),
BRANCH("branch."),
PRODUCTION("");


private final String subdomain;

Environment(String subdomain) {
this.subdomain = subdomain;
}

public String getSubdomain() {
return subdomain;
}
}


package uk.co.shopzilla.qa.regression.configuration;


public enum PageIdentifier {
Home_SZ,
Home,
HOT_8B_10SLS,
HOT_8B_MATURE,
HOT_8B_5SLS,
HOT_7S_5SLS,
HOT_10J_5SLS,
HOT_7T_5SLS,
COOL_7Y,
COOL_7Z,
COOL_8C,
COOL_8E,
COOL_8I,
SCORCHING_8N,
SCORCHING_8N_COMPACTED,
SCORCHING_9L
}



package uk.co.shopzilla.qa.regression.configuration;


public class PageInfo {
public final int productlinkno;
public final int sponsorlinkno;
public final int paginationno;

public PageInfo (int productlinkno, int sponsorlinkno, int paginationno){
this.productlinkno = productlinkno;
this.sponsorlinkno = sponsorlinkno;
this.paginationno = paginationno;
}
}




package uk.co.shopzilla.qa.regression.configuration;

public enum Site {
BR_GB("bizrate.co.uk"),
LW_GB("lowpriceshopper.co.uk"),
SZ_GB("shopzilla.co.uk"),
PC_FR("prixmoinscher.com"),
SZ_FR("shopzilla.fr"),
BR_DE("bizrate.de"),
SZ_DE("shopzilla.de"),
SG_DE("spardeingeld.de");

private final String baseUrl;

Site(String baseUrl) {
this.baseUrl = baseUrl;
}

public String getBaseUrl() {
return baseUrl;
}
}



package uk.co.shopzilla.qa.regression.configuration;

public class SubdomainAndPath {
private final String subdomain;
private final String path;
private final PageInfo pageinfo;

public SubdomainAndPath(String path) {
this("www", path);
}

public SubdomainAndPath(String subdomain, String path) {


this.subdomain = subdomain;
this.path = path;
this.pageinfo = new PageInfo(0,0,0);
}

public SubdomainAndPath (String subdomain, String path, int numberOfProductLinks, int numberOfSponsorLinks, int numberOfPaginations){
this.subdomain = subdomain;
this.path = path;
this.pageinfo = new PageInfo(numberOfProductLinks, numberOfSponsorLinks, numberOfPaginations);
}

public SubdomainAndPath (String path, int numberOfProductLinks, int numberOfSponsorLinks, int numberOfPaginations){
this("www", path, numberOfProductLinks, numberOfSponsorLinks, numberOfPaginations);
}


public String getSubdomain() {
return subdomain;
}

public String getPath() {
return path;
}

public PageInfo getPageinfo (){
return pageinfo;
}
}



/**
* Copyright (C) 2004 - 2009 Shopzilla, Inc.
* All rights reserved. Unauthorized disclosure or distribution is prohibited.
*/

package uk.co.shopzilla.qa.regression.configuration;
public enum TextIdentifier {
COBRAND,
GO_TO_STORE,
MATURE_WARNING,
MORE,
NEXT,
SL_SUFFIX
}


package uk.co.shopzilla.qa.regression.dsl;

import org.openqa.selenium.RenderedWebElement;
import org.openqa.selenium.WebElement;

import java.awt.*;


public class AbstractPositionedPod implements PositionedPod {
protected final WebElement webElement;

public AbstractPositionedPod(WebElement webElement) {
this.webElement = webElement;
}

@Override
public final boolean isAbove(PositionedPod other) {
if (!(webElement instanceof RenderedWebElement)) {
return true;
}

return ((RenderedWebElement) webElement).getLocation().y < other.getPosition().getY(); } @Override public final boolean isBelow(PositionedPod other) { if (!(webElement instanceof RenderedWebElement)) { return true; } return ((RenderedWebElement) webElement).getLocation().y > other.getPosition().getY();
}



@Override
public final boolean isLeftOf(PositionedPod other) {
if (!(webElement instanceof RenderedWebElement)) {
return true;
}

return ((RenderedWebElement) webElement).getLocation().x < other.getPosition().getX(); } @Override public final Position getPosition() { if (!(webElement instanceof RenderedWebElement)) { return Position.UNKNOWN; } final Point location = ((RenderedWebElement) webElement).getLocation(); return new Position(location.x, location.y); } } package uk.co.shopzilla.qa.regression.dsl; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; public class BreadCrumbsPod extends AbstractPositionedPod { public BreadCrumbsPod(WebElement webElement) { super(webElement); } public int getBreadCrumbsCount() { return webElement.findElements(By.tagName("a")).size(); } } package uk.co.shopzilla.qa.regression.dsl; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import java.util.List; public class FooterBanner extends AbstractPositionedPod{ public FooterBanner(WebElement webElement) { super(webElement); } public int isFooterBannerExist() { // System.out.println("\n The Text in Footer banner is : " +webElement.getText() + "\n"); System.out.println("\n The name of footer banner is 'search_bar' & = ' " + webElement.getAttribute("id")+ "' Found at run time the"); // System.out.println(wbelmnt.get(0)); // System.out.println("IS : FooterBanner exist with count : " +webElement.findElements(By.id("search_bar")).size()); // Selenium.IsElementPresent(); // SystemwebElement.findElements(By.id("search_bar")); return 1; } public void isEditBoxinBanner(){ //System.out.println("\n webElement.findElements(By.tagNameinput " + webElement.findElements(By.tagName("input"))); //System.out.println("\n input type size : " + webElement.findElements(By.tagName("input")).size()); // List wbElement= webElement.findElements(By.tagName("input"));

// System.out.println("wbElement.size() is = " + wbElement.size());
int flag=0;
for(WebElement element : webElement.findElements(By.tagName("input"))) {


// System.out.println("element.getTagName()" + element.getTagName());
// System.out.println("element.getText()" + element.getText());
// System.out.println("element.getText()" + element.findElement(By.name("keyword")));
// System.out.println("element.getAttribute(name)" + element.getAttribute("name"));

if(element.getAttribute("name").equalsIgnoreCase("keyword")){

// System.out.println("\n Banner pod EditBox Exist which having search keyword in that");

System.out.println("\n Banner pod EditBox Exist which having search keyword :: \"" + element.getValue()+ "\" in that");


flag=1;
break;
}

}


if(flag==1){


System.out.println(" PASS: the edit box in banner Pod \n" );

}

else {

System.out.println(" FAIL: the edit box NOT in banner Pod \n");
}


}
}


package uk.co.shopzilla.qa.regression.dsl;


public enum FooterLink {
HOME("footer_home"),
ABOUT("footer_about"),
PRIVACY_POLICY("footer_privacy_policy"),
USER_AGREEMENT("footer_user_agreement"),
SWEEPSTAKE("footer_sweepstake"),
PRESS("footer_press"),
JOBS("footer_jobs"),
SITEMAP("footer_sitemap"),
TOP_SEARCHES("footer_sitemap_topsearches"),
TOP_PRODUCTS("footer_sitemap_topproducts"),
RATINGS_GUIDE("footer_ratings_guide"),
NEWSLETTER("footer_newsletter"),
MERCHANT_LOGIN("footer_merchant_login"),
MERCHANT_LISTINGS("footer_merchant_listings"),
PRODUCT_REVIEWS("footer_product_reviews"),
RATINGS_AND_RESEARCH("footer_ratings_and_research"),
AFFILIATES("footer_affiliates"),
SZ_SOLUTIONS("footer_sz_solutions"),
;

private final String elementId;

private FooterLink(String elementId) {
this.elementId = elementId;
}

public String getElementId() {
return elementId;
}
}

No comments:

Post a Comment