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_Tablets 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
 
28
	//selenium.open(url);
29
	selenium.windowMaximize();
30
}
31
 
32
 
33
	@Test(description="Tablets")
34
	public void testBuyproductonprod() throws Exception {
35
		Thread.sleep(10000);
36
 
37
 
38
		selenium.setTimeout("60000");
39
		selenium.open("/");
40
 
41
		selenium.setContext("Tablets");
42
		//String s=selenium.getCookieByName("JSESSIONID");
43
		//System.out.println(s);
44
 
45
		//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);
46
		assertEquals("Mobile Phone Reviews and Best Deals in India | shop2020.in", selenium.getTitle());
47
 
48
		assertTrue("Logo not present",selenium.isElementPresent("css=img[alt=\"Shop2020\"]"));
49
		assertTrue("Search all not found",selenium.isTextPresent("Search"));
50
		assertTrue("Element searchButton not found ",selenium.isElementPresent("id=searchButton"));
51
		assertEquals("BEST DEALS", selenium.getText("css=div.home-listing-common-header-text > span.left"));
52
		assertTrue("//div[@id='products']/div[2]/div/div/span not found",selenium.isElementPresent("//div[@id='products']/div[2]/div/div/span"));
53
 
54
		assertTrue("css=span.common-widget-top-bar-text-right not found",selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
55
		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"));
56
		System.out.println(selenium.getText("//div[@id='products']/div[3]/div/div/span"));
57
		assertTrue("BEST SELLERS not found",selenium.isTextPresent("BEST SELLERS") );
58
		assertTrue("LATEST ARRIVALS not found",selenium.isTextPresent("LATEST ARRIVALS") );
59
		assertTrue("css=div.home-listing-common-content.best-sellers not found",selenium.isElementPresent("css=div.home-listing-common-content.best-sellers"));
60
		assertTrue("css=div.home-listing-common-content.latest-arrivals not found",selenium.isElementPresent("css=div.home-listing-common-content.latest-arrivals"));
61
		assertTrue("css=div.home-listing-common-content.best-deals not found",selenium.isElementPresent("css=div.home-listing-common-content.best-deals"));
62
		Thread.sleep(10000);
63
		selenium.click("link=TABLETS");
64
		selenium.waitForPageToLoad("60000");
65
		Thread.sleep(30000);
66
		//com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals("Tablets Price List India | Tablets | saholic.com not Found","Tablets Price List India | Tablets | saholic.com", selenium.getTitle(),selenium);
67
		assertEquals("Tablets Price List India | Tablets | shop2020.in", selenium.getTitle());
68
		assertTrue("id=catTab1-first not found",selenium.isElementPresent("id=catTab1-first"));
69
		assertTrue("id=catTab4-10010 not found",selenium.isElementPresent("id=catTab4-10010"));
70
		assertTrue("id=catTab3-10010 not found",selenium.isElementPresent("id=catTab3-10010"));
71
		assertTrue("id=catTab2-10010 not found",selenium.isElementPresent("id=catTab2-10010"));
72
		assertTrue("css=div.productListTop not found",selenium.isElementPresent("css=div.productListTop"));
73
		assertTrue("css=div.productListBottom not found",selenium.isElementPresent("css=div.productListBottom"));
74
		assertTrue("css=div.productDetails not found",selenium.isElementPresent("css=div.productDetails"));
75
		assertTrue("css=div.sectionHeader not found",selenium.isElementPresent("css=div.sectionHeader"));
76
		assertTrue("css=#filterByPrice > div.filterHeading > div.sectionHeader not found",selenium.isElementPresent("css=#filterByPrice > div.filterHeading > div.sectionHeader"));
77
		assertTrue("css=div.ui-slider-range.ui-widget-header not found",selenium.isElementPresent("css=div.ui-slider-range.ui-widget-header"));
78
 
79
		//assertTrue("css=div.cart-middle not found",selenium.isElementPresent("css=div.cart-middle"));
80
 
81
        assertTrue("css=div.common-widget-top-bar-text not found",selenium.isElementPresent("css=div.common-widget-top-bar-text"));
82
        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"));
83
        //verifyTrue(selenium.isElementPresent(""));
84
        assertTrue("Price not found",selenium.isTextPresent("Price"));
85
        assertTrue("Brand not found",selenium.isTextPresent("Brand"));
86
        assertTrue("Camera Resolution",selenium.isTextPresent("Camera Resolution"));
87
        for(int i=1;i<15;i++)
88
		{
89
			System.out.println("abc"+i+"");
90
			selenium.isElementPresent("dom=document.images["+i+"]");
91
			System.out.println("dom=document.images["+i+"]");
92
			assertTrue("Not able to buy Product",selenium.isElementPresent("dom=document.images["+i+"]"));
93
		selenium.click("dom=document.images["+i+"]");
94
		Thread.sleep(30000);
95
		selenium.waitForPageToLoad("60000");
96
		Thread.sleep(8000);
97
		assertTrue("Product detail element not found",selenium.isElementPresent("id=productDetail"));
98
 
99
		//selenium.captureScreenshot(screenshotresultPath+"/"+"ErrorPage"+".png");
100
		//com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Failed assert",selenium.isElementPresent("id=productDetail"),selenium);
101
		//com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Cart Summary not displayed",selenium.isElementPresent("css=div.cart"),selenium);
102
 
103
		//assertTrue("Cart Summary not displayed",selenium.isElementPresent("css=div.cart-top"));
104
		//verifyTrue(selenium.isElementPresent("css=#accessories > div.common-widget-top-bar > div.common-widget-top-bar-text"));
105
		assertTrue("Add to card button not present",selenium.isElementPresent("id=addToCart"));
106
 
107
		assertTrue("css=div.common-widget-top-bar-text not found",selenium.isElementPresent("css=div.common-widget-top-bar-text"));
108
		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"));
109
		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"));
110
        //assertTrue("id=Image1 not found",selenium.isElementPresent("id=Image1"));
111
		verifyEquals("Look n Feel", selenium.getText("//ul[@id='sideNav']/li[2]/a/span"));
112
		verifyEquals("Introduction", selenium.getText("css=a.vt > span"));
113
		assertTrue(selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
114
		selenium.setTimeout("60000");
115
		selenium.click("id=addToCart");
116
		Thread.sleep(30000);
117
		if(selenium.isVisible("id=cboxWrapper"))
118
		{
119
			selenium.goBack();
120
			Thread.sleep(15000);
121
			//selenium.click("link=HOME");
122
			continue;
123
		}
124
		break;
125
		}
126
        System.out.println("<----CART PAGE TABLETS THREAD---->");
127
        assertTrue("cartFlowHeader not found",selenium.isElementPresent("id=cartFlowHeader"));
128
		assertTrue("Cart details not found",selenium.isTextPresent("Cart Details"));
129
		assertTrue("Shipping Info. not found",selenium.isTextPresent("Shipping Info."));
130
		assertTrue("Make Payment not found",selenium.isTextPresent("Make Payment"));
131
		assertTrue("Order Status not found",selenium.isTextPresent("Order Status"));
132
		assertTrue("id=zipcode not found",selenium.isElementPresent("id=zipcode"));
133
		assertTrue("id=computeEstimate not found",selenium.isElementPresent("id=computeEstimate"));
134
		verifyEquals("Total Amount:", selenium.getText("css=tr.total-amount.payable > td.label"));
135
		Thread.sleep(6000);
136
		Thread.sleep(10000);
137
		assertEquals("ENTER SHIPPING INFO >",selenium.getText("id=poplogin"));
138
		selenium.click("id=poplogin");
139
		Thread.sleep(15000);
140
		selenium.type("id=loginEmail", "kshitijsood@ymail.com");
141
		selenium.type("id=loginPassword", "123abc");
142
		selenium.click("id=submitAddress");
143
		Thread.sleep(30000);
144
		 System.out.println("<----SHIPPING PAGE TABLETS THREAD---->");
145
		assertEquals("Item & Color", selenium.getText("css=th.first"));
146
		assertEquals("Delivery Time", selenium.getText("//table[@id='cartDetail']/thead/tr/th[2]"));
147
		assertEquals("Total Price", selenium.getText("//table[@id='cartDetail']/thead/tr/th[3]"));
148
		assertTrue("Select Shipping Address not found",selenium.isTextPresent("Select Shipping Address"));
149
		Thread.sleep(5000);
150
		//com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals("Proceed to payment button not present","PROCEED TO PAYMENT >", selenium.getText("id=proceedToPay"),selenium);
151
		assertEquals("PROCEED TO PAYMENT >", selenium.getText("id=proceedToPay"));
152
		selenium.click("id=proceedToPay");
153
		Thread.sleep(30000);
154
		 System.out.println("<----PROCEED TO PAY PAGE TABLETS THREAD---->");
155
		assertTrue("cartFlowHeader not found",selenium.isElementPresent("id=cartFlowHeader"));
156
		assertTrue("Cart details not found",selenium.isTextPresent("Cart Details"));
157
		assertTrue("Shipping Info. not found",selenium.isTextPresent("Shipping Info."));
158
		assertTrue("Make Payment not found",selenium.isTextPresent("Make Payment"));
159
		assertTrue("Order Status not found",selenium.isTextPresent("Order Status"));
160
		assertEquals("Order Amount:", selenium.getText("css=h4 > span"));
161
		String htmlstr = selenium.getBodyText();
162
    	int pos = htmlstr.indexOf("Order Amount:");
163
    	//System.out.println("Index is " + pos);
164
    	int pos1=pos+16;
165
    	int pos2=pos+28;
166
    	String amount;
167
    	amount = htmlstr.substring(pos1, pos2);
168
    	//System.out.println("pos1 pos2" + pos1 + ":" + pos2);
169
    	//int price=Integer.parseInt(amount);
170
    	//System.out.println("Amount : :" + amount + ":" + price );
171
    	amount=amount.replaceAll(",", "");
172
    	System.out.println("Amount : :" + amount);
173
    	///double price = Integer.parseInt(amount);
174
    	double price = Double.parseDouble(amount);
175
    	System.out.println("Price : :" + price);
176
    	assertTrue("CREDIT CARDS not found",selenium.isTextPresent("CREDIT CARDS"));
177
		assertTrue("EMI not found",selenium.isTextPresent("EMI"));
178
		assertTrue("DEBIT/ATM CARDS not found",selenium.isTextPresent("DEBIT/ATM CARDS"));
179
		assertTrue("NET BANKING not found",selenium.isTextPresent("NET BANKING"));
180
		assertTrue("CASH CARDS not found",selenium.isTextPresent("CASH CARDS"));
181
		assertTrue("css=input.make-payment-button not found",selenium.isElementPresent("css=input.make-payment-button"));
182
		if((price > 300) && (price < 20000))
183
		{
184
		assertTrue("CASH ON DELIVERY not found",selenium.isTextPresent("CASH ON DELIVERY"));	
185
		selenium.click("//div[@id='vtab']/ul/li[6]");
186
		assertTrue("id=captcha_response_box not found",selenium.isElementPresent("id=captcha_response_box"));
187
		assertTrue("id=captchaImage not found",selenium.isElementPresent("id=captchaImage"));
188
 
189
		assertTrue(selenium.isElementPresent("css=div.text-center > input.make-payment-button"));
190
		}
191
		selenium.deleteAllVisibleCookies();
192
	}
193
	@AfterClass
194
	public void clear() {	
195
		selenium.selectWindow(selenium.getTitle());
196
		selenium.captureScreenshot("tablets_shop2020.png");
197
		selenium.stop();
198
	}	
199
	}