一个特定的 TestNG 测试未运行,甚至没有在控制台中显示该测试

问题描述 投票:0回答:1

这是我的代码:

package Flows;

import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.PageFactoryFinder;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.SkipException;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.asserts.Assertion;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.google.common.eventbus.AllowConcurrentEvents;

import POMs.cinemaslocators;
import POMs.conditionsofAccess;
import POMs.fnbmainpage;
import POMs.loyaltyLogin;
import POMs.loyaltylLoginCred;
import POMs.nowShowing;
import POMs.paymentPage;
import POMs.purchaseconfirmation;
import POMs.seatLayout;
import POMs.showtimeslocators;
import POMs.successfullBooking;
import Support.BaseClass;
import Support.BaseClass2;
import Support.ExcelUtils;
import dev.failsafe.internal.util.Assert;
import net.bytebuddy.build.Plugin.Factory.UsingReflection.Priority;

public class GuestTicketBooking extends BaseClass2{
    public static WebDriverWait wait;
    public static ExtentReports reports;
    public static ExtentTest test;
    public static ExtentHtmlReporter reporter;
    public static String message;
    public static String Id;
    public static JavascriptExecutor js;
    public static XSSFWorkbook workbook;
    public static XSSFSheet sheet;
    

    //  BaseClass bc;




    @BeforeTest
    public void startbrowser() throws InterruptedException, IOException {

        reports = new ExtentReports();
        reporter = new ExtentHtmlReporter("extentreport.html");
        reports.attachReporter(reporter);
        test = reports.createTest("start browser", "This is the test to validate the browser started or not");      
        //      bc = new BaseClass();
        //      bc.initiateDriver();
        //      driver = new ChromeDriver();
        //      
        //      driver.manage().window().maximize();
        test.log(Status.INFO, "starting the test case");
        //      driver.get("https://amcwebv2.influx.co.in/");
        BaseClass2.browsersetup();
        test.pass("browser has been opened successfully");

    }

    @Test(priority = 1)
    public void amc_home_page()  throws InterruptedException {
        PageFactory.initElements(driver, seatlayoutprovoder.class);
        PageFactory.initElements(driver, BaseClass2.class);
        wait = new WebDriverWait(driver, Duration.ofSeconds(20));
        test = reports.createTest("Website Home Page Test", "This is the test to validate the website home page");
        test.log(Status.INFO, "starting the test case");
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@class='amc-btn-default amc-btn'][1]")));
        PageFactory.initElements(driver, loyaltylLoginCred.class);
        test.pass("website home page loaded successfully");
    }

    @Test(priority = 2)
    public  void langselection() throws InterruptedException {
        test = reports.createTest("Language selection test", "This is the Test to validate the language selection");
        test.log(Status.INFO, "starting the test case");
        PageFactory.initElements(driver,loyaltylLoginCred.class);
        loyaltylLoginCred.languageEng.click();
        test.pass("language has been selected successfully");
        Thread.sleep(10000);    
    }

    @Test(priority = 3)
    public void NowShowingMovieselection() throws InterruptedException {
        Thread.sleep(5000);
        wait = new WebDriverWait(driver, Duration.ofSeconds(20));
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@class='join-now']")));
        js = (JavascriptExecutor)driver;
        js.executeScript("window.scrollBy(0, 150)", "");
        PageFactory.initElements(driver, nowShowing.class);
        test = reports.createTest("now showing test", "This is the test to validate the now showing movie to select");
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//a[@class='amc-btn-primary amc-btn'])[14]")));
        test.log(Status.INFO, "starting the test case");
        nowShowing.getTicket.click();
        test.pass("Now Showing movie was selected");

    }

    @Test(priority = 4)
    public void session_selection() throws InterruptedException {
        PageFactory.initElements(driver, showtimeslocators.class);
        js.executeScript("window.scrollBy(0, 150)", "");
        test = reports.createTest("session selection test", "This is the test to validate the session selection");
        test.log(Status.INFO, "starting the test case");
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//span[@class='amc-time '])[1]")));
        showtimeslocators.samplesession.click();
        test.pass("session selected successfully");
        Thread.sleep(3000);

    }

    @Test(priority = 5)
    public void condition_of_access_agree() throws InterruptedException {
        test = reports.createTest("Conditions of Access Test", "This is the test to validate the conditions of access agreeing");
        PageFactory.initElements(driver, conditionsofAccess.class);
        PageFactory.initElements(driver, loyaltylLoginCred.class);
        test.log(Status.INFO, "starting the test case");
        loyaltylLoginCred.ContinueasGuest.click();
        test.pass("continue as guest has been selected successfully");
        Thread.sleep(5000);
        conditionsofAccess.agree_button.click();
        Thread.sleep(4000);
        test.pass("agree button has been clicked sucessfully");
    }

    
    
    private boolean iselementpre(String by) {
        // TODO Auto-generated method stub

        try {
            driver.findElement(By.xpath(""+by+""));
        return true;
        } catch (Exception e) {
            System.out.println(e);
            return false;
            
        }
        
        
    }
    
    
    @Test(priority = 6)
    public boolean seatclick() throws InterruptedException {
        test = reports.createTest("Seat Layout Test", "This is the test to validate the Seat Layout");
        Thread.sleep(5000);
        test.log(Status.INFO, "Test Started");      
        String element[] = {"A1", "A2", "A3", "A4", "A4", "A5", "A6", "A7"};
        for (int i = 0; i<7; i++) {
            boolean iselementpre = iselementpre("//li[@class = 'seat avail']/child::a[@title = '"+element[i]+"']");
            if(iselementpre == true) {
                Thread.sleep(4000);
                try {
                    WebElement seat = driver.findElement(By.xpath("//li[@class = 'seat avail']/child::a[@title = '"+element[i]+"']"));
                    JavascriptExecutor js = (JavascriptExecutor)driver;
                    js.executeScript("arguments[0].click();", seat);    
                }catch(Exception e) {
                    System.out.println(e);
                }
                test.pass("seat layout has been selected");
                Thread.sleep(4000);
                
                System.out.println("seat clicked"+element[i]+iselementpre);
                
            }
        }
        return false;
        
    }
    
