代码之家  ›  专栏  ›  技术社区  ›  Ahmad Raza

获取java.lang.IollegalArgumentException:在BDD cucumber中运行功能文件时必须设置驱动程序错误

  •  0
  • Ahmad Raza  · 技术社区  · 1 年前

    这是我的Runner类:

    ``package baseclass.local.Ios;
    
    
    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.ios.IOSDriver;
    import io.cucumber.junit.Cucumber;
    import io.cucumber.junit.CucumberOptions;
    import org.junit.runner.RunWith;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;
    import uitests.ios.Page.DirectoryWidget;
    
    import java.net.MalformedURLException;
    import java.net.URL;
    
    import static server.local.AppiumServerTest.startAppiumServer;
    @RunWith(Cucumber.class)
    @CucumberOptions(
            features = "src/test/resources",
            glue = "src/test/java/uitests/ios/Page",
            tags = "@tagname",
            plugin = {
                    "pretty",
                    "html:target/cucumber-reports",
                    "json:target/cucumber-reports/cucumber.json"
            }
    )
    public class LikesTest {
    
        public AppiumDriver driver;
    
        @BeforeTest
        public void setup() throws MalformedURLException {
            startAppiumServer();
            DesiredCapabilities caps = new DesiredCapabilities();
    
            caps.setCapability("platformName", "iOS");
            caps.setCapability("automationName", "XCUITest");
            caps.setCapability("deviceName", "iPhone 14 Pro");
            caps.setCapability("n", "4CE8F504-2285-47D9-AA52-371550EB3873");
            caps.setCapability("wdaStartupRetries", "4");
            caps.setCapability("iosInstallPause","8000" );
            caps.setCapability("wdaStartupRetryInterval", "20000");
            caps.setCapability("appium:noReset", "true");
    
            caps.setCapability("app", System.getProperty("user.home") + "/Library/Developer/Xcode/DerivedData/Sandmann-bxvuahotesmmbjhbcbaqtalefoar/Build/Products/Debug-iphonesimulator/Polario.app");
            this.driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);
            System.out.println(this.driver);
        }
        @Test(priority = 1)
        public void LikesTest() throws MalformedURLException {}`
    
    

    这是功能文件:

    Feature: Likes
    
      #1 when there is a like button then user should be able to like the page or news
      @Positive
      Scenario: Like Page or News
       Given the user has login to the app and navigated to Page or News
        When user press on like button
        Then user has liked the page or news
    

    这是步骤定义类:

    `package uitests.ios.Page;
    
    import io.appium.java_client.AppiumDriver;
    import io.cucumber.java.en.Then;
    import io.cucumber.java.en.When;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.support.FindBy;
    import org.openqa.selenium.support.PageFactory;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    import java.time.Duration;
    
    public class Likes {
        public AppiumDriver driver;
        AppiumDriver thatDriver;
        public Likes(AppiumDriver driver) {
    
            PageFactory.initElements(driver, this);
            this.driver = driver;
        }
       @Given("the user has login to the app and navigated to Page or News")
        public void the_user_has_login_to_the_app_and_navigated_to_page_or_news() {
            Actions actions = new Actions(driver);
            WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(40));
            new WebDriverWait(driver, Duration.ofSeconds(10));
    
            try {
                if (allowNotificationsBtnOnSystemDialogue.isDisplayed()) {
                    allowNotificationsBtnOnSystemDialogue.click();
                    new WebDriverWait(driver, Duration.ofSeconds(2));
                    allowNotificationsBtnOnSystemDialogue.click();
                    wait.until(ExpectedConditions.visibilityOf(email));
                    email.click();
                    email.sendKeys("[email protected]");
                    password.click();
                    password.sendKeys("T123plazz");
                }
    
            }catch (NoSuchElementException e) {
                new WebDriverWait(driver, Duration.ofSeconds(10));
                email.sendKeys("[email protected]");
                new WebDriverWait(driver, Duration.ofSeconds(10));
                password.sendKeys("T123plazz");
    
            }
            new WebDriverWait(driver, Duration.ofSeconds(5));
            loginBtn.click();
            new WebDriverWait(driver, Duration.ofSeconds(3));
    
            try {
                if (allowNotificationsBtnOnSystemDialogue.isDisplayed()) {
                    allowNotificationsBtnOnSystemDialogue.click();
                }
    
            }
            catch (NoSuchElementException e) {}
    
            ExpectedCondition<Boolean> condition = ExpectedConditions.or(
                    ExpectedConditions.visibilityOf(userTitleOnHomePage_Android),
                    ExpectedConditions.visibilityOf(userTitleOnHomePage_iOS)
            );
    
            new WebDriverWait(driver, Duration.ofSeconds(10));
            //scrollDown();
            smallScrollDown();
            new WebDriverWait(driver, Duration.ofSeconds(2));
            //opening project
            projectForAutomationOnHomePage.click();
            wait.until(ExpectedConditions.visibilityOf(projectMenuBtn));
    
    
            if (projectMenuBtn.isDisplayed()) {
                projectMenuBtn.click();
                System.out.println("1st clicked");
            }
            new WebDriverWait(driver, Duration.ofSeconds(2));
            actions.moveToElement(pageMenuItem).click().build().perform();
            new WebDriverWait(driver, Duration.ofSeconds(6));
            wait.until(ExpectedConditions.visibilityOf(titleOnPageTop));
    
            System.out.println(  "test is run successfully");
    
        }
        @When("user press on like button")
        public void user_press_on_like_button() {
    
            likeBtn.click();
        }
    
    
    
        @Then("user has liked the page or news")
        public void user_has_liked_the_page_or_news() {
            WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(40));
            wait.until(ExpectedConditions.visibilityOf(likedToastMessage));
        }
    
    
    
    }`
    

    不确定我为什么会出现这个错误。如果我从runner类调用步骤定义方法,然后只运行步骤runner类,那么我不会得到任何错误,但如果我从feature'文件作为场景运行测试,那么我会得到错误。

    不确定我为什么会出现这个错误。如果我从runner类调用步骤定义方法,然后只运行步骤runner类,那么我不会得到任何错误,但如果我从feature'文件作为场景运行测试,那么我会得到错误。

    我想从功能文件中运行场景,我希望runner类中的“setup”方法将启动应用程序,然后它将运行步骤定义。

    0 回复  |  直到 1 年前