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 com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter;
import com.unitedinternet.portal.selenium.utils.logging.LoggingCommandProcessor;
import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium;
import com.unitedinternet.portal.selenium.utils.logging.LoggingResultsFormatter;
import com.unitedinternet.portal.selenium.utils.logging.LoggingSelenium;
import com.unitedinternet.portal.selenium.utils.logging.LoggingUtils;
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals;
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
//import org.openqa.selenium.server.SeleniumServer;

//import java.util.regex.Pattern;

public class fakeorders extends SeleneseTestBase {
        

        BufferedWriter loggingWriter;
        protected LoggingSelenium selenium;
        final String resultbasePath = "/opt/seleniumTests/results/shop2020";
        //final String resultbasePath = "/opt/seleniumTests/results";
    final String resultHtmlFileName = resultbasePath + "/" + "result0.html";
    final String resultEncoding = "UTF-8";          
    final String screenshotpath="screenshot";
    final String screenshotresultPath=new File(resultbasePath+"/"+screenshotpath).getAbsolutePath();
        @Before
        public void setUp() throws Exception {
                if (!new File(screenshotresultPath).exists()) {
                         new File(screenshotresultPath).mkdirs();
                }
            loggingWriter = LoggingUtils.createWriter(resultHtmlFileName, resultEncoding , true);
            LoggingResultsFormatter htmlFormatter = 
                new HtmlResultFormatter(loggingWriter, resultEncoding);
           htmlFormatter.setScreenShotBaseUri(resultbasePath+"/"+screenshotpath+"/"); // this is for linking to the screenshots
           htmlFormatter.setAutomaticScreenshotPath(screenshotresultPath);
            // wrap HttpCommandProcessor from remote-control
            LoggingCommandProcessor myProcessor = 
            new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", "http://saholic:shop2020@shop2020.in:8080/"), htmlFormatter);
            //new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", "http://saholic.com/"), htmlFormatter);
            selenium = new LoggingDefaultSelenium(myProcessor);
            myProcessor.setExcludedCommands(new String[] {});
            selenium.start();   
        }

