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