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
import com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter;
6
import com.unitedinternet.portal.selenium.utils.logging.LoggingCommandProcessor;
7
import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium;
8
import com.unitedinternet.portal.selenium.utils.logging.LoggingResultsFormatter;
9
import com.unitedinternet.portal.selenium.utils.logging.LoggingSelenium;
10
import com.unitedinternet.portal.selenium.utils.logging.LoggingUtils;
11
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAs
12
 
13
import com.thoughtworks.selenium.*;
14
 
15
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals;
16
//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue;
17
import org.testng.annotations.AfterClass;
18
import org.testng.annotations.BeforeClass;
19
import org.testng.annotations.Test;
20
//import org.openqa.selenium.server.SeleniumServer;
21
 
22
//import java.util.regex.Pattern;
23
 
24
public class Buyproductonshop2020_Recharge extends SeleneseTestBase {
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 + "/" + "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
 
34
	String url = "";
35
 
36
 
37
@BeforeClass
38
public void setUp() throws Exception {
39
	if (!new File(screenshotresultPath).exists()) {
40
		 new File(screenshotresultPath).mkdirs();
41
	}
42
    loggingWriter = LoggingUtils.createWriter(resultHtmlFileName, resultEncoding , true);
43
    LoggingResultsFormatter htmlFormatter = 
44
        new HtmlResultFormatter(loggingWriter, resultEncoding);
45
   htmlFormatter.setScreenShotBaseUri("/results"+"/"+screenshotpath+"/"); // this is for linking to the screenshots
46
   htmlFormatter.setAutomaticScreenshotPath(screenshotresultPath);
47
    // wrap HttpCommandProcessor from remote-control
48
    LoggingCommandProcessor myProcessor = 
49
    new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", "http://saholic:shop2020@shop2020.in:8080/"), htmlFormatter);
50
    //new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", "http://saholic.com/"), htmlFormatter);
51
    selenium = new LoggingDefaultSelenium(myProcessor);
52
    myProcessor.setExcludedCommands(new String[] {});
53
    selenium.start();
54
 
55
//selenium.open(url);
56
selenium.windowMaximize();
57
}
58
 
59
 
60
 
61
	@Test(description="Recharge")
62
	public void testBuyproductonprod() throws Exception {
63
		Thread.sleep(10000);
64
 
65
 
66
		selenium.setTimeout("60000");
67
		selenium.open("/");
68
 
69
		selenium.setContext("Recharge");
70
		//String s=selenium.getCookieByName("JSESSIONID");
71
		//System.out.println(s);
72
 
73
		//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);
74
		assertEquals("Mobile Phone Reviews and Best Deals in India | shop2020.in", selenium.getTitle());
75
 
76
		assertTrue("Logo not present",selenium.isElementPresent("css=img[alt=\"Shop2020\"]"));
77
		assertTrue("Search all not found",selenium.isTextPresent("Search"));
78
		assertTrue("Element searchButton not found ",selenium.isElementPresent("id=searchButton"));
79
		assertEquals("BEST DEALS", selenium.getText("css=div.home-listing-common-header-text > span.left"));
80
		assertTrue("//div[@id='products']/div[2]/div/div/span not found",selenium.isElementPresent("//div[@id='products']/div[2]/div/div/span"));
81
 
82
		assertTrue("css=span.common-widget-top-bar-text-right not found",selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));
83
		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"));
84
		System.out.println(selenium.getText("//div[@id='products']/div[3]/div/div/span"));
85
		assertTrue("BEST SELLERS not found",selenium.isTextPresent("BEST SELLERS") );
86
		assertTrue("LATEST ARRIVALS not found",selenium.isTextPresent("LATEST ARRIVALS") );
87
		assertTrue("css=div.home-listing-common-content.best-sellers not found",selenium.isElementPresent("css=div.home-listing-common-content.best-sellers"));
88
		assertTrue("css=div.home-listing-common-content.latest-arrivals not found",selenium.isElementPresent("css=div.home-listing-common-content.latest-arrivals"));
89
		assertTrue("css=div.home-listing-common-content.best-deals not found",selenium.isElementPresent("css=div.home-listing-common-content.best-deals"));
90
		Thread.sleep(10000);
91
		selenium.click("link=RECHARGE");
92
		selenium.waitForPageToLoad("60000");
93
		Thread.sleep(30000);
94
		//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);
95
		assertEquals("Mobile and DTH online recharge | shop2020.in", selenium.getTitle());
96
		selenium.click("id=dth-image");
97
		Thread.sleep(10000);
98
		assertTrue("Recharge your not found",selenium.isTextPresent("Recharge Your :"));
99
		assertTrue("Operator not found",selenium.isTextPresent("Operator :"));
100
		assertTrue("Account Number not found",selenium.isTextPresent("Account Number :"));
101
		assertTrue("Amount not found",selenium.isTextPresent("Amount :"));
102
		assertTrue("Email Id not found",selenium.isTextPresent("Email Id :"));
103
		selenium.click("id=phone-image");
104
		Thread.sleep(10000);
105
		assertTrue("Recharge your not found",selenium.isTextPresent("Recharge Your :"));
106
		assertTrue("Mobile number not found",selenium.isTextPresent("Mobile Number :"));
107
		assertTrue("Operator not found",selenium.isTextPresent("Operator :"));
108
		assertTrue("Amount not found",selenium.isTextPresent("Amount :"));
109
		assertTrue("Email Id not found",selenium.isTextPresent("Email Id :"));
110
		selenium.type("name=number", "9816294760");
111
		selenium.select("id=operatorSelector", "AIRTEL");
112
		selenium.type("name=amount", "100");
113
		selenium.type("name=email", "kshitijsood@ymail.com");
114
		selenium.click("css=input.submit-button");
115
		Thread.sleep(30000);
116
		assertTrue("css=h1 not found",selenium.isElementPresent("css=h1"));
117
		assertTrue("Mobile number not found",selenium.isTextPresent("Mobile Number :"));
118
		assertTrue("Mobile number 9816294760 not found",selenium.isTextPresent("9816294760"));
119
	    assertTrue("Mobile number not found",selenium.isTextPresent("Recharge amount :"));
120
	    assertTrue("Mobile number not found",selenium.isTextPresent("Amount to pay :"));
121
	    selenium.click("css=input.submit-button");
122
	    Thread.sleep(30000);
123
		System.out.println("<----PROCEED TO PAY PAGE TABLETS THREAD---->");
124
		assertEquals("Amount to be Paid:", selenium.getText("css=h4 > span"));
125
		String htmlstr = selenium.getBodyText();
126
    	int pos = htmlstr.indexOf("Amount to be Paid:");
127
    	//System.out.println("Index is " + pos);
128
    	int pos1=pos+21;
129
    	int pos2=pos+30;
130
    	String amount;
131
    	amount = htmlstr.substring(pos1, pos2);
132
    	//System.out.println("pos1 pos2" + pos1 + ":" + pos2);
133
    	//int price=Integer.parseInt(amount);
134
    	//System.out.println("Amount : :" + amount + ":" + price );
135
    	amount=amount.replaceAll(",", "");
136
    	System.out.println("Amount : :" + amount);
137
    	///double price = Integer.parseInt(amount);
138
    	assertTrue("CREDIT CARDS not found",selenium.isTextPresent("CREDIT CARDS"));
139
		assertTrue("DEBIT/ATM CARDS not found",selenium.isTextPresent("DEBIT/ATM CARDS"));
140
		assertTrue("NET BANKING not found",selenium.isTextPresent("NET BANKING"));
141
		assertTrue("css=input.make-payment-button not found",selenium.isElementPresent("css=input.make-payment-button"));
142
		selenium.deleteAllVisibleCookies();
143
	}
144
	@AfterClass
145
	public void clear() {	
146
		selenium.selectWindow(selenium.getTitle());
147
		selenium.captureScreenshot("recharge_shop2020.png");
148
		selenium.stop();
149
	}	
150
	}