Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParameterizedTypeImpl cannot be cast to java.lang.Class - HtmlElementDecorator issue #94

Closed
ham1 opened this issue Oct 24, 2015 · 1 comment

Comments

@ham1
Copy link
Contributor

ham1 commented Oct 24, 2015

The Table implementation is very slow (it takes about 30s in Firefox for this table https://en.wikipedia.org/wiki/List_of_highest_mountains), as such, I wanted to cache the output of getRowsAsString() as we often do multiple checks on the same data (we can be sure that no other operation will happen on the table to change it, and, if needs be, we can easily clear the cache).

My page object looks like:

    @FindBy(css = "table") // luckily there's only one
    private Table listTable;

    private List<List<String>> rows; // rows cache

    public String getRankByName(String name) {
        return getRowByName(name).get(0);
    }

    public String getHeightInFeetByName(String name) {
        return getRowByName(name).get(3);
    }

    private List<String> getRowByName(String name) {
        return getRowStream()
                .filter(row -> row.get(1).contains(name)) // find by name
                .findFirst() // find the first one if it exists
                .get(); // get the row, will throw exception if not found
    }

    private Stream<List<String>> getRowStream() {
        if (null == rows) {
            rows = listTable.getRowsAsString();
        }
        return rows.stream()
                .filter(row -> row.size() > 2);  // make sure we have columns
    }

However I get the following stack trace with the latest master of htmlelements.

sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
    at ru.yandex.qatools.htmlelements.utils.HtmlElementUtils.getGenericParameterClass(HtmlElementUtils.java:95) ~[classes/:?]
    at ru.yandex.qatools.htmlelements.utils.HtmlElementUtils.isTypifiedElementList(HtmlElementUtils.java:81) ~[classes/:?]
    at ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator.decorate(HtmlElementDecorator.java:62) ~[classes/:?]
    at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113) ~[selenium-support-2.48.2.jar:?]
    at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105) ~[selenium-support-2.48.2.jar:?]
    at ru.yandex.qatools.htmlelements.loader.HtmlElementLoader.populatePageObject(HtmlElementLoader.java:251) ~[classes/:?]
    at ru.yandex.qatools.htmlelements.loader.HtmlElementLoader.populatePageObject(HtmlElementLoader.java:241) ~[classes/:?]

Is there something that could be done to allow this? e.g. an @Ignore annotation, or only parsing paramaritised lists of WebElements?

@artkoshelev
Copy link
Contributor

Can you make a pull-request with a simple failing unit-test demonstrating your problem?

@ham1 ham1 mentioned this issue Oct 25, 2015
@lanwen lanwen closed this as completed in bf3f275 Jun 13, 2016
eroshenkoam pushed a commit that referenced this issue Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants