Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;

import com.thoughtworks.selenium.*;

//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals;
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
//import org.openqa.selenium.server.SeleniumServer;

//import java.util.regex.Pattern;

public class Buyproductonshop2020_clearance extends SeleneseTestBase {
        

        String url = "";
        private Selenium selenium= null;

@BeforeClass
public void startBrowser() {
    selenium= new DefaultSelenium("localhost", 4444, "*firefox", "http://saholic:shop2020@shop2020.in:8080/");
        selenium.start();
        //selenium.open(url);
        selenium.windowMaximize();
}

        @Test(description="Clearance Sale")
        public void testBuyproductonprod() throws Exception {
                Thread.sleep(10000);
                selenium.setContext("Clearance");
                selenium.setTimeout("60000");
                selenium.open("/");
                //selenium.windowMaximize();
            //com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals("Page Title Mobile Phone Reviews and Best Deals in India | saholic.com not Found","Mobile Phone Reviews and Best Deals in India | saholic.com", selenium.getTitle(),selenium);
                assertEquals("Mobile Phone Reviews and Best Deals in India | shop2020.in", selenium.getTitle());
                assertTrue("Logo not present",selenium.isElementPresent("css=img[alt=\"Shop2020\"]"));
                assertTrue("Search all not found",selenium.isTextPresent("Search"));
                assertTrue("Element searchButton not found ",selenium.isElementPresent("id=searchButton"));
                assertEquals("BEST DEALS", selenium.getText("css=div.home-listing-common-header-text > span.left"));
                assertTrue("//div[@id='products']/div[2]/div/div/span not found",selenium.isElementPresent("//div[@id='products']/div[2]/div/div/span"));
                
                assertTrue("css=span.common-widget-top-bar-text-right not found",selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
                assertTrue("css=#browsehistory > div.common-widget-top-bar > div.common-widget-top-bar-text > span.common-widget-top-bar-text-right not found",selenium.isElementPresent("css=#browsehistory > div.common-widget-top-bar > div.common-widget-top-bar-text > span.common-widget-top-bar-text-right"));
                System.out.println(selenium.getText("//div[@id='products']/div[3]/div/div/span"));
                assertTrue("BEST SELLERS not found",selenium.isTextPresent("BEST SELLERS") );
                assertTrue("LATEST ARRIVALS not found",selenium.isTextPresent("LATEST ARRIVALS") );
                assertTrue("css=div.home-listing-common-content.best-sellers not found",selenium.isElementPresent("css=div.home-listing-common-content.best-sellers"));
                assertTrue("css=div.home-listing-common-content.latest-arrivals not found",selenium.isElementPresent("css=div.home-listing-common-content.latest-arrivals"));
                assertTrue("css=div.home-listing-common-content.best-deals not found",selenium.isElementPresent("css=div.home-listing-common-content.best-deals"));
                Thread.sleep(14000);
                selenium.click("link=Clearance Sale");
                selenium.waitForPageToLoad("60000");
                Thread.sleep(30000);
                //com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals("Spice and Micromax Phones at Best Price | Clearance Sale | saholic.com","Spice and Micromax Phones at Best Price | Clearance Sale | saholic.com", selenium.getTitle(),selenium);
                assertEquals("Clearance Sale | shop2020.in", selenium.getTitle());
                //assertTrue("css=div.cart-top",selenium.isElementPresent("css=div.cart-top"));
                //assertTrue("css=div.cart-middle",selenium.isElementPresent("css=div.cart-middle"));
                //assertTrue("css=div.cart-bottom",selenium.isElementPresent("css=div.cart-bottom"));
        assertTrue("css=div.common-widget-top-bar-text",selenium.isElementPresent("css=div.common-widget-top-bar-text"));
        assertTrue(selenium.isElementPresent("css=#browsehistory > div.common-widget-top-bar > div.common-widget-top-bar-text > span.common-widget-top-bar-text-right"));
        //verifyTrue(selenium.isElementPresent(""));
        for(int i=3;i<15;i++)
                {
                        System.out.println("abc"+i+"");
                        selenium.isElementPresent("dom=document.images["+i+"]");
                        System.out.println("dom=document.images["+i+"]");
                        assertTrue("Not able to buy Product",selenium.isElementPresent("dom=document.images["+i+"]"));
                selenium.click("dom=document.images["+i+"]");
                Thread.sleep(30000);
                selenium.waitForPageToLoad("60000");
                Thread.sleep(8000);
                assertTrue("Product detail element not found",selenium.isElementPresent("id=productDetail"));
                //selenium.captureScreenshot(screenshotresultPath+"/"+"ErrorPage"+".png");
                //com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Failed assert",selenium.isElementPresent("id=productDetail"),selenium);
                //com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Cart Summary not displayed",selenium.isElementPresent("css=div.cart"),selenium);
                
                //assertTrue("Cart Summary not displayed",selenium.isElementPresent("css=div.cart-top"));
                //verifyTrue(selenium.isElementPresent("css=#accessories > div.common-widget-top-bar > div.common-widget-top-bar-text"));
                assertTrue("Add to card button not present",selenium.isElementPresent("id=addToCart"));
                
                assertTrue("css=div.common-widget-top-bar-text not found",selenium.isElementPresent("css=div.common-widget-top-bar-text"));
                assertTrue("css=#myresearch > div.common-widget-top-bar > div.common-widget-top-bar-text not found",selenium.isElementPresent("css=#myresearch > div.common-widget-top-bar > div.common-widget-top-bar-text"));
                assertTrue("css=#browsehistory > div.common-widget-top-bar > div.common-widget-top-bar-text > span.common-widget-top-bar-text-right not found",selenium.isElementPresent("css=#browsehistory > div.common-widget-top-bar > div.common-widget-top-bar-text > span.common-widget-top-bar-text-right"));
        //assertTrue("id=Image1 not found",selenium.isElementPresent("id=Image1"));
                verifyEquals("Look n Feel", selenium.getText("//ul[@id='sideNav']/li[2]/a/span"));
                verifyEquals("Introduction", selenium.getText("css=a.vt > span"));
                assertTrue(selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
                selenium.setTimeout("60000");
                selenium.click("id=addToCart");
                Thread.sleep(30000);
                if(selenium.isVisible("id=cboxWrapper"))
                {
                        selenium.goBack();
                        Thread.sleep(15000);
                        //selenium.click("link=HOME");
                        continue;
                }
                break;
                }
        System.out.println("<----CART PAGE CLEARANCE_SALE THREAD---->");
        assertTrue("cartFlowHeader not found",selenium.isElementPresent("id=cartFlowHeader"));
                assertTrue("Cart details not found",selenium.isTextPresent("Cart Details"));
                assertTrue("Shipping Info. not found",selenium.isTextPresent("Shipping Info."));
                assertTrue("Make Payment not found",selenium.isTextPresent("Make Payment"));
                assertTrue("Order Status not found",selenium.isTextPresent("Order Status"));
                assertTrue("id=zipcode not found",selenium.isElementPresent("id=zipcode"));
                assertTrue("id=computeEstimate not found",selenium.isElementPresent("id=computeEstimate"));
                verifyEquals("Total Amount:", selenium.getText("css=tr.total-amount.payable > td.label"));
                Thread.sleep(6000);
                Thread.sleep(10000);
                assertEquals("ENTER SHIPPING INFO >",selenium.getText("id=poplogin"));
                selenium.click("id=poplogin");
                Thread.sleep(15000);
                selenium.type("id=loginEmail", "kshitijsood@ymail.com");
                selenium.type("id=loginPassword", "123abc");
                selenium.click("id=submitAddress");
                Thread.sleep(30000);
                 System.out.println("<----SHIPPING PAGE CLEARANCE_SALE THREAD---->");
                assertEquals("Item & Color", selenium.getText("css=th.first"));
                assertEquals("Delivery Time", selenium.getText("//table[@id='cartDetail']/thead/tr/th[2]"));
                assertEquals("Total Price", selenium.getText("//table[@id='cartDetail']/thead/tr/th[3]"));
                assertTrue("Select Shipping Address not found",selenium.isTextPresent("Select Shipping Address"));
                Thread.sleep(5000);
                //com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals("Proceed to payment button not present","PROCEED TO PAYMENT >", selenium.getText("id=proceedToPay"),selenium);
                assertEquals("PROCEED TO PAYMENT >", selenium.getText("id=proceedToPay"));
                selenium.click("id=proceedToPay");
                Thread.sleep(30000);
                 System.out.println("<----PROCEED TO PAY PAGE CLEARANCE_SALE THREAD---->");
                assertTrue("cartFlowHeader not found",selenium.isElementPresent("id=cartFlowHeader"));
                assertTrue("Cart details not found",selenium.isTextPresent("Cart Details"));
                assertTrue("Shipping Info. not found",selenium.isTextPresent("Shipping Info."));
                assertTrue("Make Payment not found",selenium.isTextPresent("Make Payment"));
                assertTrue("Order Status not found",selenium.isTextPresent("Order Status"));
                assertEquals("Order Amount:", selenium.getText("css=h4 > span"));
                String htmlstr = selenium.getBodyText();
        int pos = htmlstr.indexOf("Order Amount:");
        //System.out.println("Index is " + pos);
        int pos1=pos+16;
        int pos2=pos+28;
        String amount;
        amount = htmlstr.substring(pos1, pos2);
        //System.out.println("pos1 pos2" + pos1 + ":" + pos2);
        //int price=Integer.parseInt(amount);
        //System.out.println("Amount : :" + amount + ":" + price );
        amount=amount.replaceAll(",", "");
        System.out.println("Amount : :" + amount);
        ///double price = Integer.parseInt(amount);
        double price = Double.parseDouble(amount);
        System.out.println("Price : :" + price);
        assertTrue("CREDIT CARDS not found",selenium.isTextPresent("CREDIT CARDS"));
                assertTrue("EMI not found",selenium.isTextPresent("EMI"));
                assertTrue("DEBIT/ATM CARDS not found",selenium.isTextPresent("DEBIT/ATM CARDS"));
                assertTrue("NET BANKING not found",selenium.isTextPresent("NET BANKING"));
                assertTrue("CASH CARDS not found",selenium.isTextPresent("CASH CARDS"));
                assertTrue("css=input.make-payment-button not found",selenium.isElementPresent("css=input.make-payment-button"));
                if((price > 300) && (price < 20000))
                {
                assertTrue("CASH ON DELIVERY not found",selenium.isTextPresent("CASH ON DELIVERY"));    
                selenium.click("//div[@id='vtab']/ul/li[6]");
                assertTrue("id=captcha_response_box not found",selenium.isElementPresent("id=captcha_response_box"));
                assertTrue("id=captchaImage not found",selenium.isElementPresent("id=captchaImage"));
                assertTrue(selenium.isElementPresent("css=div.text-center > input.make-payment-button"));
                }
                selenium.deleteAllVisibleCookies();
        }
        @AfterClass
        public void clear() {
                selenium.selectWindow(selenium.getTitle());
                selenium.captureScreenshot("clearance_shop2020.png");
                selenium.stop();
        }       
        }