简体   繁体   中英

Cannot access static method when running thru main method from command line

I have aa method that is being called from Main but when the time comes to call the static method within it will not proceed and test stops.

I have inserted log comments in order to tell where the problem is and no exceptions are caught so there is no compiling nor runtime errors so far.

The static method that is not being called is GC2CommonMethods.loadApplication(); . The weird thing is that when running Main from Eclipse IDE it runs perfectly but it does not when executing from jar file through the same Main method.

See below both codes from the method that is being executed and the detail of the static method that is within a static class respectively.

I would appreciate your help with this. Thanks.

//This method is intented to be called from Main method 

package com.mycompany.test.loginRoleEntitlements; 
public void verifyLoginPageElements() {
   logger.info("\t1.0/1.0.2 - Verif**strong text**ying Login page elements...");
     try {
         logger.info("entering Try");

         GC2CommonMethods.loadApplication(sl);    //Static method from Static class. 
         assertTrue("Region identifier is not present.", sl.isElementPresent(PageAttributes.LoginPage.DB_LABEL));
         assertTrue("Forgot Password link is not present", sl.isElementPresent(PageAttributes.LoginPage.FORGOT_PASSWORD));

     } catch (SeleniumException se) {
           logger.info("caught SeleniumException");
           logger.error(se.getMessage());
       throw se;
     } catch (AssertionFailedError ae) {
       logger.info("caught AssertionException");
       logger.error(ae.getMessage());
       throw ae;
     } catch (Exception e) {
       logger.info("caught Exception");
       logger.info("Encountered exception");
        e.printStackTrace();
    }

  //This is the static method that is within GC2CommonMethods static class
  package com.mycompay.common;

  public static void loadApplication(SeleniumHandle sl) {   

    sl.open(props.getProperty("APPLICATION_URL"));
    sl.waitForPageToLoad("30000");
    assertEquals("The page is not the correct one.
   |Expected: "+PageAttributes.LoginPage.LOGINPAGE_TITLE + ".
   Found:"+sl.getTitle(),PageAttributes.LoginPage.LOGINPAGE_TITLE,sl.getTitle());
  }

I found the solution. The problem was on the main method when trying to read a properties file. There was an uncaught exception which was not being logged so I was not able tell where the problem was. Thanks for your replies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM