1

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();
    }

}



}
snikt
  • 581
  • 4
  • 11
  • 27
  • Any particular reason you are writing your own (yet another) Selenium FitNesse integration? Have you checked out the available plugins at http://fitnesse.org/PlugIns#slimfixtures? – Fried Hoeben Sep 09 '17 at 08:09
  • Why are you writing a Fit column fixture, do you want to create some form of decision table? When I look at the code and wiki I can't quite make out what you expect the table to represent. When you want to use a table to perform a number of steps (like opening a page) sequentially I would recommend switching to the Slim test runner and using its script table (http://fitnesse.org/FitNesse.FullReferenceGuide.UserGuide.WritingAcceptanceTests.SliM.ScriptTable). Your current code uses a jUnit `BeforeMethod` annotation, that is not something that means or does anything in a FitNesse context. – Fried Hoeben Sep 09 '17 at 08:15
  • Thank you for your response. I was not aware of the slimfixture plugins. Can you give me a step by step on how to import them into my eclipse project. Is it as simple as adding a maven dependency? If not, where is the jar exactly? Many thanks (fyi - I'm beginner to intermediate with all this, I'm used to Cucumber, but the company I'm working for wants fitnesse). – snikt Sep 09 '17 at 16:25
  • (Warning: I'm biassed as the following project is mine). I would suggest creating your own FitNesse Maven project based on one of the approaches described at https://github.com/fhoeben/hsac-fitnesse-fixtures#to-create-your-own-test-project. This gives you a FitNesse project where you can use the 'BrowserTest' fixture (https://github.com/fhoeben/hsac-fitnesse-fixtures/wiki/2.-Slim-Fixtures#browsertest) to perform your Selenium tests. But you don't have to use the whole setup, you can also just add it as a maven project(see the releases of the project), but then some more manual config is needed – Fried Hoeben Sep 09 '17 at 17:38

1 Answers1

1

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.

Jim Weaver
  • 983
  • 5
  • 15
  • Thank you Jim, I changed my wiki to reflect the 'basic docs for column fixture' link you gave me - !|SeleniumFitnesse| |URL | navigateToSite?| |http://www.google.com| But I get a - Method navigateToSite[0] not found in FitNesseConcept.fitNesse.SeleniumFitnesse. Any ideas? – snikt Sep 11 '17 at 16:13
  • Yes - your method for navigateToSite as in code above takes a single input parameter, which is the URL - fitnesse is trying to call a no argument method. Try changing your fixture on the wiki to pass the URL as a separate column, and create a public property on your fixture class for it. So: |url|navigateToSite?|, and "public string url;" on your fixture class. Remove the input parm from the navigateToSite method, and instead reference the url property. – Jim Weaver Sep 11 '17 at 17:12
  • Hi Jim, I made the changes you requested. The Wiki passes with all green, and returns a Void in the empty column. I made edits to my origional question so you can see what I did. The browser never launches :( – snikt Sep 11 '17 at 17:48
  • lol - well progress ;-). That's probably getting into webdriver stuff now, which is different quest. But, you might try to take the code you have that is trying to launch browser, and move it to another class - not in the fixture. Then invoke that from a Java Main and run it - verify browser starts up OK. Once you have that working then you can hook it up to fitnesse fixture again. – Jim Weaver Sep 11 '17 at 17:50
  • ah wait I probably see your issue. You have a unit test framework annotation on your setupClass method. That is not going to be invoked - fitnesse does not know anything about testng - you aren't running it as a unit test so that annotation does nothing. Fitnesse will call a no argument constructor on the fixture class though, so try putting your setup code in constructor for the fixture class instead. – Jim Weaver Sep 11 '17 at 17:55
  • I removed the @BeforeMethod annotation, and kept everything else as is, but still the wiki returns a "Void" :( – snikt Sep 13 '17 at 18:14
  • I think you need to move the code that's inside your setupClass method into a standard java constructor for that fixture class. – Jim Weaver Sep 13 '17 at 19:10
  • Thank you my friend. I did a standard java constructor 'this time' (removing the @BeforeMethod annotation was not enough, I'm sorry for that!). When running the wiki, it threw this - "Could not invoke constructor for SeleniumFitnesse[0]" – snikt Sep 14 '17 at 05:01
  • haha you have a lot of issues! Wassup with that? ;-). I think this last one sounds like fitnesse cannot find your most recent source code, or the constructor is not right. Post your constructor up above, but double check your fitnesse path first, and make sure your newly compiled fitnesse fixture .class file is available to that fitnesse path. – Jim Weaver Sep 14 '17 at 18:33
  • Hi Buddy, Ok, my constructor was not public (dumb mistake). Fixed that, ran it and I copied everything back to the original question (Code and Wiki). Many thanks for your help my friend. This is the new error LOL - java.lang.NoSuchMethodError: org.openqa.selenium.remote.service.DriverCommandExecutor.(Lorg/openqa/selenium/remote/service/DriverService;Ljava/util/Map;)V – snikt Sep 15 '17 at 04:08
  • You think it is a problem with selenium version? Java-client, server or remote driver? – snikt Sep 15 '17 at 04:12
  • That's getting into Selenium / WebDriver API and I'm less informed, but yes that type of error is usually a version mismatch between two things. It might be easier for you to diagnose that if you just create a java class with a "main" method that is entirely independent of fitnesse and execute it. You can download the latest java webdriver api on selenium hq site, I believe. – Jim Weaver Sep 15 '17 at 14:35