package Tests.TestCases.WetWasteCollection; import Tests.APIs.Compost_Pit.WetWaste_API; import Tests.TestCases.Login.Login_City; import Tests.Utilities.ReadExcelData; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.testng.Assert; import org.testng.annotations.Test; import java.text.DecimalFormat; import java.time.Duration; public class Wet_Waste extends Login_City { @Test(dataProviderClass = ReadExcelData.class, dataProvider = "WetWasteData",priority = 1) public void Wet_Waste_Collection(String VehicleNumber, String Weight,String Description) throws InterruptedException { double Weight_double = Double.parseDouble(Weight); DecimalFormat df = new DecimalFormat("#"); String Weight1 = df.format(Weight_double); driver.findElement(By.xpath(locators.getProperty("Wet_waste_Collection"))).click(); Thread.sleep(2000); //Create New Report driver.findElement(By.xpath(locators.getProperty("Create_New_Report"))).click(); driver.runAppInBackground(Duration.ofSeconds(5)); Thread.sleep(2000); driver.findElement(By.xpath(locators.getProperty("Next"))).click(); Thread.sleep(2000); WebElement compostID= driver.findElement(By.xpath(locators.getProperty("CompostID"))); String text= compostID.getText(); if(text.equals("compost Id")) { compostID.sendKeys("QA_automation"); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); }else { System.out.println("CompostID:"+" "+text); } driver.findElement(By.xpath(locators.getProperty("Vehicle_Number"))).sendKeys(VehicleNumber); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); driver.findElement(By.xpath(locators.getProperty("Weight_Kg"))).sendKeys(Weight1); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); driver.findElement(By.xpath(locators.getProperty("Description"))).sendKeys(Description); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); driver.findElement(By.xpath(locators.getProperty("photos"))).click(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); driver.findElement(By.xpath(locators.getProperty("Select_ImageFrom"))).click(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); driver.findElement(By.xpath(locators.getProperty("shutter"))).click(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); driver.findElement(By.xpath(locators.getProperty("Done"))).click(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); driver.findElement(By.xpath(locators.getProperty("Check"))).click(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); WebElement submit= driver.findElement(By.xpath(locators.getProperty("submit"))); submit.click(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(90)); /*WetWaste_API Object = new WetWaste_API(); Object.wetWasteAPI(VehicleNumber, Weight, Description);*/ WetWaste_API myInstance = new WetWaste_API(); String ResponseBody = myInstance.wetWasteAPI(VehicleNumber, Weight, Description); System.out.println("ResponseBody:"+ResponseBody); if (ResponseBody.equals("Your Report Created Successfully")) { System.out.println("Response is " + ResponseBody); } driver.findElement(By.xpath(locators.getProperty("Error"))).click(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); Assert.assertEquals(ResponseBody,"Your Report Created Successfully"); } package Tests.TestCases.Login; import Tests.APIs.Login_API; import Tests.Base.BaseClass; import io.restassured.RestAssured; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; import io.restassured.specification.RequestSpecification; import org.json.JSONArray; import org.json.JSONObject; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.testng.annotations.Listeners; import org.testng.annotations.Test; import org.uncommons.reportng.HTMLReporter; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.time.Duration; public class Login_City extends BaseClass { String apiUrl = "http://api-officer.silicontechnolabs.com:9017/api/v1/auth/sign_in"; @Test(priority = 0) public void mcd() throws FileNotFoundException { String login_id = "qa_delhi@yopmail.com"; String password = "Qa@123456"; String expectedResponse = "200"; WebElement emailInput = driver.findElement(By.xpath(locators.getProperty("Email"))); emailInput.sendKeys(login_id); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); WebElement passwordInput = driver.findElement(By.xpath(locators.getProperty("Password"))); passwordInput.sendKeys(password); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); WebElement loginButton = driver.findElement(By.xpath(locators.getProperty("LoginButton"))); loginButton.click(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); /* Login_API Object = new Login_API(); Object.loginAPI(login_id, password, expectedResponse);*/ Login_API myInstance = new Login_API(); String Body = myInstance.loginAPI(login_id, password, expectedResponse); JSONObject jsonObject = new JSONObject(Body); JSONArray notificationArray = jsonObject.getJSONArray("NOTIFICATION"); String notification = notificationArray.getString(0); System.out.println("Notification: " + notification); JsonPath jsonPath = new JsonPath(Body); String authToken = jsonPath.getString("user.authtoken"); System.out.println("AuthToken:" + " " + authToken); // Write the Auth token to a file try (PrintWriter out = new PrintWriter("authtoken.txt")) { out.println(authToken); } } } package Tests.Base; import com.google.common.collect.ImmutableMap; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.connection.ConnectionStateBuilder; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.*; import java.io.FileReader; import java.io.IOException; import java.net.URL; import java.time.Duration; import java.util.Properties; public class BaseClass { public static AndroidDriver driver; public static Properties prop = new Properties(); public static Properties locators = new Properties(); public static FileReader fr; public static FileReader fr1; @BeforeClass public void Setup() throws IOException { if (driver == null) { fr = new FileReader(System.getProperty("user.dir") + "\\src\\test\\java\\Resources\\ConfigFiles\\config.properties"); fr1 = new FileReader(System.getProperty("user.dir") + "\\src\\test\\java\\Resources\\ConfigFiles\\locators.properties"); prop.load(fr); locators.load(fr1); DesiredCapabilities dc = new DesiredCapabilities(); dc.setCapability("DEVICE_NAME", "Redmi note 11"); // Android Emulator dc.setCapability("PLATFORM_NAME", "Android"); dc.setCapability("UDID", "cb1dfd9a"); dc.setCapability("PLATFORM_VERSION", "12 SKQ1.211103.001"); dc.setCapability("appPackage", "com.infoweb.smartcity311.demo"); dc.setCapability("appActivity", "com.infoweb.smartcity311.demo.MainActivity"); dc.setCapability("autoGrantPermissions", true); dc.setCapability("newCommandTimeout", 0); dc.setCapability("noReset", true); // (you can get it from apk info app) URL url = new URL("http://127.0.0.1:4723/wd/hub"); driver = new AndroidDriver(url, dc); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30)); String currentPackage = driver.getCurrentPackage(); driver.executeScript("mobile: shell", ImmutableMap.of("command", "pm grant " + currentPackage + " android.permission.READ_EXTERNAL_STORAGE")); driver.executeScript("mobile: shell", ImmutableMap.of("command", "pm grant " + currentPackage + " android.permission.WRITE_EXTERNAL_STORAGE")); driver.executeScript("mobile: shell", ImmutableMap.of("command", "pm grant " + currentPackage + " android.permission.CAMERA")); // Set up the network interception using Charles Proxy driver.setConnection(new ConnectionStateBuilder().withWiFiEnabled().build()); } } @AfterClass public void tearDown() { // Close the WebDriver instance driver.quit(); } } }