Java 为什么会跳过一些案例?

Java 为什么会跳过一些案例?,java,selenium,Java,Selenium,虽然我可以运行这个测试用例,但它会跳过一些测试用例,然后它会再次回来运行那个测试用例 package WebApplication; import java.io.IOException; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; i

虽然我可以运行这个测试用例,但它会跳过一些测试用例,然后它会再次回来运行那个测试用例

    package WebApplication;  
    import java.io.IOException;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.Select;
    import org.openqa.selenium.support.ui.WebDriverWait;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;

    import CommonDetails.Driverselectiondetails;

    public class TimeClockWizard extends Driverselectiondetails {
        public WebDriver driver;

        // Driver installation
        @BeforeTest
        public void insatllation() throws IOException, InterruptedException {
            driver = drivernavigation();

        }

        // Forgotsubdominepage
        @Test
        public void Forgotsubdomine() throws InterruptedException {
            driver.get("https://apps.timeclockwizard.com");

            Forgotsubdomine bsd = new Forgotsubdomine(driver);
            bsd.getlink().click();
            System.out.println("forgotsubdominepage:" + driver.getTitle());
            bsd.getforgotlink().sendKeys("tbs.shailesh@gmail.com");
            bsd.getsendmail().click();
            WebDriverWait wait = new WebDriverWait(driver, 5000);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("txtSubDomain")));
            // bsd.getbackbutton().click();

        }

        // Subdominehomepage and forgot password page
        @Test
        public void Subdominepage() throws InterruptedException {
            Subdominepage sp = new Subdominepage(driver);
            sp.getsubname().sendKeys("technobrains");
            sp.getbutton().click();
            WebDriverWait wait = new WebDriverWait(driver, 15);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("aForgotPassword")));
            Forpassword fp = new Forpassword(driver);
            fp.getforgotpasswordlink().click();
            fp.gteenteremail().sendKeys("tbs.shailesh@gmail.com");
            fp.getresetpasswordbutton().click();
            Thread.sleep(5000);
            driver.navigate().back();
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("btnSelfRegister")));
        }

        // selfregistration page
        @Test
        public void slefregistartion() {
            SelfRegistration sr = new SelfRegistration(driver);
            sr.getselfregilink().click();
            sr.getenterpin().sendKeys("1234");
            sr.getdonebutton().click();
            WebDriverWait wait = new WebDriverWait(driver, 50);
            wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.cssSelector("#modelSelfRegistration > div > div > div.modal-header.border_none > h4")));
            System.out.println(sr.gettiltelofpage().getText());
            sr.getfullname().sendKeys("prsanthkumar");
            sr.getemail().sendKeys("tbs.prasanth@gmail.com");
            sr.getusername().sendKeys("prasanth421");
            sr.getpassword().sendKeys("tbs@67789");
            sr.getconformpassword().sendKeys("tbs@67789");
            sr.getdateofbirth().sendKeys("12122010");
            sr.getaddress().sendKeys("India");
            Select dropcon = new Select(driver.findElement(By.id("ddlCountry")));
            dropcon.selectByVisibleText("India");
            sr.getcity().sendKeys("India");
            sr.getstate().sendKeys("india");
            sr.getzip().sendKeys("12345");
            sr.gethomephone().sendKeys("7382978410");
            sr.getworkphone().sendKeys("1234567891");
            sr.getemergencycontactname().sendKeys("prasanth");
            sr.getemergencycontactnumber().sendKeys("7896541232");
            sr.getcellphone().sendKeys("7896541230");
            sr.getworkextension().sendKeys("2222222");
            Select droptime = new Select(driver.findElement(By.id("ddlTimeZone")));
            droptime.selectByIndex(5);
            sr.getcapche().click();
            sr.getaddbutton().click();

        }
        //For desktop app links
        public void Desktoplink() throws InterruptedException
        {
            Desktopapplications dp = new Desktopapplications();
            dp.getwindowsapp().click();
            Thread.sleep(2000);
            dp.getIOSapp();
        }
        // Login deatisl page
        @Test
        public void login()
        {
            LoginPage lp = new LoginPage(driver);
            lp.getusername().sendKeys("ravi");
            lp.getpassword().sendKeys("tbs@67789");
            lp.getloginbutton().click();
        }

        // Closing the driver
        @AfterTest
        public void closingdriver() {
            driver.close();
        }

    }
