运行Gradle构建时出现错误

3
当我运行 gradle build 命令时,会出现以下错误:
ola@ola-VirtualBox:~$ cd workspace/sample/
ola@ola-VirtualBox:~/workspace/sample$ gradle build
:compileJava
:processResources
:classes
:jar
:startScripts
:distTar
:distZip
:assemble
:compileTestJava
:processTestResources
:testClasses
:test

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

org.gradle.AllMethodsTest > initializationError FAILED
    java.lang.Exception

39 tests completed, 39 failed
:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///home/ola/workspace/sample/build/reports/tests/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 11.356 secs

以下是我的gradle.build文件的图像:

build file

以下是项目结构: 项目结构

当我运行gradle build或gradle clean build时,我一直收到错误提示。任何帮助都将不胜感激...在向团队演示我的项目之前,我真的需要让index.html文件正常工作。

index.html文件堆栈跟踪:所有都是相同的错误 index.html

请求更新的代码......

package main.java.Functional;

import static org.junit.Assert.assertTrue;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import main.java.Functional.AllMethodsTestcases.performAction;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


/**
 * This class is used for testing all the indo functionalities.
 * 
 * @author Ola
 */
public class AllMethodsTest {

    /**
     * Variables to set up driver and browser.
     */
    public static AllMethods callMethod;
    public static WebDriver driver;
    public static String ID;
    public static String filePath = "C:\\Users\\Ola\\workspace\\Config.properties";

    /**
     * Setup method to run chrome browser
     * @param args
     * @throws Exception
     */
    @Before
    public static void setup(String[] args) throws Exception {
        callMethod = new AllMethods();
        callMethod.setup();
        callMethod.driver.get("http://independent.ie");
        // Maximize browser window
        callMethod.driver.manage().window().maximize();
        // store current url in a string
        String site = callMethod.driver.getCurrentUrl();
        // print out the URL in the console
        System.out.println("The current Url IS: " + site);
        // Get the OS on which the driver is running.......
        String detectOS = log.DetectOS();
        log.log(detectOS);
        Thread.sleep(7000);
    }

    /**
     * Main Method to start the browser and run all necessary testcases.     * 
     * @param args
     * @throws Exception
     */
    @Before
    public static void main(String[] args) throws Exception {

        // specify the Test to Run.........
        performAction tc = performAction.acct_Profile;
        try {
            setup(args);

        } catch (Exception e) {
            log.log("Error while setting up the driver.");
        }

        try {

            switch (tc) {
            case testMouseOverJobs:
                testVerifyJobsLink();
                break;
            case testMouseOverCars:
                testVerifyCarsLink();
                break;
            case testMouseOverDating:
                testVerifyDatingLink();
                break;
            case testMouseOverDeath:
                testVerifyDeathNoticesLink();
                break;
            case testMouseOverFitMag:
                testVerifyFitMagLink();
                break;
            case testMouseOverHotels:
                testVerifyHotelsLink();
                break;
            case click_subscribe:
                testVerifySubscribeLink();
                break;
            case click_SignInNative:
                testVerifySignIn_Native();
                break;
            case click_SignUpNative:
                testVerifySignUp_Native();
                break;
            case searchUser:
                testVerifySearchUser();
                break;
            case deleteUser:
                testVerifyDeleteUser();
                break;
            case click_SignInFB:
                testVerifySignInFB();
                break;
            case click_SignInFB_EditInfo:
                testVerifySignInFB_EditInfo();
                break;
            case click_SignInGoogle:
                testVerifySignInGoogle();
                break;
            case click_MyAcct_SS:
                testVerifyClick_MyAcctPage_forS_S_user();
                break;
            case click_MyAcct:
                testVerifyClick_MyAcct();
                break;
            case acct_Profile:
                testVerifyAcct_ProfileUpdated();
                break;
            case acct_Password:
                testVerifyAcct_PasswordChange();
                break;
            case acct_SocialAccts_FB:
                testVerifyAcct_SocialLink_FB();
                break;
            case acct_SocialAccts_Google:
                testVerifyAcct_SocialLink_Google();
                break;
                }
        } catch (Exception e) {
            log.log("There was an Exception while running the test: "
                    + e.getMessage());
        }
        tearDown();
    }



    /**
     * "C:\\Users\\Ola\\workspace\\Config.properties"
     * @throws Exception
     */
    @Test
    private static void testVerifyFileExist() throws Exception {
        boolean verify =callMethod.FileExist();
        if(verify)
        {
            log.log("File does exist");
        }else
        {
            log.log("File does not exist, .....");
        }
        tearDown();
    }

    @Test
    private static void testVerifyloadConfig_File() throws Exception {
        log.divider("Load Config file path specified");
        String response =callMethod.parseConf_File("NATIVE_PASSWORD");
        log.log(response);
        tearDown();
    }

