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 Buyproductonprod_Recharge extends SeleneseTestBase {
23
 
24
 
25
	BufferedWriter loggingWriter;
26
	protected LoggingSelenium selenium;
27
	final String resultbasePath = "/opt/seleniumTests/results/prod";
28
	//final String resultbasePath = "/opt/seleniumTests/results";
29
    final String resultHtmlFileName = resultbasePath + "/" + "result9.html";
30
    final String resultEncoding = "UTF-8";	    
31
    final String screenshotpath="screenshot";
32
    final String screenshotresultPath=new File("/var/www/results"+"/"+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("/results"+"/"+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
Thread.sleep(10000);
55
 
56
 
57
		selenium.setTimeout("189000");
58
		selenium.open("/");
59
 
60
		selenium.setContext("Recharge");
61
		//String s=selenium.getCookieByName("JSESSIONID");
62
		//System.out.println(s);
63
 
64
		//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);
65
		assertEquals("Mobile Phone Reviews and Best Deals in India | saholic.com", selenium.getTitle());
66
 
67
		assertTrue("Logo not present",selenium.isElementPresent("css=img[alt=\"Saholic\"]"));
68
		assertTrue("Search all not found",selenium.isTextPresent("Search"));
69
		assertTrue("Element searchButton not found ",selenium.isElementPresent("id=searchButton"));
70
		assertEquals("BEST DEALS", selenium.getText("css=div.home-listing-common-header-text > span.left"));
71
		assertTrue("//div[@id='products']/div[2]/div/div/span not found",selenium.isElementPresent("//div[@id='products']/div[2]/div/div/span"));
72
		//assertTrue("css=div.cart-top not found",selenium.isElementPresent("css=div.cart-top"));
73
		assertTrue("css=span.common-widget-top-bar-text-right not found",selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
74
		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"));
75
		System.out.println(selenium.getText("//div[@id='products']/div[3]/div/div/span"));
76
		assertTrue("BEST SELLERS not found",selenium.isTextPresent("BEST SELLERS") );
77
		assertTrue("LATEST ARRIVALS not found",selenium.isTextPresent("LATEST ARRIVALS") );
78
		assertTrue("css=div.home-listing-common-content.best-sellers not found",selenium.isElementPresent("css=div.home-listing-common-content.best-sellers"));
79
		assertTrue("css=div.home-listing-common-content.latest-arrivals not found",selenium.isElementPresent("css=div.home-listing-common-content.latest-arrivals"));
80
		assertTrue("css=div.home-listing-common-content.best-deals not found",selenium.isElementPresent("css=div.home-listing-common-content.best-deals"));
81
		Thread.sleep(10000);
82
		selenium.click("link=RECHARGE");
83
		selenium.waitForPageToLoad("60000");
84
		Thread.sleep(30000);
85
		//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);
86
		assertEquals("Mobile and DTH online recharge | saholic.com", selenium.getTitle());
87
		selenium.click("id=dth-image");
88
		Thread.sleep(10000);
89
		assertTrue("Recharge your not found",selenium.isTextPresent("Recharge Your :"));
90
		assertTrue("Operator not found",selenium.isTextPresent("Operator :"));
91
		assertTrue("Account Number not found",selenium.isTextPresent("Account Number :"));
92
		assertTrue("Amount not found",selenium.isTextPresent("Amount :"));
93
		assertTrue("Email Id not found",selenium.isTextPresent("Email Id :"));
94
		selenium.click("id=phone-image");
95
		Thread.sleep(10000);
96
		assertTrue("Recharge your not found",selenium.isTextPresent("Recharge Your :"));
97
		assertTrue("Mobile number not found",selenium.isTextPresent("Mobile Number :"));
98
		assertTrue("Operator not found",selenium.isTextPresent("Operator :"));
99
		assertTrue("Amount not found",selenium.isTextPresent("Amount :"));
100
		assertTrue("Email Id not found",selenium.isTextPresent("Email Id :"));
101
		selenium.type("name=number", "9816294760");
102
		selenium.select("id=operatorSelector", "AIRTEL");
103
		selenium.type("name=amount", "100");
104
		selenium.type("name=email", "kshitijsood@ymail.com");
105
		selenium.click("css=input.submit-button");
106
		Thread.sleep(30000);
107
		assertTrue("css=h1 not found",selenium.isElementPresent("css=h1"));
108
		assertTrue("Mobile number not found",selenium.isTextPresent("Mobile Number :"));
109
		assertTrue("Mobile number 9816294760 not found",selenium.isTextPresent("9816294760"));
110
	    assertTrue("Mobile number not found",selenium.isTextPresent("Recharge amount :"));
111
	    assertTrue("Mobile number not found",selenium.isTextPresent("Amount to pay :"));
112
	    selenium.click("css=input.submit-button");
113
	    Thread.sleep(30000);
114
		System.out.println("<----PROCEED TO PAY PAGE TABLETS THREAD---->");
115
		assertEquals("Amount to be Paid:", selenium.getText("css=h4 > span"));
116
		String htmlstr = selenium.getBodyText();
117
    	int pos = htmlstr.indexOf("Amount to be Paid:");
118
    	//System.out.println("Index is " + pos);
119
    	int pos1=pos+21;
120
    	int pos2=pos+30;
121
    	String amount;
122
    	amount = htmlstr.substring(pos1, pos2);
123
    	//System.out.println("pos1 pos2" + pos1 + ":" + pos2);
124
    	//int price=Integer.parseInt(amount);
125
    	//System.out.println("Amount : :" + amount + ":" + price );
126
    	amount=amount.replaceAll(",", "");
127
    	System.out.println("Amount : :" + amount);
128
    	///double price = Integer.parseInt(amount);
129
    	assertTrue("CREDIT CARDS not found",selenium.isTextPresent("CREDIT CARDS"));
130
		assertTrue("DEBIT/ATM CARDS not found",selenium.isTextPresent("DEBIT/ATM CARDS"));
131
		assertTrue("NET BANKING not found",selenium.isTextPresent("NET BANKING"));
132
		assertTrue("css=input.make-payment-button not found",selenium.isElementPresent("css=input.make-payment-button"));
133
		selenium.deleteAllVisibleCookies();
134
	}
135
	@After
136
	public void tearDown() throws Exception {
137
		selenium.stop();
138
        //stopSeleniumServer();
139
		try {
140
	        if (null != loggingWriter) {
141
	            loggingWriter.close();
142
	        }
143
	    } catch (IOException e) {
144
	      System.out.println("IO exception");
145
	    }
146
	}
147
}