2017-04-03 31 views
-1
Feature: Test Milacron Smoke scenario 

    Scenario: Test login with valid credentials 
    Given open firefox and start application 
    When I click on Login 
    And enter valid "[email protected]" and valid "passw0rd" 
    Then Click on login and User should be able to login successfully 

    Scenario: Test shop for cart 
    Given Click on shop for carts 
    And select plates 
    When Click on Add to cart 
    Then product should be added in the cart successfully 

Runner.class當產品在車已加入它的投擲元素是不能點擊例外

package runner; 

import org.junit.runner.RunWith; 

import cucumber.api.junit.Cucumber; 

@RunWith(Cucumber.class) 
@Cucumber.Options(features="features",glue={"steps"}, format = {"pretty", "html:target/Destination"}) 

public class TestRunnr { 

} 

StepDefinition.class

public class MilacronSmoke { 
    static WebDriver driver; 
    @Given("^open firefox and start application$") 
    public void open_firefox_and_start_application() throws Throwable { 
     driver=new FirefoxDriver(); 
     driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES); 
     driver.get("https://milacronqa.genalphacatalog.com"); 

    } 

    @When("^I click on Login$") 
    public void I_click_on_Login() throws Throwable { 
     driver.findElement(By.xpath("//a[contains(.,'Login')]")).click(); 

    } 

    @When("^enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$") 
    public void enter_valid_and_valid(String uname, String pass) throws Throwable { 
     driver.findElement(By.id("Username")).sendKeys(uname); 
     driver.findElement(By.id("Password")).sendKeys(pass); 

    } 

    @Then("^Click on login and User should be able to login successfully$") 
    public void Click_on_login_and_User_should_be_able_to_login_successfully() throws Throwable { 
     driver.findElement(By.id("loginUser")).click(); 

    } 


    @Given("^Click on shop for carts$") 
    public void Click_on_shop_for_carts() throws Throwable { 

     driver.findElement(By.xpath("//span[text()='Shop for Parts']")).click(); 

    } 

    @Given("^select plates$") 
    public void select_plates() throws Throwable { 
     driver.findElement(By.xpath("//a[contains(.,'Plates ')]")).click(); 

    } 


    @When("^Click on Add to cart$") 
    public void Click_on_Add_to_cart() throws Throwable { 
     driver.findElement(By.xpath(".//*[@id='product-catalog-hldr']/div[1]/div[4]/button[1]")).click(); 
    } 



    @Then("^product should be added in the cart successfully$") 
    public void product_should_be_added_in_the_cart_successfully() throws Throwable { 
     WebElement element = driver.findElement(By.xpath("//a[contains(.,'Cart1')]")); 
     element.click(); 

     WebElement element1=driver.findElement(By.xpath("//a[contains(.,'Item # 10010773')]")); 
     String str=element1.getText(); 
     System.out.println(str); 
     Assert.assertEquals("Item # 10010773", str); 
     System.out.println("Test passed successfully"); 
} 
} 

當已經添加任何產品在購物車中它沒有點擊購物車和拋出元素是可點擊的異常,如果購物車是空的,這個腳本是wor國王罰款如下:

org.openqa.selenium.WebDriverException:元素不可點擊點(1193,52)。其他元素將收到點擊: 命令持續時間或超時:76毫秒 構建信息:版本:'2.53.1',修訂:'a36b8b1',時間:'2016-06-30 17:32:46' 系統信息:host:'WLL16GJ7',ip:'10 .1.18.240',os.name:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'1.8.0_121' 驅動程序信息:org.openqa.selenium.firefox.FirefoxDriver 功能[{applicationCacheEnabled = true,rotate = false,handlesAlerts = true,databaseEnabled = true,version = 47.0.1,platform = WINDOWS,nativeEvents = false,acceptSslCerts = true, webStorageEnabled = true,locationContextEnabled = true,browserName = firefox,takesScreenshot = true,javascriptEnabled = true,cssSelectorsEnabled = true}] 會話ID:95fda63b-abc3-4758-825d-223e67522d86 at sun.reflect.NativeConstructorAccessorImpl .newInstance0(本機方法) 在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在java.lang.reflect.Constructor.newInstance( Constructor.java:423) 在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) 在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) 的組織。在org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327) (位於org.openqa.selenium.remote.RemoteWebElement.click())處打開openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) RemoteWebElement.java:85) 在steps.MilacronSmoke.product_should_be_added_in_the_cart_successfully(MilacronSmoke.java:75) 的。那麼產品應在成功的購物車(MyApplication.feature:13)加入?

+0

爲AUT提供HTML代碼段。 – SelThroughJava

+0

https://milacronqa.genalphacatalog.com –

回答

0

我不知道實際的Java代碼,但嘗試引入等待幾毫秒(或者等到,如果您希望它在需要時繼續),請確保具有xpath://div[contains(@class, 'pageLoader')]的元素不再出現在頁面上。

我有一種感覺,它是點擊添加按鈕,立即嘗試點擊購物車,但它不能,因爲這個pageLoader元素的方式。

編輯

我已經做了一些搜索,並發現this,它看起來像什麼,我在說什麼。

這些部件特別是:

import org.openqa.selenium.support.ui.WebDriverWait; 

而且

WebDriverWait wait = new WebDriverWait(webDriver, 1); 
    wait.until(ExpectedConditions.elementToBeClickable(By.id("celcius"))); 

當然,你的代碼會更喜歡這樣的:

@Then("^product should be added in the cart successfully$") 
public void product_should_be_added_in_the_cart_successfully() throws Throwable { 

    // THIS IS THE NEW BIT 
    WebDriverWait wait = new WebDriverWait(webDriver, 1); 
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(.,'Cart1')]"))); 
    // UNTIL HERE 

    WebElement element = driver.findElement(By.xpath("//a[contains(.,'Cart1')]")); 
    element.click(); 

    WebElement element1=driver.findElement(By.xpath("//a[contains(.,'Item # 10010773')]")); 
    String str=element1.getText(); 
    System.out.println(str); 
    Assert.assertEquals("Item # 10010773", str); 
    System.out.println("Test passed successfully"); 
} 

只記得有包括聲明您的步驟定義文件

相關問題