@SuppressWarnings("deprecation") public void verify_facualcal_onfresh_launch() throws InterruptedException, IOException { // Handling error / failures FactSteps = 1; // Report part invoking ExtentReports reporter = Driver.getInstance(); logger = reporter.startTest("Verify Factual Call test case").assignCategory("Smoke_Test"); logger.log(LogStatus.PASS, "Started Factual Call Testcase"); System.out.println("Case Started"); // reading filr from Propery file Driver.property(); PropertyFile.property(); // Report logs for Launching the app ATUReports.add("Launch the app", false); logger.log(LogStatus.PASS, "Launch the app"); // run command for getting logs in idevicesyslog.log String[] str = { "/bin/bash", "-c", "/usr/local/bin/idevicesyslog.log >>" + properties.getProperty("LogFilePath") }; Process p = Runtime.getRuntime().exec(str); FactSteps = FactSteps + 1; BufferedReader r = new BufferedReader(new FileReader(properties.getProperty("LogFilePath"))); String line = ""; String allLine = ""; while ((line = r.readLine()) != null) { System.out.println("Sys data is ::" + line); } String FilePath = properties.getProperty("LogFilePath"); // Users/aparna/Desktop/syslog1.log"; Map<String, String> mapkeys = new HashMap<String, String>(); try { FileInputStream fstream = new FileInputStream(FilePath); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine; // / read log line by line ------ strLine = br.readLines(6, 10); / StringBuffer sb = new StringBuffer(""); while ((strLine = br.readLine()) != null) { sb.append(strLine); } ATUReports.add("Verify the Factual values(FAUD,FGEO) in Feed_1 Call", false); logger.log(LogStatus.PASS, "Verify the Factual values(FAUD,FGEO) in Feed_1 Call"); // Handle wrong data failure for log file // if(!sb.toString().contains("7646/app_iphone_us/display")) // { // FactSteps=4+1; // System.out.println("Log data is not correct"); // Assert.fail(); // } // Get sg values form pub ad call if (sb.toString().contains("Requesting ad: /7646/app_iphone_us/display/feed/feed_1")) { String req = sb.toString() .substring( sb.toString() .lastIndexOf( "Requesting ad: /7646/app_iphone_us/display/feed/feed_1 with parameters: {")); req = req.substring(req.indexOf("{") + 1, req.indexOf("}")); String[] arrays = req.split(";"); System.out.println("Verifing the " + req); for (String keys : arrays) { System.out.println("keys is::" + keys); if (keys.contains("=")) { String[] key = keys.split("="); // System.out.println(key[0] + "---"+key[1]); mapkeys.put(key[0], key[1]); } } for (Entry<String, String> entryKeys : mapkeys.entrySet()) { // System.out.println("key : "+entryKeys.getKey() + "----"+"value:"+entryKeys.getValue()); if (entryKeys.getKey().contains("fgeo")) { String fgeo = entryKeys.getValue(); System.out.println("fgeo values are :" + entryKeys.getValue()); ATUReports.add("sg values are presented", false); logger.log(LogStatus.PASS, "sg values are present"); // container.add(entryKeys.getValue()); // sg.add(entryKeys.getValue()); int size = fgeo.length(); System.out.println("Size is : " + size); fgeo = fgeo.substring(2, fgeo.lastIndexOf('"')); fgeo = fgeo.replaceAll(",", ", "); // System.out.println("sg1::"+sg1); fgeoval.add(fgeo); System.out.println("fgeo values and split data is ::" + fgeoval); } } // Get id values for lotame call Map<String, String> Factualkeys = new HashMap<String, String>(); String factualString; if (sb.toString().contains("https://location.wfxtriggers.com")) { String factualreq = sb.toString().substring(sb.toString().lastIndexOf("WFX triggers Response {")); String factualreq1 = factualreq.substring(factualreq.indexOf("(") + 1, factualreq.indexOf(");") - 1); // String[] arrays = Lotamereq.split(";"); System.out.println("FactualReq1 ::" + factualreq1); // System.out.println("json is :;"+Lotamereq1); String[] factualarrays = factualreq1.split("},"); // System.out.println("Lotamearray is::"+ Lotamearrays.toString()); // Gson gson = new Gson(); String[] factualVal = null; for (String factualKeys : factualarrays) { // System.out.println("Lotkeys ::"+LotKeys.toString()); factualVal = factualKeys.split(";"); for (String FactualValues : factualVal) { if (FactualValues.contains("index")) { String Factualval = FactualValues.toString().replace("{", "").trim(); System.out.println("Factual values are ::" + Factualval); if (Factualval.contains("")) { Assert.assertNotNull(Factualval); } else { container.add( Factualval.toString().replaceAll("index =", "").trim().replaceAll(", ", ",")); } } } } // System.out.println("sg values are :" + sg.toString()); String Actual = fgeoval.toString().replace("[", "").replace("]", ""); System.out.println("fgeoval ::" + Actual.toString()); // System.out.println("Container vales are :"+container.toString()); String Expected = container.toString().replace("[", "").replace("]", ""); System.out.println("Container vales are ::" + Expected.toString()); // Assert.assertEquals(Actual, Expected); String[] Factualarrays = Actual.split(","); System.out.println("Verifing the " + Factualarrays); for (String Factualkey : Factualarrays) { System.out.println(Factualkey); if (Expected.toString().contains(Factualkey.toString())) { System.out.println("Values are matched"); ATUReports.add("FGEO value is present", false); logger.log(LogStatus.PASS, "FGEO Values are matched"); } else { FactSteps = FactSteps + 1; System.out.println("Values are not matched"); Assert.fail(); } } } } br.close(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Verification of FactualCall test case done"); reporter.endTest(logger); reporter.flush(); }
@SuppressWarnings({"unused", "unchecked", "rawtypes", "resource", "deprecation"}) public void SmokeTest_WFX() throws Exception { // app kill and relaunch the app app_Kill_Relaunch.Kill_realaunch(); System.out.println("Verification of WeatherFX Call Test_Case Started"); String adbPath = properties.getProperty("adbPath"); String[] str = {"/bin/bash", "-c", adbPath + " shell setprop log.tag.TwcAd DEBUG"}; Process p = Runtime.getRuntime().exec(str); System.out.println("Debug command is done"); String[] str1 = { "/bin/bash", "-c", adbPath + " -d logcat -v time >> " + properties.getProperty("LogFilePath") }; Process p1 = Runtime.getRuntime().exec(str1); System.out.println("Writing App logs to LogFile"); ATUReports.add("Launch the app", false); try { // Wait for 20 sec for element presence WebDriverWait wait = new WebDriverWait(Ad, 10); wait.until( ExpectedConditions.presenceOfElementLocated(By.id("com.weather.Weather:id/temperature"))); // Temperature Element MobileElement el = (MobileElement) Ad.findElementById("com.weather.Weather:id/temperature"); System.out.println("Temp : " + el.getText()); ATUReports.add("Scroll to Feed-1 Ad", false); Swipe.swipe(); Swipe.swipe(); // Ad.swipe(0,1800,0,20,2000); // Ad.swipe(0,1800,0,20,2000); } catch (Exception e) { // System.out.println("Exception message :: "+e); } MobileElement AdEle = (MobileElement) Ad.findElementById("com.weather.Weather:id/ad_view_holder"); WebDriverWait wait1 = new WebDriverWait(Ad, 4); wait1.until(ExpectedConditions.visibilityOf(AdEle)); if (AdEle.isDisplayed()) { System.out.println("Feed-1 Ad is displayed"); ATUReports.add("Feed-1 Ad is present", false); } Thread.sleep(6000); // Reading the log file for feed_1,to verify WFXTG value BufferedReader r = new BufferedReader(new FileReader(properties.getProperty("LogFilePath"))); String line = ""; String allLine = ""; while ((line = r.readLine()) != null) { System.out.println("Sys data is ::" + line); } String FilePath = properties.getProperty("LogFilePath"); try { FileInputStream fstream = new FileInputStream(FilePath); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine; // / read log line by line ------ strLine = br.readLines(6, 10); / StringBuffer sb = new StringBuffer(""); while ((strLine = br.readLine()) != null) { sb.append(strLine); } Thread.sleep(2000); String req = null; String[] arrays; String[] key; String zipcode = null; List<String> pubad_zip = new ArrayList<String>(); ATUReports.add("Verify the PubAd_WFXTG values in Feed_1 Call", false); if (sb.toString().contains("slotName=weather.feed1")) { req = sb.toString().substring(sb.toString().lastIndexOf("slotName=weather.feed1")); req = req.substring(req.indexOf(",") + 1, req.indexOf("}")); System.out.println("Verifing the " + req); arrays = req.split(" "); for (String keys : arrays) { if (keys.contains("=")) { key = keys.split("="); // System.out.println("keys are :: "+key[0] + "---"+key[1]); if (key[0].contains("zip")) { key[1] = key[1].toString(); key[1] = key[1].substring(0, key[1].lastIndexOf(",")); pubad_zip.add(key[1]); break; } } } zipcode = pubad_zip.toString().replace("[", "").replace("]", ""); System.out.println("Zip value is :: " + zipcode); } List<String> pubad_ZCSvalues = wfxtg.getValues(req, "zcs"); List<String> pubad_HZCSvalues = wfxtg.getValues(req, "hzcs"); List<String> pubad_NZCSvalues = wfxtg.getValues(req, "nzcs"); Thread.sleep(1000); System.out.println("================================"); try { // Capturing the WFXTG Call Data String wfxValues = null; int test = 0; for (int i = 1; i <= 6; i++) { int index = sb.toString() .indexOf( "response from server is {" + "\"wfxtg\"" + ":{" + "\"current\"" + ":[", test); int emptyindex = sb.toString() .indexOf( "response from server is {" + "\"wfxtg\"" + ":{" + "\"current\"" + ":[]", test); if (index == -1) { break; } else if (index != emptyindex) { wfxValues = sb.toString().substring(index); wfxValues = wfxValues.substring( wfxValues.indexOf("scatterSegs" + '"' + ":") + 13, wfxValues.indexOf("]}}") + 1); // WFXTG call of https://triggers.wfxtriggers.com System.out.println("Verifing the WFXTG call" + wfxValues); } test = index + 2; } // if (sb.toString().contains("response from server is {" + '"' + "wfxtg")) { // String wfxValues = null; // if (sb.toString().contains("response from server is {" + "\"wfxtg\"")) { // wfxValues = sb.toString().substring(sb.toString().lastIndexOf("response from // server is {" + '"'+ "wfxtg")); // wfxValues = wfxValues.substring( // wfxValues.indexOf("scatterSegs" + '"' + ":") + 13, // wfxValues.indexOf("]}}") + 1); // System.out.println("Verifing the WFX call " + wfxValues); // } System.out.println("================================"); Thread.sleep(1000); List<String> segmentList = new ArrayList<String>(); String seg = null; String zip = zipcode; JSONParser parser = new JSONParser(); Object obj = parser.parse(wfxValues.toString()); JSONArray jsonObject = (JSONArray) obj; Map<String, List<String>> zcsmap = new HashMap<String, List<String>>(); Map<String, List<String>> hzcsmap = new HashMap<String, List<String>>(); Map<String, List<String>> nzcsmap = new HashMap<String, List<String>>(); for (int index = 0; index < jsonObject.size(); index++) { JSONObject obj1 = (JSONObject) jsonObject.get(index); if (obj1.containsKey("zcs")) { JSONArray array2 = (JSONArray) obj1.get("zcs"); for (int index2 = 0; index2 < array2.size(); index2++) { JSONObject obj2 = (JSONObject) array2.get(index2); JSONArray array3 = (JSONArray) obj2.get("segments"); List<String> list = new ArrayList<String>(); for (int index3 = 0; index3 < array3.size(); index3++) { list.add(((Long) array3.get(index3)).toString()); } zcsmap.put((String) obj2.get("zip"), list); } } else if (obj1.containsKey("hzcs")) { JSONArray array2 = (JSONArray) obj1.get("hzcs"); for (int index2 = 0; index2 < array2.size(); index2++) { JSONObject obj2 = (JSONObject) array2.get(index2); JSONArray array3 = (JSONArray) obj2.get("segments"); List<String> list = new ArrayList<String>(); for (int index3 = 0; index3 < array3.size(); index3++) { list.add(((Long) array3.get(index3)).toString()); } hzcsmap.put((String) obj2.get("zip"), list); } } else if (obj1.containsKey("nzcs")) { JSONArray array2 = (JSONArray) obj1.get("nzcs"); for (int index2 = 0; index2 < array2.size(); index2++) { JSONObject obj2 = (JSONObject) array2.get(index2); JSONArray array3 = (JSONArray) obj2.get("segments"); List<String> list = new ArrayList<String>(); for (int index3 = 0; index3 < array3.size(); index3++) { list.add(((Long) array3.get(index3)).toString()); } nzcsmap.put((String) obj2.get("zip"), list); } } } // Asserting the PubAd_ZCS_Values and WFX_APICall_ZCS_Values List<String> zcssegments = zcsmap.get(zip); List wfx_zcs = new ArrayList(); for (String i : zcssegments) { wfx_zcs.add(Integer.parseInt(i)); } Collections.sort(wfx_zcs); String wfx_zcs_values = wfx_zcs.toString().replace(" ", ""); String pubAd_zcs_values = pubad_ZCSvalues.toString(); System.out.println("PubAd_ZCS_values " + pubAd_zcs_values); System.out.println("WFX_APICall_ZCS_values " + wfx_zcs_values); // // ATUReports.add("PubAd_ZCS_values :: "+pubAd_zcs_values,false); // // ATUReports.add("WFX_APICall_ZCS_values :: "+wfx_zcs_values,false); ATUReports.add("ZCS_values are present in Feed-1_PubAd call", false); ATUReports.add("ZCS_values are present in WFX_APICall", false); if (wfx_zcs_values.equalsIgnoreCase(pubAd_zcs_values)) { System.out.println("PubAd_ZCS_values and WFX_APICall_ZCS_values are equal"); ATUReports.add("PubAd_ZCS_values and WFX_APICall_ZCS_values are equal", false); } else { System.out.println("PubAd_ZCS_values and WFX_APICall_ZCS_values are NOT equal"); ATUReports.add("PubAd_ZCS_values and WFX_APICall_ZCS_values are NOT equal", false); } System.out.println("================================"); // Asserting the PubAd_NZCS_Values and WFX_APICall_NZCS_Values List<String> nzcssegments = nzcsmap.get(zip); List wfx_nzcs = new ArrayList(); for (String j : nzcssegments) { wfx_nzcs.add(Integer.parseInt(j)); } Collections.sort(wfx_nzcs); String wfx_nzcs_values = wfx_nzcs.toString().replace(" ", ""); String pubAd_nzcs_values = pubad_NZCSvalues.toString(); System.out.println("PubAd_NZCS_values " + pubAd_nzcs_values); System.out.println("WFX_APICall_NZCS_values " + wfx_nzcs_values); // // ATUReports.add("PubAd_NZCS_values :: "+pubAd_nzcs_values,false); // // ATUReports.add("WFX_APICall_NZCS_values :: "+wfx_nzcs_values,false); ATUReports.add("NZCS_values are present in Feed-1_PubAd call", false); ATUReports.add("NZCS_values are present in WFX_APICall", false); if (wfx_nzcs_values.equalsIgnoreCase(pubAd_nzcs_values)) { System.out.println("PubAd_NZCS_values and WFX_APICall_NZCS_values are equal"); ATUReports.add("PubAd_NZCS_values and WFX_APICall_NZCS_values are equal", false); } else { System.out.println("PubAd_NZCS_values and WFX_APICall_NZCS_values are NOT equal"); ATUReports.add("PubAd_NZCS_values and WFX_APICall_NZCS_values are NOT equal", false); } System.out.println("================================"); // Asserting the PubAd_HZCS_Values and WFX_APICall_HZCS_Values List<String> hzcssegments = hzcsmap.get(zip); List wfx_hzcs = new ArrayList(); for (String j : hzcssegments) { wfx_hzcs.add(Integer.parseInt(j)); } Collections.sort(wfx_hzcs); String wfx_hzcs_values = wfx_hzcs.toString().replace(" ", ""); String pubAd_hzcs_values = pubad_HZCSvalues.toString(); System.out.println("PubAd_HZCS_values " + pubAd_hzcs_values); System.out.println("WFX_APICall_HZCS_values " + wfx_hzcs_values); // ATUReports.add("PubAd_HZCS_values :: "+pubAd_hzcs_values,false); // ATUReports.add("WFX_APICall_HZCS_values :: "+wfx_hzcs_values,false); ATUReports.add("HZCS_values are present in Feed-1_PubAd call", false); ATUReports.add("HZCS_values are present in WFX_APICall", false); if (wfx_hzcs_values.equalsIgnoreCase(pubAd_hzcs_values)) { System.out.println("PubAd_HZCS_values and WFX_APICall_HZCS_values are equal"); ATUReports.add("PubAd_HZCS_values and WFX_APICall_HZCS_values are equal", false); } else { System.out.println("PubAd_HZCS_values and WFX_APICall_HZCS_values are NOT equal"); ATUReports.add("PubAd_HZCS_values and WFX_APICall_HZCS_values are NOT equal", false); } System.out.println("================================"); // } br.close(); } catch (Exception e) { System.out.println("WFXTG values are showing as " + '"' + "nl" + '"' + "for ZCS/NZCS"); ATUReports.add("WFXTG values are showing as " + '"' + "nl" + '"' + "for ZCS/NZCS", false); } } catch (Exception e) { e.printStackTrace(); } System.out.println("Verifying WFX test case done"); }