//  @Test(priority = 6)
//  public void seat_selection() throws InterruptedException {
//      try {
//          PageFactory.initElements(driver, seatLayout.class);
//          js.executeScript("window.scrollBy(0, 100)", "");
//          Thread.sleep(2000);
//          test = reports.createTest("Seat Layout Test", "This is the test to validate the seatlayout");
//          test.log(Status.INFO, "Starting the test case");
//          
//          String element[] = {"A1", "A2", "A3", "A4", "A4", "A5", "A6", "A7"};
//          for(String seatnumber : element) {
//              WebElement seat = driver.findElement(By.xpath("//a[@title='"+seatnumber+"']"));
//              
//                  wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@title='"+seatnumber+"']")));
//                  seat.click();   
//          }
//      }catch (InterruptedException e) {
//              e.printStackTrace();
//              e.getCause();
//              e.getMessage();
//          }
//          finally {
//              seat_selection();
//          }
//                  }
//  
        
        
    


//      @Test(priority = 6, dataProvider = "seatlayout", dataProviderClass = seatlayoutprovoder.class)
//      public void seat_layout_selection(String Seatnumber) throws InterruptedException {
//          PageFactory.initElements(driver, seatLayout.class);
//          js.executeScript("window.scrollBy(0, 50)", "");
//          Thread.sleep(2000);
//          test = reports.createTest("Seat Layout Test", "This is the test to validate the seatlayout");
//          test.log(Status.INFO, "Starting the test case");
//          WebElement seat = driver.findElement(By.xpath("//a[@title='"+Seatnumber+"']"));
//          seat.click();
//  if(seat.isDisplayed()&& seat.isEnabled()) {
//  
//  test.pass("seat has been selected");
//  }else {
//  test.pass("selecting another seat");
//  seat_layout_selection(Seatnumber);
//  
//          }
//          Thread.sleep(2000);
//          seatLayout.continue_button_at_seatlayout.click();
//          test.pass("seat layout completed successfully");
//          Thread.sleep(5000);
//      }

    @Test(priority = 7)
    public void fnb() throws InterruptedException {

        PageFactory.initElements(driver, fnbmainpage.class);
        test = reports.createTest("FNB Page Test", "This is the test to vaidate the FNB page");
        test.log(Status.INFO, "starting the test case");
        fnbmainpage.continue_button_at_fnb.click();
        test.pass("FNB page completed successfully");
        Thread.sleep(5000);


    }

    @Test(priority = 8)
    public void confirm_purchase_guestuser_details() throws InterruptedException {

        PageFactory.initElements(driver, purchaseconfirmation.class);
        test = reports.createTest("Guest User details Test", "This is the test to validate the guest user details");
        test.log(Status.INFO, "starting the test case");
        purchaseconfirmation.first_name.sendKeys("Test");
        purchaseconfirmation.last_name.sendKeys("QA");
        purchaseconfirmation.mobile_number.sendKeys("9791075150");
        Thread.sleep(2000);
        js.executeScript("window.scrollBy(0, 100)", "");
        purchaseconfirmation.email_id.sendKeys("[email protected]");
        purchaseconfirmation.guest_details_confirm_continue.click();
        test.pass("guest user details are entered successfully");

    }

    @Test(priority = 9)
    public void confirm_purchase_card_details() throws InterruptedException {

        test = reports.createTest("card details test", "This is the test to validate the card details in the confirm purchase page");
        test.log(Status.INFO, "starting the test case");
        PageFactory.initElements(driver, purchaseconfirmation.class);
        Thread.sleep(3000);
        js.executeScript("window.scrollBy(0, 200)", "");
        Thread.sleep(2000);
        purchaseconfirmation.cardradiobutton.click();
        Thread.sleep(4000);
        js.executeScript("window.scrollBy(0, 300)", "");
        Thread.sleep(3000);
        purchaseconfirmation.card_number.sendKeys("4111111111111111");
        purchaseconfirmation.card_expiry.sendKeys("0929");
        purchaseconfirmation.card_holder.sendKeys("Test Card");
        purchaseconfirmation.cvv.sendKeys("123");
        js.executeScript("window.scrollBy(0,150)", "");
        Thread.sleep(2000);
        purchaseconfirmation.pay_now_button.click();
        test.pass("card details are enteres successfully");
        Thread.sleep(5000); 
    }

    @Test(priority = 10)
    public void external_payment_page() throws InterruptedException {
        test = reports.createTest("external payment page test", "This is the test to validate the external payment page");
        test.log(Status.INFO, "starting the test case");
        PageFactory.initElements(driver, paymentPage.class);
        paymentPage.Pay_button.click(); 
        Thread.sleep(8000);
        test.pass("external page has been completed successfully");
    }

    @Test(priority = 11)
    public void successfull_booking() throws InterruptedException {
        PageFactory.initElements(driver, successfullBooking.class);
        message = successfullBooking.booking_message.getText();
        js.executeScript("window.scrollBy(0, 250)", "");
        Thread.sleep(2000);
        Id = successfullBooking.booking_ID.getText();
        org.testng.Assert.assertEquals(message, "Your ticket booking was successful!");
        test.pass("booking done successfully");
        Thread.sleep(3000); 
    }


    @AfterTest
    public void teardown() {
        reports.flush();
        driver.close();
    }
}

直到优先级 5 为止,它都可以正确执行,但是在优先级 5 之后,脚本失败并停止运行,控制台没有该特定测试

我总共运行了 11 个测试,但在控制台中它显示为 10 个测试

由于我是硒的新手,请帮助我解决方案

selenium-webdriver testng selenium-java
1个回答
0
投票

“seatclick”方法(测试#6)未运行的原因可能是由于测试方法签名。

默认情况下(遵循最佳实践)TestNG 测试方法不应返回任何内容,即它们应该具有返回类型 - void。

如果您确实需要通过测试方法返回某些内容,则需要将“allow-return-values”属性添加到您的套件 XML 中。
如果没有此属性,您的测试将被跳过,并且下一个测试(第 7 个)将失败,因为它很可能取决于上一个测试(第 6 个)。

© www.soinside.com 2019 - 2024. All rights reserved.