0

I am a bit new to eclipse and the cucumber/selenium combo. I have three files: a feature, a TestRunner, and the stepDefintion file. I would like to be able to run these files outside of the eclipse IDE. I need to be able to run these tests on a different computer that does not have Eclipse or access to external websites, only the one that will be tested. I've included code for the three sample files (this does not include the proper URL or credentials). I would like to make this somehow executable, however I know that lacking a main method, I can't run this as a Jar.

Feature:

Feature: Login Action
 
Scenario: Successful Login with Valid Credentials
 Given User is on Home Page
 When User enters "maximo" and "source1"
 Then Message displayed Login Successfully
 
Scenario: Successful LogOut
 When User LogOut from the Application
 Then Message displayed LogOut Successfully

TestRunner

package cucumberTest;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
  features = "Feature"
  ,glue={"stepDefinition"}
  , monochrome = true
  , plugin  = {"pretty"}
  )

public class firstTestCase {

}

And the actual Step Definitions

package stepDefinition;
 
import java.util.concurrent.TimeUnit;
 
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class Test_Steps {
 public static WebDriver driver;
 private String baseUrl;
 static WebDriverWait wait;
 
 @Given("^User is on Home Page$")
 public void user_is_on_Home_Page() throws Throwable {
  System.setProperty("webdriver.chrome.driver", 
    "C:\\Selenium\\chromedriver.exe");
  
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        baseUrl = "https://maximo-demo76.mro.com/";
        wait = new WebDriverWait(driver, 60);
        driver.get(baseUrl + "/maximo/webclient/login/login.jsp?welcome=true");
  }
 
// @When("^User Navigate to LogIn Page$")
// public void user_Navigate_to_LogIn_Page() throws Throwable {
//  driver.findElement(By.xpath(".//*[@id='account']/a")).click();
//  }S
 
 
 @When("^User enters \"(.*)\" and \"(.*)\"$")
 public void user_enters_UserName_and_Password(String realUsername, String realPassword) throws Throwable {
  driver.findElement(By.id("username")).clear();
  driver.findElement(By.id("username")).sendKeys(realUsername);
  driver.findElement(By.id("password")).clear();
     driver.findElement(By.id("password")).sendKeys(realPassword);
     driver.findElement(By.id("loginbutton")).click();
 }

 
 @Then("^Message displayed Login Successfully$")
 public void message_displayed_Login_Successfully() throws Throwable {
  System.out.println("Login Successfully");
 }
 
 @When("^User LogOut from the Application$")
 public void user_LogOut_from_the_Application() throws Throwable {
  WebElement logOut =
       driver.findElement(By.id("titlebar_hyperlink_8-lbsignout_image"));
  Actions actions = new Actions(driver);
  actions.moveToElement(logOut).click().perform();
 }
 
 
 @Then("^Message displayed LogOut Successfully$")
 public void message_displayed_LogOut_Successfully() throws Throwable {
     // Write code here that turns the phrase above into concrete actions
  System.out.println("LogOut Successfully");
 }
 
}
Jrawr
  • 199
  • 2
  • 3
  • 15
  • Duplicate of http://stackoverflow.com/questions/30586937/how-to-run-cucumber-file-from-command-line. Also why do you have runwith and cucumberoptions in your step definition class. – Grasshopper Aug 23 '16 at 13:34
  • Oh that was a mistake in posting on here. It's not in the actual file. Thank you for the catch. I'll check this other question. – Jrawr Aug 23 '16 at 15:15
  • The answer on the other question still seems a little too high level for me. I'm hoping someone can break it down a little further. This is all still kind of new to me. – Jrawr Aug 23 '16 at 15:19

0 Answers0