Fitnesse wiki unable to call selenium method correctly

963 views Asked by At

I am trying to write a simple fixture that opens the browser and navigates to www.google.com. When I run the wiki page, it passes with all green, but the browser never opens up (I don't think the method even gets called by the wiki). Can someone take a look at my fixture and wiki to see what I am doing wrong? Many thanks in advance,

Here is the Wiki -

 !|SeleniumFitness|
  |URL                  |navigateToSite?|
  |http://www.google.com|               |

After Running -

!|SeleniumFitnesse| java.lang.NoSuchMethodError: org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(Lorg/openqa/selenium/remote/service/DriverService;Ljava/util/Map;)V
 |URL |The instance decisionTable_4.setURL. does not exist|navigateToSite? 
 |http://www.google.com|!The instance decisionTable_4.navigateToSite. does not exist |

Here is the Fixture -

package FitNesseConcept.fitNesse;

import java.util.Properties;

import org.junit.BeforeClass;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeMethod;

//import com.google.common.base.Preconditions.*;
//import com.google.common.collect.Lists;

import fit.ColumnFixture;

public class SeleniumFitnesse extends ColumnFixture {

public static ChromeDriver driver = null;
private String navigateToSite = "";
public String URL = "";



    public SeleniumFitnesse() {

    Properties props = System.getProperties();

    props.setProperty("webdriver.chrome.driver", "/home/ninad/eclipse-workspace/chromedriver");

    driver = new ChromeDriver();
    }



// SET-GET Methods

public String getURL() {
    return URL;
}

public void setURL(String uRL) {
    URL = uRL;
}

public String getNavigateToSite() {
    return navigateToSite;
}

public void setNavigateToSite(String navigateToSite) {
    this.navigateToSite = navigateToSite;
}

// Navigate to URL

public void navigateToSite() throws Throwable {
    System.out.println("Navigating to Website");

    try {
        driver.navigate().to(URL);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}



}
1

There are 1 answers

12
Jim Weaver On BEST ANSWER

You are getting some good recommendations as comments - but to answer your question directly, for an old-style ColumnFixture, which is what you have written, the method "navigateToSite" is indeed not going to be called.

These styles of fixtures are not often used anymore, Slim is preferred, and your fitnesse instance in its documentation will show you how to use Slim style. However, for a column fixture as you have written, if you want a method to be called it needs to be a "?" following name of the method in the header row.

See basic docs for column fixture: http://fitnesse.org/FitNesse.UserGuide.FixtureGallery.BasicFitFixtures.ColumnFixture

You are mis-using column fixture, even granted the old style though. Column fixture's pattern is "here is a series of columns that represent inputs, now here is a method call I want to make to get the output and check result". Navigating a website does not often fit that pattern. In old style fitnesse it would probably be approached by an ActionFixture:

http://fitnesse.org/FitNesse.UserGuide.FixtureGallery.BasicFitFixtures.ActionFixture

In the newer Slim style, a good fit for navigation and checking where you are would be a Scenario Table.

http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.SliM.ScenarioTable

In general doing WebDriver / Selenium tests through a wiki is worth extra thought as to whether it's your best medium. Fitnesse is really designed to be a collaborative tool for documenting and verifying business requirements, directly against source code.

Here's an example of how to do with a ColumnFixture, although again ColumnFixture not exactly appropriate:

|url|navigateToUrl?|
|www.google.com| |

java class:
public String url;

public void navigateToUrl() {
}

You could return an "OK" if it navigates alright, or return the title of the page as opposed to void if you wanted.