    /**
     * Verifies JOB link on home page
     * @throws Exception
     * @author Ola
     */
    @Test
    public static void testVerifyJobsLink() throws Exception {
        log.header("....... Verify JOBS Link.........");
        callMethod.hoverAndClickOnce(By.cssSelector(AllMethodsCONSTANTElements.JOBS),
                By.cssSelector(AllMethodsCONSTANTElements.IRISHJOBS), "JOBS", "JOBS");
        tearDown();
    }
    /**
     * Verifies CARS link on home page
     * @throws Exception
     * @author Ola
     */
    @Test
    public static void testVerifyCarsLink() throws Exception {
        log.header("....... Verify CARS Link.........");
        String[] elementNames = new String[] { AllMethodsCONSTANTElements.CARSIRELAND,
                AllMethodsCONSTANTElements.USED_CARS_SEARCH, AllMethodsCONSTANTElements.CAR_DEALERS };
        for (String elementName : elementNames) {
            log.divider("1st Element ......'CarsIreland.ie'.....");
            if (callMethod.elementPresent(By.cssSelector(elementName),
                    "CARS_IRELAND")) {
                callMethod.hoverAndClickMultiple(
                        By.cssSelector(AllMethodsCONSTANTElements.CARS),
                        By.cssSelector(AllMethodsCONSTANTElements.CARSIRELAND), "CARS",
                        "CarsIreland.ie");
                Thread.sleep(3000);
                log.header2("");
            }
            log.divider("2nd Element .......'Used Car Search.....'");
            log.step("");
            if (callMethod.elementPresent(By.cssSelector(elementName),
                    "USED CAR SEARCH")) {
                log.log("Open Used Car Search link.....");
                callMethod.hoverAndClickMultiple(
                        By.cssSelector(AllMethodsCONSTANTElements.CARS),
                        By.cssSelector(AllMethodsCONSTANTElements.USED_CARS_SEARCH),
                        "CARS", "USED CAR SEARCH");
                Thread.sleep(3000);
                log.header2("");
            }
            log.divider("3rd Element .......'Car Dealers'..........");
            log.step("");
            if (callMethod.elementPresent(By.cssSelector(elementName),
                    "CAR DEALERS")) {
                log.log("Open Cars Dealers Link........");
                callMethod.hoverAndClickMultiple(
                        By.cssSelector(AllMethodsCONSTANTElements.CARS),
                        By.cssSelector(AllMethodsCONSTANTElements.CAR_DEALERS), "CARS",
                        "CAR DEALERS");
                break;
            }
        }
        tearDown();
    }
    /**
     *  Verifies my profile updated NATIVELY
     * @throws Exception
     * @author Ola
     */
    @Test
    public static void testVerifyAcct_ProfileUpdated() throws Exception {
        log.header("........ Verify MY ACCOUNT PROFILE section ........");
        String finalResponse = callMethod.profileSection(
                callMethod.parseConf_File("EMAIL_ADDRESS"),
                callMethod.parseConf_File("NATIVE_PASSWORD"), 
                callMethod.parseConf_File("DISPLAY_NAME"),
                callMethod.parseConf_File("FIRST_NAME"),
                callMethod.parseConf_File("LAST_NAME"),
                callMethod.parseConf_File("ADDRESS_1"),
                callMethod.parseConf_File("ADDRESS_2"),
                callMethod.parseConf_File("CITY"),
                callMethod.parseConf_File("COUNTRY"),
                callMethod.parseConf_File("COUNTRY_2"),
                callMethod.parseConf_File("COUNTY"),
                callMethod.parseConf_File("COUNTY_2"),
                callMethod.parseConf_File("POSTCODE"),
                callMethod.parseConf_File("TELEPHONE"));

        if (finalResponse.contains("DOES NOT Exist")) {
            log.log("User DOES NOT Exist in Database.... You will have to Sign Up.");

        } else if (finalResponse.contains("FACEBOOK")) {
            log.log("User Exist in Database with FACEBOOK Social Account and "
                    + "Cannot Sign Up Natively......Open My Acct process terminated!........");
        } else if (finalResponse.contains("GOOGLE")) {
            log.log("User Exist in Database with GOOGLE Social Account and "
                    + "Cannot Sign Up Natively......Open My Acct process terminated!........");
        }else if (finalResponse.contains("STILL DOES NOT EXIS")){
            log.log("CANNOT continue process as COUNTRY or COUNTY specified STILL DO NOT exist on list, ..pls contact Customer support");
        }else if (finalResponse.contains("Disabled state")) {
            log.log("Button is in Disabled state.....Profile was "
                    + "NOT updated as NO Update was made.....");
        } else if (finalResponse.contains("Successfully")) {
            log.log("Profile was Successfully updated");
        } else if (finalResponse.contains("NOT updated")) {
            log.log("Profile was NOT updated.... pls contact Gigya customer service......");
        } else if (finalResponse.contains("MY ACCOUNT page")) {
            log.log("MY ACCOUNT page Successfully Opened and updated as expected.......");
        }
        tearDown();
    }