在该代码中也可以看到,首先它将运行前面提到的subdomine(),然后是subdomine(),它将重定向到Login(),然后它将返回deskapp()的测试用例。我不给那个测试用例任何执行优先级

    package WebApplication;  
    import java.io.IOException;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.Select;
    import org.openqa.selenium.support.ui.WebDriverWait;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;

    import CommonDetails.Driverselectiondetails;

    public class TimeClockWizard extends Driverselectiondetails {
        public WebDriver driver;

        // Driver installation
        @BeforeTest
        public void insatllation() throws IOException, InterruptedException {
            driver = drivernavigation();

        }

        // Forgotsubdominepage
        @Test
        public void Forgotsubdomine() throws InterruptedException {
            driver.get("https://apps.timeclockwizard.com");

            Forgotsubdomine bsd = new Forgotsubdomine(driver);
            bsd.getlink().click();
            System.out.println("forgotsubdominepage:" + driver.getTitle());
            bsd.getforgotlink().sendKeys("tbs.shailesh@gmail.com");
            bsd.getsendmail().click();
            WebDriverWait wait = new WebDriverWait(driver, 5000);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("txtSubDomain")));
            // bsd.getbackbutton().click();

        }

        // Subdominehomepage and forgot password page
        @Test
        public void Subdominepage() throws InterruptedException {
            Subdominepage sp = new Subdominepage(driver);
            sp.getsubname().sendKeys("technobrains");
            sp.getbutton().click();
            WebDriverWait wait = new WebDriverWait(driver, 15);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("aForgotPassword")));
            Forpassword fp = new Forpassword(driver);
            fp.getforgotpasswordlink().click();
            fp.gteenteremail().sendKeys("tbs.shailesh@gmail.com");
            fp.getresetpasswordbutton().click();
            Thread.sleep(5000);
            driver.navigate().back();
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("btnSelfRegister")));
        }

        // selfregistration page
        @Test
        public void slefregistartion() {
            SelfRegistration sr = new SelfRegistration(driver);
            sr.getselfregilink().click();
            sr.getenterpin().sendKeys("1234");
            sr.getdonebutton().click();
            WebDriverWait wait = new WebDriverWait(driver, 50);
            wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.cssSelector("#modelSelfRegistration > div > div > div.modal-header.border_none > h4")));
            System.out.println(sr.gettiltelofpage().getText());
            sr.getfullname().sendKeys("prsanthkumar");
            sr.getemail().sendKeys("tbs.prasanth@gmail.com");
            sr.getusername().sendKeys("prasanth421");
            sr.getpassword().sendKeys("tbs@67789");
            sr.getconformpassword().sendKeys("tbs@67789");
            sr.getdateofbirth().sendKeys("12122010");
            sr.getaddress().sendKeys("India");
            Select dropcon = new Select(driver.findElement(By.id("ddlCountry")));
            dropcon.selectByVisibleText("India");
            sr.getcity().sendKeys("India");
            sr.getstate().sendKeys("india");
            sr.getzip().sendKeys("12345");
            sr.gethomephone().sendKeys("7382978410");
            sr.getworkphone().sendKeys("1234567891");
            sr.getemergencycontactname().sendKeys("prasanth");
            sr.getemergencycontactnumber().sendKeys("7896541232");
            sr.getcellphone().sendKeys("7896541230");
            sr.getworkextension().sendKeys("2222222");
            Select droptime = new Select(driver.findElement(By.id("ddlTimeZone")));
            droptime.selectByIndex(5);
            sr.getcapche().click();
            sr.getaddbutton().click();

        }
        //For desktop app links
        public void Desktoplink() throws InterruptedException
        {
            Desktopapplications dp = new Desktopapplications();
            dp.getwindowsapp().click();
            Thread.sleep(2000);
            dp.getIOSapp();
        }
        // Login deatisl page
        @Test
        public void login()
        {
            LoginPage lp = new LoginPage(driver);
            lp.getusername().sendKeys("ravi");
            lp.getpassword().sendKeys("tbs@67789");
            lp.getloginbutton().click();
        }

        // Closing the driver
        @AfterTest
        public void closingdriver() {
            driver.close();
        }

    }

尝试设置@Test的优先级。例如。您想要得到的测试首先执行@test(priority=0),然后依次执行。

尝试设置@test的优先级。例如。您想要得到的测试首先执行@test(priority=0),其余的测试依次执行。希望这有帮助。@kaustubh tnx现在正在工作,很高兴它有帮助。我把它贴出来作为答复。请点击答案上的向上箭头并接受它。干杯!