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 com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter;
8
import com.unitedinternet.portal.selenium.utils.logging.LoggingCommandProcessor;
9
import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium;
10
import com.unitedinternet.portal.selenium.utils.logging.LoggingResultsFormatter;
11
import com.unitedinternet.portal.selenium.utils.logging.LoggingSelenium;
12
import com.unitedinternet.portal.selenium.utils.logging.LoggingUtils;
13
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals;
14
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue;
15
import org.junit.After;
16
import org.junit.Before;
17
import org.junit.Test;
18
//import org.openqa.selenium.server.SeleniumServer;
19
 
20
//import java.util.regex.Pattern;
21
 
22
public class fakeorders extends SeleneseTestBase {
23
 
24
 
25
	BufferedWriter loggingWriter;
26
	protected LoggingSelenium selenium;
27
	final String resultbasePath = "/opt/seleniumTests/results/shop2020";
28
	//final String resultbasePath = "/opt/seleniumTests/results";
29
    final String resultHtmlFileName = resultbasePath + "/" + "result0.html";
30
    final String resultEncoding = "UTF-8";	    
31
    final String screenshotpath="screenshot";
32
    final String screenshotresultPath=new File(resultbasePath+"/"+screenshotpath).getAbsolutePath();
33
	@Before
34
	public void setUp() throws Exception {
35
		if (!new File(screenshotresultPath).exists()) {
36
			 new File(screenshotresultPath).mkdirs();
37
		}
38
	    loggingWriter = LoggingUtils.createWriter(resultHtmlFileName, resultEncoding , true);
39
	    LoggingResultsFormatter htmlFormatter = 
40
	        new HtmlResultFormatter(loggingWriter, resultEncoding);
41
	   htmlFormatter.setScreenShotBaseUri(resultbasePath+"/"+screenshotpath+"/"); // this is for linking to the screenshots
42
	   htmlFormatter.setAutomaticScreenshotPath(screenshotresultPath);
43
	    // wrap HttpCommandProcessor from remote-control
44
	    LoggingCommandProcessor myProcessor = 
45
	    new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", "http://saholic:shop2020@shop2020.in:8080/"), htmlFormatter);
46
	    //new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", "http://saholic.com/"), htmlFormatter);
47
	    selenium = new LoggingDefaultSelenium(myProcessor);
48
	    myProcessor.setExcludedCommands(new String[] {});
49
	    selenium.start();	
50
	}
51
 
52
	@Test(expected=AssertionError.class)
53
	public void testBuyproductonprod() throws Exception {
54
		selenium.setContext("testBuyprodonprod()");
55
		selenium.setTimeout("60000");
56
		selenium.open("/");
57
		selenium.windowMaximize();
58
		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);
59
		verifyTrue(selenium.isElementPresent("css=img[alt=\"Shop2020\"]"));
60
		verifyTrue(selenium.isTextPresent("Search All"));
61
		verifyTrue(selenium.isElementPresent("id=searchButton"));
62
		verifyEquals("BEST DEALS", selenium.getText("css=div.home-listing-common-header-text > span.left"));
63
		verifyTrue(selenium.isElementPresent("//div[@id='products']/div[2]/div/div/span"));
64
		verifyTrue(selenium.isElementPresent("css=div.cart-top"));
65
		verifyTrue(selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
66
		verifyTrue(selenium.isElementPresent("css=#browsehistory > div.common-widget-top-bar > div.common-widget-top-bar-text > span.common-widget-top-bar-text-right"));
67
		verifyEquals("BEST SELLERS", selenium.getText("//div[@id='products']/div[3]/div/div/span"));
68
		verifyTrue(selenium.isElementPresent("css=div.home-listing-common-content.best-sellers"));
69
		verifyTrue(selenium.isElementPresent("css=div.home-listing-common-content.latest-arrivals"));
70
		verifyTrue(selenium.isElementPresent("css=div.home-listing-common-content.best-deals"));
71
		for(int j=1;j<=47;j++)
72
		{
73
			//System.out.println("abc"+i+"");
74
			//selenium.isElementPresent("dom=document.images["+i+"]");
75
			//assertTrue("Not able to buy Product",selenium.isElementPresent("dom=document.images["+i+"]"));
76
		selenium.click("dom=document.images[4]");
77
		Thread.sleep(20000);
78
		selenium.waitForPageToLoad("30000");
79
		Thread.sleep(8000);
80
		com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Product detail element not found",selenium.isElementPresent("id=productDetail"),selenium);
81
		//selenium.captureScreenshot(screenshotresultPath+"/"+"ErrorPage"+".png");
82
		//com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Failed assert",selenium.isElementPresent("id=productDetail"),selenium);
83
		//com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Cart Summary not displayed",selenium.isElementPresent("css=div.cart"),selenium);
84
 
85
		com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Cart Summary not displayed",selenium.isElementPresent("css=div.cart-top"),selenium);
86
		verifyTrue(selenium.isElementPresent("css=#accessories > div.common-widget-top-bar > div.common-widget-top-bar-text"));
87
		com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue("Add to card button not present",selenium.isElementPresent("id=addToCart"),selenium);
88
		verifyTrue(selenium.isElementPresent("css=div.cart-top"));
89
		verifyTrue(selenium.isElementPresent("css=div.common-widget-top-bar-text"));
90
		verifyTrue(selenium.isElementPresent("css=#myresearch > div.common-widget-top-bar > div.common-widget-top-bar-text"));
91
		verifyTrue(selenium.isElementPresent("css=#browsehistory > div.common-widget-top-bar > div.common-widget-top-bar-text > span.common-widget-top-bar-text-right"));
92
        verifyTrue(selenium.isElementPresent("id=Image1"));
93
		verifyEquals("Look n Feel", selenium.getText("//ul[@id='sideNav']/li[2]/a/span"));
94
		verifyEquals("Introduction", selenium.getText("css=a.vt > span"));
95
		verifyTrue(selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
96
		selenium.setTimeout("60000");
97
		selenium.click("id=addToCart");
98
		Thread.sleep(10000);
99
		if(selenium.isVisible("id=cboxLoadedContent"))
100
		{
101
			selenium.goBack();
102
			Thread.sleep(15000);
103
			//selenium.click("link=HOME");
104
			continue;
105
		}
106
		//Thread.sleep(6000);
107
		verifyEquals("Cart Details", selenium.getText("css=span.label"));
108
		verifyEquals("Shipping Info.", selenium.getText("//div[@id='cartFlowHeader']/div[2]/span[2]"));
109
		verifyEquals("Make Payment", selenium.getText("//div[@id='cartFlowHeader']/div[3]/span[2]"));
110
		verifyEquals("Order Status", selenium.getText("//div[@id='cartFlowHeader']/div[4]/span[2]"));
111
		verifyTrue(selenium.isElementPresent("id=zipcode"));
112
		verifyTrue(selenium.isElementPresent("id=computeEstimate"));
113
		verifyEquals("Total Amount:", selenium.getText("css=tr.total-amount.payable > td.label"));
114
		Thread.sleep(6000);
115
		verifyTrue(selenium.isElementPresent("xpath=//div[@class='cartflow-main-action-button right checkout-button-below']"));
116
		selenium.click("xpath=//div[@class='cartflow-main-action-button right checkout-button-below']");
117
		Thread.sleep(6000);
118
		selenium.type("id=loginEmail", "kshitijsood@ymail.com");
119
		selenium.type("id=loginPassword", "123abc");
120
		selenium.click("id=submitAddress");
121
		selenium.waitForPageToLoad("30000");
122
		verifyEquals("Shipping Info.", selenium.getText("//div[@id='cartFlowHeader']/div/span[2]"));
123
		verifyEquals("Item & Color", selenium.getText("css=th.first"));
124
		verifyEquals("Delivery Time", selenium.getText("//table[@id='cartDetail']/thead/tr/th[2]"));
125
		verifyEquals("Total Price", selenium.getText("//table[@id='cartDetail']/thead/tr/th[3]"));
126
		verifyTrue(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
		selenium.click("id=proceedToPay");
130
		selenium.waitForPageToLoad("30000");
131
		Thread.sleep(5000);
132
		assertEquals("Make Payment", selenium.getText("//div[@id='cartFlowHeader']/div/span[2]"));
133
		assertEquals("Amount to be Paid:", selenium.getText("css=h4 > span"));
134
		String htmlstr = selenium.getBodyText();
135
    	int pos = htmlstr.indexOf("Amount to be Paid:");
136
    	//System.out.println("Index is " + pos);
137
    	int pos1=pos+21;
138
    	int pos2=pos+30;
139
    	String amount;
140
    	amount = htmlstr.substring(pos1, pos2);
141
    	//System.out.println("pos1 pos2" + pos1 + ":" + pos2);
142
    	//int price=Integer.parseInt(amount);
143
    	//System.out.println("Amount : :" + amount + ":" + price );
144
    	amount=amount.replaceAll(",", "");
145
    	System.out.println("Amount : :" + amount);
146
    	///double price = Integer.parseInt(amount);
147
    	double price = Double.parseDouble(amount);
148
    	System.out.println("Price : :" + price);
149
    	verifyTrue(selenium.isTextPresent("CREDIT CARDS"));
150
		verifyTrue(selenium.isTextPresent("EMI"));
151
		verifyTrue(selenium.isTextPresent("DEBIT/ATM CARDS"));
152
		verifyTrue(selenium.isTextPresent("NET BANKING"));
153
		verifyTrue(selenium.isTextPresent("CASH CARDS"));
154
		assertTrue(selenium.isElementPresent("css=input.make-payment-button"));
155
		selenium.click("//div[@id='vtab']/ul/li[3]");
156
		Thread.sleep(5000);
157
		selenium.click("name=payment_option value=1001");
158
		selenium.click("xpath=(//input[@value='MAKE PAYMENT'])[3]");
159
		selenium.waitForPageToLoad("30000");
160
		selenium.type("id=frm_name_on_card", "Test");
161
		selenium.type("id=frm_number", "4111");
162
		selenium.type("name=number_2", "1111");
163
		selenium.type("name=number_3", "1111");
164
		selenium.type("name=number_4", "1111");
165
		selenium.select("//select[@id='frm_exp_month']", "label=07 (Jul)");
166
		selenium.select("//select[@id='frm_exp_year']", "label=2016");
167
		selenium.type("id=frm_cvv", "123");
168
		selenium.click("id=submitted");
169
		Thread.sleep(15000);
170
		selenium.deleteAllVisibleCookies();
171
		selenium.click("link=HOME");
172
		Thread.sleep(10000);
173
		selenium.waitForPageToLoad("30000");
174
		}
175
 
176
	}
177
	@After
178
	public void tearDown() throws Exception {
179
		selenium.stop();
180
        //stopSeleniumServer();
181
		try {
182
	        if (null != loggingWriter) {
183
	            loggingWriter.close();
184
	        }
185
	    } catch (IOException e) {
186
	      System.out.println("IO exception");
187
	    }
188
	}
189
}