3

When i run gradle build, it fails with the error below:

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

below is the image of my gradle.build file:

build file

project structure below: project structure

I keep getting errors when i run gradle build or gradle clean build. Please any help will be much appreciated... I really need to get the index.html file working before i can demo my project to the team.

index.html file stacktrace:its same error for all index.html

UPDATED CODE REQUESTED......

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();
    }

result of build command

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

New output below output explained output screenshot

Joe
  • 147
  • 1
  • 4
  • 17
  • by just looking at it I think your test are failing try to do a gradle clean built with *-x test* just to ignore the test and see if it builds if the built is fine then you must be missing some dependency for tests. – Grinish Nepal Apr 25 '16 at 16:55
  • can you please explain further, i dont get you. Firstly, is my gradle.build file OK?, why do i have issues about static mthods?.. tanx – Joe Apr 25 '16 at 17:04
  • @dpr can view this please – Joe Apr 25 '16 at 17:19
  • 1
    what I am trying to say is try this command *gradle clean build -x test * if this works then it would be nice to see the code that you are testing and what have you written to test it. gradle seems OK to me. – Grinish Nepal Apr 25 '16 at 17:20
  • tanx , i just ran the command and the BUILD was successful. Have also updated my code. please review... tanx – Joe Apr 25 '16 at 17:28
  • @Grinish Have done as requested, can you please review my code for me please, .. the stack trace in the index.html complains about static method.. Tanx you so much in advance – Joe Apr 25 '16 at 17:40
  • Not sure what is happening with your test but you are getting error for the method testVerifyPrivacyMethod() which i cant see anywhere. Reading these might help. http://stackoverflow.com/questions/21413174/junit-crashes-saying-method-should-be-static-then-crashes-saying-it-shouldnt http://stackoverflow.com/questions/1052577/why-must-junits-fixturesetup-be-static – Grinish Nepal Apr 25 '16 at 18:57
  • ... Have read that link earlier and it was no good. its same error for all the class. i have the testVerifyPrivacyMethod in my code. its just that my code is too vague and cant post it all. but its same error message displayed. dont know why its complaining about the static method. are mt JUNIT annotations Ok tho?. i mean the @Before. – Joe Apr 25 '16 at 19:07
  • 1
    @Joe why are you actually using the seperate `selenium` source set in your gradle file and the `seleniumCompile` configuration and not just the `testCompile` configuration that comes with the Java plugin? And what is the reason to apply the application plugin to the project? From what I have seen so far this is simply not needed as you are only using it to execute the tests in some weird way... – dpr Apr 26 '16 at 07:46

1 Answers1

3

The error is actually in your stack trace already:

Method testVerifyPrivacyStatement() should not be static

That is your test methods should have the following signature:

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

Furthermore the @Before and @After methods must not be static as well and you don't need to call the @After methods manually. These methods are invoked by JUnit before and after each test method. You should seriously read some JUnit tutorials and the Javadoc of the different annotations!!!

@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
}

And last but definitively not least. The main-method is of absolutely no meaning for a JUnit test. You can keep it, if you want to execute your tests in a standalone way, but I'd rather remove it. If you want to keep it, you need to remove the @Before annotation from the method and you need to execute the tests through JUnit programatically in order for the annotations to work properly.


TLDNR:

  • Remove all the static modifiers in your test class
  • Remove the main method from your test class. If there is some initialization that is needed for the test execution, put it in the setup() method. But from what I can see, there is nothing in there that is actually needed...
  • Remove the manual calls to tearDown()
  • Read some basic tutorials on Java code structure (Oracle Lesson on Packages) and JUnit (JUnit Basic Usage)
dpr
  • 10,591
  • 3
  • 41
  • 71
  • Tank a mill for your help. Appreciate. Will do as advised as regards the tutorials. so far so good, all looks well now but only need to figure out why only one test runs when i call the gradle build. No results in reports because it says 0 Test but there is a log of the test run in the classes folder. ... Tanx so much once again :) – Joe Apr 28 '16 at 09:45
  • @Joe, you're welcome. Gaining some reputation though ;-) Did you make sure all of your test methods are properly annotated with `@Test`? – dpr Apr 28 '16 at 09:49
  • Yes. let me put it in a zip file and will attach it here if i can, that will give you a through view of what i have done so far. :) Here is a link to the project. it will give you a better overview... [projectLink](http://www.filehosting.org/file/details/565307/IndoAutomation_GradleProject.7z) Tanx once again – Joe Apr 28 '16 at 10:21
  • I don't know what your doing wrong. If execute `gradle build` on your project all tests (32 in total) are executed. However they are all failing due to a missing chrome driver `java.lang.IllegalStateException: The driver executable does not exist: C:\home\ola\chromedriver`. All I did was to add a `gradle.properties` file in to project root containing the location of my java installation (`org.gradle.java.home=c:\PathToJava`)... – dpr Apr 28 '16 at 10:43
  • The gradle build is not failing tho, but outputs what have added in the image above . don't know if this is right or wrong. pls check added image – Joe Apr 28 '16 at 11:06
  • http://s32.postimg.org/fstugkid1/2016_04_28_13h13_58.png That's the result of my build on your project... – dpr Apr 28 '16 at 11:15
  • Now this is becoming so crazy ... :))) This is totally different from my result. don't know what else to do. I was getting this result ONLY when i had my test methods static, after removing the static from my test class, my build was successful but what i dont understand is why is it only picking the 7th test when i run gradle build..... Ok what command do i need to run my test? maybe that is where am wrong...... – Joe Apr 28 '16 at 11:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/110505/discussion-between-dpr-and-joe). – dpr Apr 28 '16 at 11:26
  • I Finally figured it out... You won't believe the silly mistake i did. OMG !!! its so hilarious ... In my close() i had system.exit(0) instaed of driver.close(). So the process will always end after every first test run. Its working perfectly now..... Am so so silly, laughing hard here right now. OMG !!! . ThumbsUp to dpr He his a genius. – Joe Apr 29 '16 at 11:33
  • @Joe good to read you were able to solve the remaining issue your self. – dpr May 01 '16 at 07:19