Selenium 2.0 with ChromeDriver for testing of Joomla sites - part 2 (revisited)

Rate this item
(0 votes)

For application testing of web sites is Selenium framework very well suited tool. But as many times so usual it has some difficult parts which costs the tester long time for searching of the satisfactory solution. One of obstacles is working with multilevel menu item selection for switching from one to some other page.

During last sessions testing new JotCache extension on Joomla 2.5.11 was found that solution described in blog article Using Selenium 2.0 with ChromeDriver for testing of Joomla sites was partially unstable sometimes running as desired sometimes the test was waiting and waiting on menu item click position without any further movement to the next test step. The problem was recognized as unsufficient recognition of menu link.

Using latest version of Webdriver 2.33 were checked out following solution :

1. using javascript for making clickable menu item visible :

public void setElementVisible(WebElement el) {
    String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
    ((JavascriptExecutor) driver).executeScript(js, el);

WebElement menuitem = driver.findElement(By.xpath("//div[@id='module-menu']/ul/li[a[text()='Content']]/ul/li/a[text()='Article Manager']"));

2. using Actions for cascade access to requested menu item :

public void clickThreeLevelMenu (String level1Text, String level2Text, String level3Text) {
   WebElement el = driver.findElement(By.xpath("//a[text()='" + level1Text + "']"));
   WebElement el2 = driver.findElement(By.xpath("//a[text()='" + level2Text + "']"));
   Actions acts = new Actions(driver);
   WebElement el3 = driver.findElement(By.xpath("//a[text()='" + level3Text + "']"));

Both shown solutions helped to solve some specific obstacles but sometimes still happens the test run stop because of error "cannot find the reqested element". Joomla site response time varies very heavy and find the proper adjustment was difficult.

As the final solution was taken case #1 with implemented wait condition, using contains(text(),..) Xpath function and direct click on clickable menu item by javascript :

public void clickTwoLevelMenu(String level1Text, String level2Text) {
    WebElement menuitme = Do.elementXpathWait("//div[@id='module-menu']/ul/li[a[text()='" + level1Text + "']]/ul/li/a[contains(text(),'" + level2Text + "')]");
    String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';arguments[0].click();";
    ((JavascriptExecutor) driver).executeScript(js, menuitme);

Final test code was used in different use cases with good, stable operation.


Read 1665 times Last modified onSunday, 16 August 2015 09:11

Only registred users have rights to post comments. Please log-in or create an account.

We have 43 guests and no members online
Copyright © 2015 JotComponents
We have 43 guests and no members online
Copyright © 2022 JotComponents