Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8614 kshitij.so 1
package com;
2
import java.io.BufferedWriter;
3
import java.io.File;
4
import java.io.IOException;
5
 
6
import com.thoughtworks.selenium.*;
7
 
8
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals;
9
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue;
10
import org.testng.annotations.AfterClass;
11
import org.testng.annotations.BeforeClass;
12
import org.testng.annotations.Test;
13
//import org.openqa.selenium.server.SeleniumServer;
14
 
15
//import java.util.regex.Pattern;
16
 
17
public class Buyproductonshop2020_clearance extends SeleneseTestBase {
18
 
19
 
20
	String url = "";
21
	private Selenium selenium= null;
22
 
23
@BeforeClass
24
public void startBrowser() {
25
    selenium= new DefaultSelenium("localhost", 4444, "*firefox", "http://saholic:shop2020@shop2020.in:8080/");
26
	selenium.start();
27
	//selenium.open(url);
28
	selenium.windowMaximize();
29
}
30
 
31
	@Test(description="Clearance Sale")
32
	public void testBuyproductonprod() throws Exception {
33
		Thread.sleep(10000);
34
		selenium.setContext("Clearance");
35
		selenium.setTimeout("60000");
36
		selenium.open("/");
37
		//selenium.windowMaximize();
38
	    //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);
39
		assertEquals("Mobile Phone Reviews and Best Deals in India | shop2020.in", selenium.getTitle());
40
		assertTrue("Logo not present",selenium.isElementPresent("css=img[alt=\"Shop2020\"]"));
41
		assertTrue("Search all not found",selenium.isTextPresent("Search"));
42
		assertTrue("Element searchButton not found ",selenium.isElementPresent("id=searchButton"));
43
		assertEquals("BEST DEALS", selenium.getText("css=div.home-listing-common-header-text > span.left"));
44
		assertTrue("//div[@id='products']/div[2]/div/div/span not found",selenium.isElementPresent("//div[@id='products']/div[2]/div/div/span"));
45
 
46
		assertTrue("css=span.common-widget-top-bar-text-right not found",selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
47
		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"));
48
		System.out.println(selenium.getText("//div[@id='products']/div[3]/div/div/span"));
49
		assertTrue("BEST SELLERS not found",selenium.isTextPresent("BEST SELLERS") );
50
		assertTrue("LATEST ARRIVALS not found",selenium.isTextPresent("LATEST ARRIVALS") );
51
		assertTrue("css=div.home-listing-common-content.best-sellers not found",selenium.isElementPresent("css=div.home-listing-common-content.best-sellers"));
52
		assertTrue("css=div.home-listing-common-content.latest-arrivals not found",selenium.isElementPresent("css=div.home-listing-common-content.latest-arrivals"));
53
		assertTrue("css=div.home-listing-common-content.best-deals not found",selenium.isElementPresent("css=div.home-listing-common-content.best-deals"));
54
		Thread.sleep(14000);
55
		selenium.click("link=Clearance Sale");
56
		selenium.waitForPageToLoad("60000");
57
		Thread.sleep(30000);
58
		//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);
59
		assertEquals("Clearance Sale | shop2020.in", selenium.getTitle());
60
		//assertTrue("css=div.cart-top",selenium.isElementPresent("css=div.cart-top"));
61
		//assertTrue("css=div.cart-middle",selenium.isElementPresent("css=div.cart-middle"));
62
		//assertTrue("css=div.cart-bottom",selenium.isElementPresent("css=div.cart-bottom"));
63
        assertTrue("css=div.common-widget-top-bar-text",selenium.isElementPresent("css=div.common-widget-top-bar-text"));
64
        assertTrue(selenium.isElementPresent("css=#browsehistory > div.common-widget-top-bar > div.common-widget-top-bar-text > span.common-widget-top-bar-text-right"));
65
        //verifyTrue(selenium.isElementPresent(""));
66
        for(int i=3;i<15;i++)
67
		{
68
			System.out.println("abc"+i+"");
69
			selenium.isElementPresent("dom=document.images["+i+"]");
70
			System.out.println("dom=document.images["+i+"]");
71
			assertTrue("Not able to buy Product",selenium.isElementPresent("dom=document.images["+i+"]"));
72
		selenium.click("dom=document.images["+i+"]");
73
		Thread.sleep(30000);
74
		selenium.waitForPageToLoad("60000");
75
		Thread.sleep(8000);
76
		assertTrue("Product detail element not found",selenium.isElementPresent("id=productDetail"));
77
		//selenium.captureScreenshot(screenshotresultPath+"/"+"ErrorPage"+".png");
78
		//com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Failed assert",selenium.isElementPresent("id=productDetail"),selenium);
79
		//com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Cart Summary not displayed",selenium.isElementPresent("css=div.cart"),selenium);
80
 
81
		//assertTrue("Cart Summary not displayed",selenium.isElementPresent("css=div.cart-top"));
82
		//verifyTrue(selenium.isElementPresent("css=#accessories > div.common-widget-top-bar > div.common-widget-top-bar-text"));
83
		assertTrue("Add to card button not present",selenium.isElementPresent("id=addToCart"));
84
 
85
		assertTrue("css=div.common-widget-top-bar-text not found",selenium.isElementPresent("css=div.common-widget-top-bar-text"));
86
		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"));
87
		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"));
88
        //assertTrue("id=Image1 not found",selenium.isElementPresent("id=Image1"));
89
		verifyEquals("Look n Feel", selenium.getText("//ul[@id='sideNav']/li[2]/a/span"));
90
		verifyEquals("Introduction", selenium.getText("css=a.vt > span"));
91
		assertTrue(selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
92
		selenium.setTimeout("60000");
93
		selenium.click("id=addToCart");
94
		Thread.sleep(30000);
95
		if(selenium.isVisible("id=cboxWrapper"))
96
		{
97
			selenium.goBack();
98
			Thread.sleep(15000);
99
			//selenium.click("link=HOME");
100
			continue;
101
		}
102
		break;
103
		}
104
        System.out.println("<----CART PAGE CLEARANCE_SALE THREAD---->");
105
        assertTrue("cartFlowHeader not found",selenium.isElementPresent("id=cartFlowHeader"));
106
		assertTrue("Cart details not found",selenium.isTextPresent("Cart Details"));
107
		assertTrue("Shipping Info. not found",selenium.isTextPresent("Shipping Info."));
108
		assertTrue("Make Payment not found",selenium.isTextPresent("Make Payment"));
109
		assertTrue("Order Status not found",selenium.isTextPresent("Order Status"));
110
		assertTrue("id=zipcode not found",selenium.isElementPresent("id=zipcode"));
111
		assertTrue("id=computeEstimate not found",selenium.isElementPresent("id=computeEstimate"));
112
		verifyEquals("Total Amount:", selenium.getText("css=tr.total-amount.payable > td.label"));
113
		Thread.sleep(6000);
114
		Thread.sleep(10000);
115
		assertEquals("ENTER SHIPPING INFO >",selenium.getText("id=poplogin"));
116
		selenium.click("id=poplogin");
117
		Thread.sleep(15000);
118
		selenium.type("id=loginEmail", "kshitijsood@ymail.com");
119
		selenium.type("id=loginPassword", "123abc");
120
		selenium.click("id=submitAddress");
121
		Thread.sleep(30000);
122
		 System.out.println("<----SHIPPING PAGE CLEARANCE_SALE THREAD---->");
123
		assertEquals("Item & Color", selenium.getText("css=th.first"));
124
		assertEquals("Delivery Time", selenium.getText("//table[@id='cartDetail']/thead/tr/th[2]"));
125
		assertEquals("Total Price", selenium.getText("//table[@id='cartDetail']/thead/tr/th[3]"));
126
		assertTrue("Select Shipping Address not found",selenium.isTextPresent("Select Shipping Address"));
127
		Thread.sleep(5000);
128
		//com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals("Proceed to payment button not present","PROCEED TO PAYMENT >", selenium.getText("id=proceedToPay"),selenium);
129
		assertEquals("PROCEED TO PAYMENT >", selenium.getText("id=proceedToPay"));
130
		selenium.click("id=proceedToPay");
131
		Thread.sleep(30000);
132
		 System.out.println("<----PROCEED TO PAY PAGE CLEARANCE_SALE THREAD---->");
133
		assertTrue("cartFlowHeader not found",selenium.isElementPresent("id=cartFlowHeader"));
134
		assertTrue("Cart details not found",selenium.isTextPresent("Cart Details"));
135
		assertTrue("Shipping Info. not found",selenium.isTextPresent("Shipping Info."));
136
		assertTrue("Make Payment not found",selenium.isTextPresent("Make Payment"));
137
		assertTrue("Order Status not found",selenium.isTextPresent("Order Status"));
138
		assertEquals("Order Amount:", selenium.getText("css=h4 > span"));
139
		String htmlstr = selenium.getBodyText();
140
    	int pos = htmlstr.indexOf("Order Amount:");
141
    	//System.out.println("Index is " + pos);
142
    	int pos1=pos+16;
143
    	int pos2=pos+28;
144
    	String amount;
145
    	amount = htmlstr.substring(pos1, pos2);
146
    	//System.out.println("pos1 pos2" + pos1 + ":" + pos2);
147
    	//int price=Integer.parseInt(amount);
148
    	//System.out.println("Amount : :" + amount + ":" + price );
149
    	amount=amount.replaceAll(",", "");
150
    	System.out.println("Amount : :" + amount);
151
    	///double price = Integer.parseInt(amount);
152
    	double price = Double.parseDouble(amount);
153
    	System.out.println("Price : :" + price);
154
    	assertTrue("CREDIT CARDS not found",selenium.isTextPresent("CREDIT CARDS"));
155
		assertTrue("EMI not found",selenium.isTextPresent("EMI"));
156
		assertTrue("DEBIT/ATM CARDS not found",selenium.isTextPresent("DEBIT/ATM CARDS"));
157
		assertTrue("NET BANKING not found",selenium.isTextPresent("NET BANKING"));
158
		assertTrue("CASH CARDS not found",selenium.isTextPresent("CASH CARDS"));
159
		assertTrue("css=input.make-payment-button not found",selenium.isElementPresent("css=input.make-payment-button"));
160
		if((price > 300) && (price < 20000))
161
		{
162
		assertTrue("CASH ON DELIVERY not found",selenium.isTextPresent("CASH ON DELIVERY"));	
163
		selenium.click("//div[@id='vtab']/ul/li[6]");
164
		assertTrue("id=captcha_response_box not found",selenium.isElementPresent("id=captcha_response_box"));
165
		assertTrue("id=captchaImage not found",selenium.isElementPresent("id=captchaImage"));
166
		assertTrue(selenium.isElementPresent("css=div.text-center > input.make-payment-button"));
167
		}
168
		selenium.deleteAllVisibleCookies();
169
	}
170
	@AfterClass
171
	public void clear() {
172
		selenium.selectWindow(selenium.getTitle());
173
		selenium.captureScreenshot("clearance_shop2020.png");
174
		selenium.stop();
175
	}	
176
	}