Произошла ошибка при создании экземпляра класса mobileautomation.FormFilling: null с использованием фермы устройств - PullRequest
0 голосов
/ 17 июня 2020

Следующие классы отлично работают на моем локальном компьютере с использованием appium, но не работают на aws ферме устройств, дайте мне знать

Ниже приведен мой класс настройки: -

package Base;

public abstract class AndroidCapabilities {

    public static ExtentHtmlReporter reporter;
    public static ExtentReports extent;
    public static ExtentTest logger1;


    public static AndroidDriver<MobileElement> driver;
      public abstract String getName();

    @BeforeTest
    public abstract void setUpPage();

    @BeforeSuite
    public void setUpAppium() throws MalformedURLException {

        final String URL_STRING = "http://127.0.0.1:4723/wd/hub";

        URL url = new URL(URL_STRING);

        // Use a empty DesiredCapabilities object
        driver = new AndroidDriver<MobileElement>(url, new DesiredCapabilities());

        // Use a higher value if your mobile elements take time to show up
        driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);
    }

    protected static Properties properties;
    static {
        properties = new Properties();
        FileInputStream fis;
        InputStream input;
        try {
            // fis = new FileInputStream(System.getProperty("user.dir") +
            // "//src//test//resources//Properties//Android_OR.properties");
            fis = (FileInputStream) Thread.currentThread().getContextClassLoader()
                    .getResourceAsStream("Android_OR.properties");
            System.out.println(properties.getProperty("url"));
            properties.load(fis);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getObject(String Data) throws IOException {
        String data = properties.getProperty(Data);
        return data;

    }

    public static void type(String Locator, String key) {
        if (Locator.endsWith("_Xpath")) {
            driver.findElement(By.xpath(properties.getProperty(Locator))).sendKeys(properties.getProperty(key));

        } else if (Locator.endsWith("_ID")) {
            driver.findElement(By.id(properties.getProperty(Locator))).sendKeys(properties.getProperty(key));
        } else if (Locator.endsWith("_ID1")) {
            driver.findElement(By.id(properties.getProperty(Locator))).sendKeys(properties.getProperty(key));
        } else if (Locator.endsWith("_Xpath1")) {
            driver.findElement(By.xpath(properties.getProperty(Locator))).sendKeys(properties.getProperty(key));
        }
    }

    public static void click(String Locator) {
        if (Locator.endsWith("_Xpath")) {
            driver.findElement(By.xpath(properties.getProperty(Locator))).click();

        } else if (Locator.endsWith("_ID")) {
            driver.findElement(By.id(properties.getProperty(Locator))).click();
            // driver.findElementByAccessibilityId(properties.getProperty(Locator)).click();
        } else if (Locator.endsWith("_ID1")) {
            driver.findElement(By.id(properties.getProperty(Locator))).click();
        } else if (Locator.endsWith("_Xpath1")) {
            driver.findElement(By.xpath(properties.getProperty(Locator))).click();
        }

    }

    public static String getPropertyValue(String key) {

        return properties.getProperty(key);

    }

    public static WebElement findElement(String Locator) {
        WebElement WebElement = null;
        if (Locator.endsWith("_Xpath")) {
            WebElement = driver.findElement(By.xpath(properties.getProperty(Locator)));

        } else if (Locator.endsWith("_ID")) {
            WebElement = driver.findElement(By.id(properties.getProperty(Locator)));
            // driver.findElementByAccessibilityId(properties.getProperty(Locator)).click();

        }

        return WebElement;
    }

    public static void back() {
        driver.navigate().back();
    }

    public static void to(String String) {
        driver.navigate().to(String);
    }

    public void clear(String Locator) {
        if (Locator.endsWith("_Xpath")) {
            driver.findElement(By.xpath(properties.getProperty(Locator))).clear();

        } else if (Locator.endsWith("_ID")) {
            driver.findElement(By.id(properties.getProperty(Locator))).clear();
            // driver.findElementByAccessibilityId(properties.getProperty(Locator)).click();
        } else if (Locator.endsWith("_ID1")) {
            driver.findElement(By.id(properties.getProperty(Locator))).clear();
        } else if (Locator.endsWith("_Xpath1")) {
            driver.findElement(By.xpath(properties.getProperty(Locator))).clear();
        }
    }

    public static void point(int xPoint, int yPoint) {
        TouchAction touchAction = new TouchAction(driver);
        touchAction.tap(PointOption.point(xPoint, yPoint)).perform();
    }

    public static void tapObject(String Locator) {
        MobileElement element = driver.findElement(By.xpath((properties.getProperty(Locator))));

        JavascriptExecutor js = (JavascriptExecutor) driver;
        HashMap<String, Integer> tapObject1 = new HashMap<String, Integer>();

        tapObject1.put("x", element.getCenter().getX());
        tapObject1.put("y", element.getCenter().getY());
        js.executeScript("mobile: tap", tapObject1);
    }

    public static void swipeup(int xPoint, int yPoint) {
        JavascriptExecutor jse = (JavascriptExecutor) driver;
        jse.executeScript("window.scrollBy(xPoint,yPoint)", "up");

    }

    /*
     * JavascriptExecutor jse = (JavascriptExecutor) driver;
     * jse.executeScript("window.scrollBy(0,500)", "up");
     */
    // jse.executeScript("scroll(0, -1110);","down");

//scroll to bottom of page
//JavascriptExecutor js = ((JavascriptExecutor) driver);
//js.executeScript("window.scrollTo(0, document.body.scrollHeight)");

    public static void captureScreenShots(String file_name) throws IOException {
        String folder_name;
        DateFormat df;
        folder_name = "Screenshot";
        File f = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        // Date format fot screenshot file name
        // df = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
        // create dir with given folder name
        new File(folder_name).mkdir();
        // Setting file name
        // String file1_name=df.format(new Date())+".png";
        // coppy screenshot file into screenshot folder.
        FileUtils.copyFile(f, new File(folder_name + "/" + file_name));
    }

    @BeforeTest
    public void createReport() {
        reporter = new ExtentHtmlReporter("./extent.html");
        extent = new ExtentReports();
        extent.attachReporter(reporter);

    }

    @AfterTest
    public void flush() throws IOException {
        extent.flush();
        // reporter.setAppendExisting(true);
    }

    @AfterSuite
    public void closeApplication() {
        driver.quit();
        Reporter.log("===Session End===", true);
    }

}

//Following is my testng class code:-

package mobileautomation;

public abstract class FormFilling extends AndroidCapabilities {

    // WebDriverWait wait = new WebDriverWait(driver, 10);
    // WebElement element =
    // wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ID")));

    @BeforeClass
    public static void init() {

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.navigate().to(properties.getProperty("url"));
    }

    @Test()
    public static void formFilling() throws Exception {
        logger1 = extent.createTest("formFilling");
        try {

            JavascriptExecutor jse = (JavascriptExecutor) driver;
            jse.executeScript("window.scrollBy(0,1500)", "up");

            Thread.sleep(2000);
            logger1.info("First name 'Form' is typed in textbox");
            type("fFirstName_Xpath", "fFirstName");

            Thread.sleep(2000);
            logger1.info("Last name 'Testing' is typed in textbox");
            type("fLastName_Xpath", "fLastName");

            Thread.sleep(2000);
            JavascriptExecutor jse1 = (JavascriptExecutor) driver;
            jse1.executeScript("window.scrollBy(0,100)", "up");

            //Thread.sleep(3000);
            //logger1.info("Country code '+91' for country 'UK' is selected");
            //WebElement s = findElement("fCountryCode_Xpath");
            //Select jobType = new Select(s);
            //jobType.selectByVisibleText(AndroidCapabilities.getPropertyValue("fCountryCode"));

            // ----------------------------------------------------------------------------------------------

            Thread.sleep(2000);
            logger1.info("Area code+phone is '9899928177' given in textbox");
            type("fPhoneNumber_Xpath", "fPhoneNumber");


            Thread.sleep(2000);
            logger1.info("Business Email Address 'poonam.gupta@algoworks.com' typed in textbox ");
            type("fBusinessEmailAddress_Xpath", "fBusinessEmailAddress");


/*          Thread.sleep(5000);
            logger1.info("Popup is closed");
            click("fPopupClose_Xpath");*/

            // ---------------------------------------------------------------------------------------------------

            Thread.sleep(2000);
            logger1.info("Company 'Algoworks' given in textbox");
            type("fCompany_Xpath", "fCompany");

            Thread.sleep(2000);
            logger1.info("Job Title 'Automation QA' given in textbox");
            type("fJobTitle_Xpath", "fJobTitle");

            // --------------------------------------------------------------------------------------------------------------------------------------------------
            Thread.sleep(2000);
            JavascriptExecutor jse2 = (JavascriptExecutor) driver;
            jse2.executeScript("window.scrollBy(0,100)", "up");

            logger1.info("Country name 'United Kingdom' given in textbox");
            WebElement s1 = findElement("fCountry2_Xpath");
            Select jobType1 = new Select(s1);
            Thread.sleep(2000);
            jobType1.selectByValue(AndroidCapabilities.getPropertyValue("fCountry2"));

            // ----------------------------------------------------------------------------------------------------------------

            Thread.sleep(2000);
            logger1.info("City name 'Noida' given in textbox");
            type("fCity_Xpath", "fCity");

            Thread.sleep(2000);
            logger1.info("'Reason for inquiry' is given in textbox'");
            WebElement s3 = findElement("fJobInquiry_Xpath");
            Select jobType3 = new Select(s3);
            Thread.sleep(2000);
            jobType3.selectByVisibleText(AndroidCapabilities.getPropertyValue("fJobInquiry"));

            jse2.executeScript("window.scrollBy(0,100)", "up");

            Thread.sleep(2000);
            logger1.info("Message is displayed in textbox");
            type("fMessage_Xpath", "fMessage");

            jse2.executeScript("window.scrollBy(0,300)", "up");
            Thread.sleep(2000);

/*          logger1.info(
                    "'contact us' is clicked having id '//*[@id='global-content']/div[3]/div[1]/section/div/form/div[13]/button'");
            click("fContactUs_Xpath");
            Thread.sleep(2000);*/
            /*click("fContactUs_Xpath");
            Thread.sleep(5000);*/

             logger1.info("Contact Us button is selected");
             WebElement button =driver.findElement(By.xpath("//form[@name='enquiryform']//button"));
                JavascriptExecutor jsexec = (JavascriptExecutor)driver;
                jsexec.executeScript("arguments[0].click();", button);          

            jse2.executeScript("window.scrollBy(0, -800)", "down");


        } catch (Exception e) {
            logger1.fail(e);
            captureScreenShots("ErrorScreenshot.png");
            throw e;
        }
        Thread.sleep(8000);

        logger1.pass("Testcase FormFilling is Passed");
    }

    public static void setAttribute(WebElement element, String attName, String attValue) {
        driver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attName, attValue);

    }
}
...