简体   繁体   中英

How to resolve UmbrellaException error in java using phantomjs and selenium

I want to test login to a page automatically using selenium and phantomJs this is my code it's work fine with firefox but i need to use phantomJs

try {
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "D:\\phantomjs_2_1_1\\bin\\phantomjs.exe");
        caps.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX,"Y");
        caps.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0");
        caps.setJavascriptEnabled(true);
        caps.setCapability("takesScreenshot", true);

        PhantomJSDriver driver = new PhantomJSDriver(caps);

        driver.get("mypage-login");

        TimeUnit.SECONDS.sleep(3);

        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);


        FileUtils.copyFile(scrFile, new File("d:\\sample.png"),true);

        System.out.println("FIND ELEMENT [OK] ");


        new WebDriverWait(driver, 120).until(
                ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"elemId17\"]"))).click();

        scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

        System.out.println("scrFile := " + scrFile.getAbsolutePath());
        FileUtils.copyFile(scrFile, new File("d:\\sample2.png"),true);

        TimeUnit.SECONDS.sleep(2);

        driver.findElement(By.xpath("//*[@id=\"x-auto-1-input\"]")).sendKeys("username");
        driver.findElement(By.xpath("//*[@id=\"x-auto-5-input\"]")).sendKeys("domain");
        driver.findElement(By.xpath("//*[@id=\"x-auto-4-input\"]")).sendKeys("password");

        new WebDriverWait(driver, 120).until(
                ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"elemId98\"]"))).click();

        scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, new File("d:\\sample3.png"),true);

        if (driver.findElement(By.id("elemId98")) == null)
            System.out.println("OK");
        System.out.println("KO");


    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }catch (NullPointerException e) {
        e.printStackTrace();
    }
    finally {
        System.out.println("life is good !");
    }

The errors that a got is :

ERROR - 2018-04-24T16:23:41.092Z] Session [cb29bc00-47db-11e8-9aae-df14adbccf9e] - page.onError - msg: Error: com.google.gwt.event.shared.UmbrellaException: Exception caught: (TypeError) : null is not an object (evaluating 'result[1]')
phantomjs://platform/console++.js:263 in error
[ERROR - 2018-04-24T16:23:41.092Z] Session [cb29bc00-47db-11e8-9aae-df14adbccf9e] - page.onError - stack: vkb (mypage:326)
 dispatchEvent (:0)
U (:119) $ (:108)
$ (:101)
gh (:141)
sh (:152)
(anonymous function) (:152)
(anonymous function) (:152)
(anonymous function) (:153)
phantomjs://platform/console++.js:263 in error

In the screenshot i can see something that's not ok; after the last test (this code below) i add a new TakesScreenshot after a sleep for 10s the result was the same like before in the screenshot number 3 'simple3' it seem like it's blocked in this phase ( login button clicked and an animation for loading index or error page was shown)

 if (driver.findElement(By.id("elemId98")) == null)
            System.out.println("OK");
        System.out.println("KO");

any addition information i'm listening and thank you in advance :)

UmbrellaException

UmbrellaException is the Java RuntimeException defined in com.google.web.bindery.event.shared package of gwtproject that collects a set of child Throwables together. This exception is typically thrown after a loop, with all of the exceptions thrown during that loop, but delayed so that the loop finishes executing.

A detailed error stack trace would have helped us to research the issue in a better way. But as per the following discussions :

It seems the root cause of com.google.gwt.event.shared.UmbrellaException is java.lang.NullPointerException

The problems and the solution

You need to take care of a certain things in your code as follows :

  • When the element identified as (By.xpath("//*[@id=\\"elemId98\\"]")) is returned as you are trying to invoke click() instead of ExpectedConditions method presenceOfElementLocated() you must use elementToBeClickable() as follows :

     new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='elemId98']"))).click(); 

    This should be a part of practice while waiting for any element to be clickable.

  • If the elelemt identified as (By.xpath("//*[@id=\\"elemId98\\"]")) is returned after WebDriverWait and click() is invoked thereafter in the next step findElement() won't be able to find the previous element again as in :

     if (driver.findElement(By.id("elemId98")) == null) 

    Here possibly a NoSuchElementException or StaleElementReferenceException should have been raised.

  • Next as you have tried to compare the result of driver.findElement(By.id("elemId98")) with null which is not as per the best practices. As per the documentation of findElement() it is clearly mentioned that :

findElement() should not be used to look for non-present elements, use findElements(By) and assert zero length response instead.

Conclusion

All these issues/error are happening within the **try-catch {}** block which combinedly throws com.google.gwt.event.shared.UmbrellaException . Abiding by the mentioned steps will solve the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM