Pagefactory中的Arity不匹配错误消息

时间:2018-08-09 23:31:39

标签: java selenium

我正在homedepot.com练习 现在我有这种问题被卡住,错误信息是:  “ Arity不匹配:步骤定义'StepsTestCase.SearchShoppingStep.click_close_button_in_add_to_cart_window(WebDriver)在文件:/ C:/ Users / Administrator / git / MavenProject / target / classes /中,其模式为[^单击添加到购物车窗口中的关闭按钮$]带有1个参数声明,但小黄瓜步骤具有0个参数[]。       步骤:在“添加到购物车”窗口中单击关闭按钮时

我在步进定义中的代码:

公共类SearchShoppingStep {

@Given("^Input 'Hammer' in search bar$")

public void input_Hammer_in_search_bar() throws Throwable {
     System.setProperty("webdriver.chrome.driver", "C://Webdrivers//chromedriver.exe/");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        driver.navigate().to("https://www.homedepot.com");
    ShoppingPage SP = PageFactory.initElements(driver, ShoppingPage.class);
   ShoppingPage.SearchBar.sendKeys("Hammer");
}

@Given("^Click search button$")
public void click_search_button() throws Throwable {
 ShoppingPage.SearchBtn.click();
}

@When("^Verify 'Husky_(\\d+)_oz\\. Fiberglass_Claw_Hammer' is displayed$")
public void verify_Husky___oz_Fiberglass_Claw_Hammer_is_displayed(int arg1) throws Throwable {
     if(ShoppingPage.Husky16oz.isDisplayed() )      
        {
             System.out.println("'Husky 16 oz. Fiberglass Claw Hammer' displayed.");
        }
        else
        {
            System.out.println("'Husky 16 oz. Fiberglass Claw Hammer' not displayed.");
        }
}

@When("^Click add to cart button of \"([^\"]*)\"$")
public void click_add_to_cart_button_of(String arg1) throws Throwable {
    ShoppingPage.AddtoCartBtn.click();
}

@When("^Click close button in add to cart window$")
public void click_close_button_in_add_to_cart_window(WebDriver driver) throws Throwable {
      driver.switchTo().frame(ShoppingPage.IframeXpath);
    ShoppingPage.ClsBtnOfIframe.click();
}

@Then("^go back to homepage$")
public void go_back_to_homepage() throws Throwable {
   ShoppingPage.HomeDepotLogoBtn.click();
}

@Then("^verify  selected items in cart is displayed$")
public void verify_selected_items_in_cart_is_displayed() throws Throwable {
    String quantity =
            ShoppingPage.IteminMycart.getText();
                    int n = Integer.parseInt(quantity);
                    if(n==1) {
                            System.out.println("1 item is selected");
                    }else {
                            System.out.println("Check the cart");
                    }
}

@Given("^Input 'Bug_Spray' in search bar$")
public void input_Bug_Spray_in_search_bar() throws Throwable {
    ShoppingPage.SearchBar.clear();
    ShoppingPage.SearchBar.sendKeys("Bug Spray");
}

@When("^click searh button$")
public void click_searh_button() throws Throwable {
   ShoppingPage.SearchBtn.click();
}

@Then("^verify 'Repel (\\d+)\\.(\\d+) oz\\. Aerosol Sportsmen Max Insect Repellent' is displayed$")
public void verify_Repel_oz_Aerosol_Sportsmen_Max_Insect_Repellent_is_displayed(int arg1, int arg2) throws Throwable {
     if(ShoppingPage.RepelInsectRepellent.isDisplayed() )      
        {
             System.out.println("''Repel 6.5 oz. Aerosol Sportsmen Max Insect Repellent' is displayed.");
        }
        else
        {
            System.out.println("'Repel 6.5 oz. Aerosol Sportsmen Max Insect Repellent' is not displayed.");
        }
}

@Then("^go back to home page$")
public void go_back_to_home_page() throws Throwable {
      ShoppingPage.HomeDepotLogoBtn.click();
}

}

和功能文件:

@ Searchitem1   场景:SearchItem1     在搜索栏中输入“ Hammer”     然后点击搜索按钮     当验证'Husky_16_oz。显示“ Fiberglass_Claw_Hammer”     然后点击“ Husky_16oz”的添加到购物车按钮     单击添加到购物车窗口中的关闭按钮时     然后返回首页     并确认已显示购物车中的选定项目

它在“ 在添加到购物车窗口中单击关闭按钮时时停止”

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:0)

通过以下方法删除参数WebDriver驱动程序。您没有在功能文件中提及自变量。因此,您无法在此方法中使用参数。

@When("^Click close button in add to cart window$")
public void click_close_button_in_add_to_cart_window(WebDriver driver) throws Throwable {
      driver.switchTo().frame(ShoppingPage.IframeXpath);
    ShoppingPage.ClsBtnOfIframe.click();
}