        @Test(expected=AssertionError.class)
        public void testBuyproductonprod() throws Exception {
                selenium.setContext("testBuyprodonprod()");
                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 | shop2020.in not Found","Mobile Phone Reviews and Best Deals in India | shop2020.in", selenium.getTitle(),selenium);
                verifyTrue(selenium.isElementPresent("css=img[alt=\"Shop2020\"]"));
                verifyTrue(selenium.isTextPresent("Search All"));
                verifyTrue(selenium.isElementPresent("id=searchButton"));
                verifyEquals("BEST DEALS", selenium.getText("css=div.home-listing-common-header-text > span.left"));
                verifyTrue(selenium.isElementPresent("//div[@id='products']/div[2]/div/div/span"));
                verifyTrue(selenium.isElementPresent("css=div.cart-top"));
                verifyTrue(selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
                verifyTrue(selenium.isElementPresent("css=#browsehistory > div.common-widget-top-bar > div.common-widget-top-bar-text > span.common-widget-top-bar-text-right"));
                verifyEquals("BEST SELLERS", selenium.getText("//div[@id='products']/div[3]/div/div/span"));
                verifyTrue(selenium.isElementPresent("css=div.home-listing-common-content.best-sellers"));
                verifyTrue(selenium.isElementPresent("css=div.home-listing-common-content.latest-arrivals"));
                verifyTrue(selenium.isElementPresent("css=div.home-listing-common-content.best-deals"));
                for(int j=1;j<=47;j++)
                {
                        //System.out.println("abc"+i+"");
                        //selenium.isElementPresent("dom=document.images["+i+"]");
                        //assertTrue("Not able to buy Product",selenium.isElementPresent("dom=document.images["+i+"]"));
                selenium.click("dom=document.images[4]");
                Thread.sleep(20000);
                selenium.waitForPageToLoad("30000");
                Thread.sleep(8000);
                com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Product detail element not found",selenium.isElementPresent("id=productDetail"),selenium);
                //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);
                
                com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Cart Summary not displayed",selenium.isElementPresent("css=div.cart-top"),selenium);
                verifyTrue(selenium.isElementPresent("css=#accessories > div.common-widget-top-bar > div.common-widget-top-bar-text"));
                com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Add to card button not present",selenium.isElementPresent("id=addToCart"),selenium);
                verifyTrue(selenium.isElementPresent("css=div.cart-top"));
                verifyTrue(selenium.isElementPresent("css=div.common-widget-top-bar-text"));
                verifyTrue(selenium.isElementPresent("css=#myresearch > div.common-widget-top-bar > div.common-widget-top-bar-text"));
                verifyTrue(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("id=Image1"));
                verifyEquals("Look n Feel", selenium.getText("//ul[@id='sideNav']/li[2]/a/span"));
                verifyEquals("Introduction", selenium.getText("css=a.vt > span"));
                verifyTrue(selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
                selenium.setTimeout("60000");
                selenium.click("id=addToCart");
                Thread.sleep(10000);
                if(selenium.isVisible("id=cboxLoadedContent"))
                {
                        selenium.goBack();
                        Thread.sleep(15000);
                        //selenium.click("link=HOME");
                        continue;
                }
                //Thread.sleep(6000);
                verifyEquals("Cart Details", selenium.getText("css=span.label"));
                verifyEquals("Shipping Info.", selenium.getText("//div[@id='cartFlowHeader']/div[2]/span[2]"));
                verifyEquals("Make Payment", selenium.getText("//div[@id='cartFlowHeader']/div[3]/span[2]"));
                verifyEquals("Order Status", selenium.getText("//div[@id='cartFlowHeader']/div[4]/span[2]"));
                verifyTrue(selenium.isElementPresent("id=zipcode"));
                verifyTrue(selenium.isElementPresent("id=computeEstimate"));
                verifyEquals("Total Amount:", selenium.getText("css=tr.total-amount.payable > td.label"));
                Thread.sleep(6000);
                verifyTrue(selenium.isElementPresent("xpath=//div[@class='cartflow-main-action-button right checkout-button-below']"));
                selenium.click("xpath=//div[@class='cartflow-main-action-button right checkout-button-below']");
                Thread.sleep(6000);
                selenium.type("id=loginEmail", "kshitijsood@ymail.com");
                selenium.type("id=loginPassword", "123abc");
                selenium.click("id=submitAddress");
                selenium.waitForPageToLoad("30000");
                verifyEquals("Shipping Info.", selenium.getText("//div[@id='cartFlowHeader']/div/span[2]"));
                verifyEquals("Item & Color", selenium.getText("css=th.first"));
                verifyEquals("Delivery Time", selenium.getText("//table[@id='cartDetail']/thead/tr/th[2]"));
                verifyEquals("Total Price", selenium.getText("//table[@id='cartDetail']/thead/tr/th[3]"));
                verifyTrue(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);
                selenium.click("id=proceedToPay");
                selenium.waitForPageToLoad("30000");
                Thread.sleep(5000);
                assertEquals("Make Payment", selenium.getText("//div[@id='cartFlowHeader']/div/span[2]"));
                assertEquals("Amount to be Paid:", selenium.getText("css=h4 > span"));
                String htmlstr = selenium.getBodyText();
        int pos = htmlstr.indexOf("Amount to be Paid:");
        //System.out.println("Index is " + pos);
        int pos1=pos+21;
        int pos2=pos+30;
        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);
        verifyTrue(selenium.isTextPresent("CREDIT CARDS"));
                verifyTrue(selenium.isTextPresent("EMI"));
                verifyTrue(selenium.isTextPresent("DEBIT/ATM CARDS"));
                verifyTrue(selenium.isTextPresent("NET BANKING"));
                verifyTrue(selenium.isTextPresent("CASH CARDS"));
                assertTrue(selenium.isElementPresent("css=input.make-payment-button"));
                selenium.click("//div[@id='vtab']/ul/li[3]");
                Thread.sleep(5000);
                selenium.click("name=payment_option value=1001");
                selenium.click("xpath=(//input[@value='MAKE PAYMENT'])[3]");
                selenium.waitForPageToLoad("30000");
                selenium.type("id=frm_name_on_card", "Test");
                selenium.type("id=frm_number", "4111");
                selenium.type("name=number_2", "1111");
                selenium.type("name=number_3", "1111");
                selenium.type("name=number_4", "1111");
                selenium.select("//select[@id='frm_exp_month']", "label=07 (Jul)");
                selenium.select("//select[@id='frm_exp_year']", "label=2016");
                selenium.type("id=frm_cvv", "123");
                selenium.click("id=submitted");
                Thread.sleep(15000);
                selenium.deleteAllVisibleCookies();
                selenium.click("link=HOME");
                Thread.sleep(10000);
                selenium.waitForPageToLoad("30000");
                }
        
        }
        @After
        public void tearDown() throws Exception {
                selenium.stop();
        //stopSeleniumServer();
                try {
                if (null != loggingWriter) {
                    loggingWriter.close();
                }
            } catch (IOException e) {
              System.out.println("IO exception");
            }
        }
}