Unable to assert axis label text in highcharts usi

2019-09-06 18:29发布

I am writing a geb test that asserts the axis labels in a highcharts graph.

The test I wrote works when run with the selenium chrome driver. When I run with phantomjs it fails.

//Selector in GEB

$(id:"graph-id").find("g.highcharts-legend-item").find("tspan").text()

This returns as expected in Chrome. It returns empty in phantomjs.

We have to use phantomjs for our CI builds.

3条回答
混吃等死
2楼-- · 2019-09-06 18:41

We resolved the issue by reverting the version of phantomjs from 1.9.7 to 1.9.1 and the following library dependencies:

def seleniumVersion = "2.41.0"
def gebVersion = "0.9.0"

test "org.gebish:geb-spock:$gebVersion"
test "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
test( "com.github.detro.ghostdriver:phantomjsdriver:1.0.4" ) {
    transitive = false
}
查看更多
爷、活的狠高调
3楼-- · 2019-09-06 18:46

If for whatever reason geb isn't supporting your phantomjs driver properly, you can always execute a javascript selector directly through the browser:

def webElements = browser.driver.executeScript("""return document.querySelectorAll("#graph-id g.highcharts-legend-item tspan"); """)
def gebNavigators = webElements.collect{ new NonEmptyNavigator(browser, it) }

Which will give you a list of geb navigators which point to the selected elements.

查看更多
放我归山
4楼-- · 2019-09-06 18:51

I don't have phantomjs on my machine but can you please try this and update us whether it's working or not?

$("#graph-id .highcharts-legend-item").find("tspan").text()
查看更多
登录 后发表回答