从eclipse

时间:2016-08-23 12:59:53

标签: java eclipse selenium cucumber cucumber-jvm

我对日食和黄瓜/硒组合有点新鲜。我有三个文件:功能,TestRunner和stepDefintion文件。我希望能够在eclipse IDE之外运行这些文件。我需要能够在没有Eclipse或访问外部网站的其他计算机上运行这些测试,只需要测试一个。我已经包含了三个示例文件的代码(这不包括正确的URL或凭据)。我想以某种方式使这个可执行,但我知道缺少一个主方法,我不能把它作为一个Jar运行。

功能:

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 {

}

实际步骤定义

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

0 个答案:

没有答案