Blame | Last modification | View Log | RSS feed
package com;import java.io.BufferedWriter;import java.io.File;import java.io.IOException;import com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter;import com.unitedinternet.portal.selenium.utils.logging.LoggingCommandProcessor;import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium;import com.unitedinternet.portal.selenium.utils.logging.LoggingResultsFormatter;import com.unitedinternet.portal.selenium.utils.logging.LoggingSelenium;import com.unitedinternet.portal.selenium.utils.logging.LoggingUtils;//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAsimport com.thoughtworks.selenium.*;//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals;//import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue;import org.testng.annotations.AfterClass;import org.testng.annotations.BeforeClass;import org.testng.annotations.Test;//import org.openqa.selenium.server.SeleniumServer;//import java.util.regex.Pattern;public class Buyproductonshop2020_Recharge extends SeleneseTestBase {BufferedWriter loggingWriter;protected LoggingSelenium selenium;final String resultbasePath = "/opt/seleniumTests/results/shop2020";//final String resultbasePath = "/opt/seleniumTests/results";final String resultHtmlFileName = resultbasePath + "/" + "result9.html";final String resultEncoding = "UTF-8";final String screenshotpath="screenshot";final String screenshotresultPath=new File("/var/www/results"+"/"+screenshotpath).getAbsolutePath();String url = "";@BeforeClasspublic void setUp() throws Exception {if (!new File(screenshotresultPath).exists()) {new File(screenshotresultPath).mkdirs();}loggingWriter = LoggingUtils.createWriter(resultHtmlFileName, resultEncoding , true);LoggingResultsFormatter htmlFormatter =new HtmlResultFormatter(loggingWriter, resultEncoding);htmlFormatter.setScreenShotBaseUri("/results"+"/"+screenshotpath+"/"); // this is for linking to the screenshotshtmlFormatter.setAutomaticScreenshotPath(screenshotresultPath);// wrap HttpCommandProcessor from remote-controlLoggingCommandProcessor myProcessor =new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", "http://saholic:shop2020@shop2020.in:8080/"), htmlFormatter);//new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", "http://saholic.com/"), htmlFormatter);selenium = new LoggingDefaultSelenium(myProcessor);myProcessor.setExcludedCommands(new String[] {});selenium.start();//selenium.open(url);selenium.windowMaximize();}@Test(description="Recharge")public void testBuyproductonprod() throws Exception {Thread.sleep(10000);selenium.setTimeout("60000");selenium.open("/");selenium.setContext("Recharge");//String s=selenium.getCookieByName("JSESSIONID");//System.out.println(s);//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);assertEquals("Mobile Phone Reviews and Best Deals in India | shop2020.in", selenium.getTitle());assertTrue("Logo not present",selenium.isElementPresent("css=img[alt=\"Shop2020\"]"));assertTrue("Search all not found",selenium.isTextPresent("Search"));assertTrue("Element searchButton not found ",selenium.isElementPresent("id=searchButton"));assertEquals("BEST DEALS", selenium.getText("css=div.home-listing-common-header-text > span.left"));assertTrue("//div[@id='products']/div[2]/div/div/span not found",selenium.isElementPresent("//div[@id='products']/div[2]/div/div/span"));assertTrue("css=span.common-widget-top-bar-text-right not found",selenium.isElementPresent("css=span.common-widget-top-bar-text-right"));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"));System.out.println(selenium.getText("//div[@id='products']/div[3]/div/div/span"));assertTrue("BEST SELLERS not found",selenium.isTextPresent("BEST SELLERS") );assertTrue("LATEST ARRIVALS not found",selenium.isTextPresent("LATEST ARRIVALS") );assertTrue("css=div.home-listing-common-content.best-sellers not found",selenium.isElementPresent("css=div.home-listing-common-content.best-sellers"));assertTrue("css=div.home-listing-common-content.latest-arrivals not found",selenium.isElementPresent("css=div.home-listing-common-content.latest-arrivals"));assertTrue("css=div.home-listing-common-content.best-deals not found",selenium.isElementPresent("css=div.home-listing-common-content.best-deals"));Thread.sleep(10000);selenium.click("link=RECHARGE");selenium.waitForPageToLoad("60000");Thread.sleep(30000);//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);assertEquals("Mobile and DTH online recharge | shop2020.in", selenium.getTitle());selenium.click("id=dth-image");Thread.sleep(10000);assertTrue("Recharge your not found",selenium.isTextPresent("Recharge Your :"));assertTrue("Operator not found",selenium.isTextPresent("Operator :"));assertTrue("Account Number not found",selenium.isTextPresent("Account Number :"));assertTrue("Amount not found",selenium.isTextPresent("Amount :"));assertTrue("Email Id not found",selenium.isTextPresent("Email Id :"));selenium.click("id=phone-image");Thread.sleep(10000);assertTrue("Recharge your not found",selenium.isTextPresent("Recharge Your :"));assertTrue("Mobile number not found",selenium.isTextPresent("Mobile Number :"));assertTrue("Operator not found",selenium.isTextPresent("Operator :"));assertTrue("Amount not found",selenium.isTextPresent("Amount :"));assertTrue("Email Id not found",selenium.isTextPresent("Email Id :"));selenium.type("name=number", "9816294760");selenium.select("id=operatorSelector", "AIRTEL");selenium.type("name=amount", "100");selenium.type("name=email", "kshitijsood@ymail.com");selenium.click("css=input.submit-button");Thread.sleep(30000);assertTrue("css=h1 not found",selenium.isElementPresent("css=h1"));assertTrue("Mobile number not found",selenium.isTextPresent("Mobile Number :"));assertTrue("Mobile number 9816294760 not found",selenium.isTextPresent("9816294760"));assertTrue("Mobile number not found",selenium.isTextPresent("Recharge amount :"));assertTrue("Mobile number not found",selenium.isTextPresent("Amount to pay :"));selenium.click("css=input.submit-button");Thread.sleep(30000);System.out.println("<----PROCEED TO PAY PAGE TABLETS THREAD---->");assertEquals("Amount to be Paid:", selenium.getText("css=h4 > span"));String htmlstr = selenium.getBodyText();int pos = htmlstr.indexOf("Amount to be Paid:");//System.out.println("Index is " + pos);int pos1=pos+21;int pos2=pos+30;String amount;amount = htmlstr.substring(pos1, pos2);//System.out.println("pos1 pos2" + pos1 + ":" + pos2);//int price=Integer.parseInt(amount);//System.out.println("Amount : :" + amount + ":" + price );amount=amount.replaceAll(",", "");System.out.println("Amount : :" + amount);///double price = Integer.parseInt(amount);assertTrue("CREDIT CARDS not found",selenium.isTextPresent("CREDIT CARDS"));assertTrue("DEBIT/ATM CARDS not found",selenium.isTextPresent("DEBIT/ATM CARDS"));assertTrue("NET BANKING not found",selenium.isTextPresent("NET BANKING"));assertTrue("css=input.make-payment-button not found",selenium.isElementPresent("css=input.make-payment-button"));selenium.deleteAllVisibleCookies();}@AfterClasspublic void clear() {selenium.selectWindow(selenium.getTitle());selenium.captureScreenshot("recharge_shop2020.png");selenium.stop();}}