    @After
    public static void tearDown(){
        callMethod.close();
    }

构建命令的结果
ola@ola-VirtualBox:~/workspace/sample$ gradle clean build -x test
:clean
:compileJava
:processResources
:classes
:jar
:startScripts
:distTar
:distZip
:assemble
:check
:build

BUILD SUCCESSFUL

Total time: 8.445 secs

以下是新的输出 解释的输出 截图的输出


仅凭外观,我认为您的测试失败了。尝试使用 -x test 进行 gradle clean built,以忽略测试并查看是否构建成功。如果构建成功,则必须缺少一些测试依赖项。 - Grinish Nepal
1
我想说的是尝试一下这个命令 gradle clean build -x test,如果可以正常工作的话,那么很高兴能看到你正在测试的代码以及你编写的测试内容。对我来说,Gradle看起来还不错。 - Grinish Nepal
谢谢,我刚刚运行了命令,构建成功了。我也更新了我的代码,请审核一下... 谢谢 - Joe
不确定您的测试出了什么问题,但是您在testVerifyPrivacyMethod()方法中遇到了错误,而我无法找到该方法。阅读以下内容可能会有所帮助。https://dev59.com/-Xvaa4cB1Zd3GeqPIdhuhttps://dev59.com/unNA5IYBdhLWcg3wNa6T - Grinish Nepal
1
@Joe,你为什么在gradle文件中使用单独的selenium源集和seleniumCompile配置,而不只是使用Java插件提供的testCompile配置?另外,为什么要将应用程序插件应用于该项目呢?从我目前所见,这是不必要的,因为你只是以某种奇怪的方式执行测试。 - dpr
显示剩余4条评论
1个回答

3

错误实际上已经在您的堆栈跟踪中了:

方法testVerifyPrivacyStatement()不应该是静态的

也就是说,您的测试方法应该具有以下签名:

@Test
public void testWhatEverYouThingNeedsToBeTested() throws Exception {
    // Put you test code here
}

此外,@Before@After方法也不能是静态的,你不需要手动调用@After方法。这些方法会在每个测试方法之前和之后由JUnit调用。你应该认真阅读一些JUnit教程以及不同注释的Javadoc!!!
@Before
public void setup() throws Exception {
    // This method will be called by JUnit _before_ execution of each test
    // Do whatever is needed to initialize the runtime environment for your tests
}

@After
public void tearDown() throws Exception {
    // This method will be called by JUnit _after_ execution of each test
    // Free resources allocated during the initialization or the tests themselves
}

最后但绝对不是最不重要的,main方法对于JUnit测试来说毫无意义。如果您想以独立方式执行测试,可以保留它,但我更愿意删除它。如果您想保留它,需要从该方法中删除@Before注释,并且需要通过JUnit程序化地执行测试,以便注释正常工作。


TLDNR:

  • 移除测试类中的所有静态修饰符
  • 从测试类中移除main方法。如果有一些需要在测试执行之前初始化的内容,请将其放入setup()方法中。但是从我所看到的情况来看,实际上没有什么东西是必需的...
  • 移除手动调用tearDown()
  • 阅读一些关于Java代码结构(Oracle Lesson on Packages)和JUnit(JUnit Basic Usage)的基础教程

感谢您的帮助,真是太感激了。我会按照建议去学习教程的。目前为止一切看起来都很好,但我需要找出调用gradle构建时为什么只运行一个测试的原因。由于报告中显示“0个测试”,所以没有任何结果,但测试运行日志已存储在“classes”文件夹中。再次非常感谢您的帮助 :) - Joe
@Joe,不用谢。虽然你的声望有所提高;-)你确定所有的测试方法都正确地注释了@Test吗? - dpr
好的,让我把它打包成一个zip文件并附在这里,如果可以的话,这将为您提供我迄今为止所做的完整视图。 :) 这是项目的链接。它会给你一个更好的概述... projectLink 再次感谢 - Joe
我不知道你做错了什么。如果在你的项目上执行 gradle build,所有测试(共32个)都会被执行。但是由于缺少chrome驱动程序,它们全部失败了:java.lang.IllegalStateException: The driver executable does not exist: C:\home\ola\chromedriver。我所做的就是在项目根目录中添加一个 gradle.properties 文件,其中包含我的Java安装位置 (org.gradle.java.home=c:\PathToJava) 的信息... - dpr
让我们在聊天中继续这个讨论。 - dpr
显示剩余5条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接