Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
117 views
in Technique[技术] by (71.8m points)

java - Only Before method code is executed for RemoteWebdriver and @Test method is skipped

*Please check my below code for executing selenium grid. here only before method code is only executed and @Test method name after that execution terminated and browser closed. Get this msg on node console "06:52:20.813 INFO [ActiveSessions$1.onStop] - Removing session 05fc2104cf4026a03f06e8bb1919a1fd (org.openqa.selenium.chrome.ChromeDriverService)" I have created a SeleniumSrver folder in C drive and it contains selenium standalone server jar and chromedriver.exe. using this i am starting Hub and Node. Both machines hub and node contains this folder. While i am executing it browser is launched, login to the app after that it does not execute @Test method code and browser closed on Node machine.... Please help...

TESTNG.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="ParallelConfig1">
    <listeners>
        <listener class-name="com.ephesoft.automation.utils.Listeners.TestListener"/>
        <listener class-name="com.ephesoft.automation.utils.Listeners.AnnotationTransformer"/>
  </listeners>
    <parameter name="config" value="gridConfig1.conf.json" />
    <parameter name="browser" value="chrome" />
    <test name="Regression_01">
        <classes>   
            <class name="com.ephesoft.automation.regression.test.DBExportTest" />
            <class name="com.ephesoft.automation.regression.test.FuzzyDBExtractTest" />
            <class name="com.ephesoft.automation.regression.test.VerifyFuzzyDBConfigurationTest" />
            <class name="com.ephesoft.automation.regression.test.AdvancedBarCodeExtractionTest" />
            <class name="com.ephesoft.automation.regression.test.BIMValidateSreenTest" />
            <class name="com.ephesoft.automation.regression.test.BCMTest" />    
            <class name="com.ephesoft.automation.regression.test.FolderManagementTest" />   
                                         
        </classes>
    </test>
</suite>





public class TestBaseClass extends EnvData {

    Logger logger = Logger.getLogger(TestBaseClass.class);

    public WebDriver driver;
    public WebDriverWait wait;
    public Pages page;

    public static final String HOME = System.getProperty("user.dir");
    public static final long TimeStamp = System.currentTimeMillis();
    public static String DROP_LOCATION;

    private Local local;
    private JSONParser parser;
    private static String testCaseName;
    public static int defaultImplicitWaitTime;
    private String bsSessionInfoUrl;
    private String bsSessionID;
    private String reason;

    private String status;

    @BeforeMethod
    public void beforeMethod(Method method) throws Exception {
        /*
         * Get the executed test method name
         */
        Test test = method.getAnnotation(Test.class);
        testCaseName = test.description();
        ExtentTestManager.startTest(method.getName(), testCaseName);
        logger.info("Method Starts " + StringUtils.repeat("-", 60));
        logger.info("Method Starts ----------: " + testCaseName);
        logger.info("Method Starts " + StringUtils.repeat("-", 60));

    }





    /**
     * Setup method for test cases.
     * 
     * @param configFile
     * @param environment
     * @param runBrowserStack
     * @throws Exception
     */
    @BeforeMethod
    @Parameters(value = { "config", "browser", "runBrowserStack" })
    public void setUp(@Optional String configFile, @Optional String browser, boolean runBrowserStack) 
        throws Exception {
        logger.info("configFile=" + configFile + ", browser=" + browser + ", runBrowserStack=" + 
        runBrowserStack);

        defaultImplicitWaitTime = Integer.valueOf(EnvData.getValue("DRIVER_IMPLICIT_WAIT"));

        if (runBrowserStack) {
            setUpBrowserStack(configFile, browser);
        } else {
            setUpLocalQa(configFile, browser, runBrowserStack);
            TestScreenRecorder.startRecording(testCaseName);
            logger.info("Recording Starts");

        }
    }





    /**
     * Setup method for test cases.
     * 
     * @param configFile
     * @param environment
     * @param runBrowserStack
     * @throws Exception
     */
    @BeforeMethod
    @Parameters(value = { "config", "browser"})
    public void setUp(@Optional String configFile, @Optional String browser) throws Exception {
        logger.info("configFile=" + configFile + ", browser=" + browser + ", grid=" + "");
        defaultImplicitWaitTime = Integer.valueOf(EnvData.getValue("DRIVER_IMPLICIT_WAIT"));
        setUpGrid(configFile, browser);

    }





    /**
     * TestCase setup for Grid.
     * @Author PRASHANT MISHRA
     * @param config_file
     * @param browser
     * @throws Exception
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    private void setUpGrid(String config_file, String browser) throws Exception {

        //  Read Configuration file

        JSONParser parser = new JSONParser();
        JSONObject config = (JSONObject) parser.parse(new FileReader("src/test/resources/conf/" + 
        config_file));
        JSONObject envs = (JSONObject) config.get("environments");

        DesiredCapabilities capabilities = new DesiredCapabilities();

        //  Read Environment capabilities

        Map<String, String> envCapabilities = (Map<String, String>) envs.get(browser);
        Iterator it = envCapabilities.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pair = (Map.Entry) it.next();
            capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString());
        }
        //  URL from env

        String url = EnvData.getValue("URL");

        capabilities.setCapability("resolution", "1920x1080");

        capabilities.setCapability("name", testCaseName);

        capabilities.setCapability("browserName", browser);
        capabilities.setCapability("OS", Platform.WIN10);

        ChromeOptions option = new ChromeOptions();
        option.merge(capabilities);

        // Generate Remote WebDriver

        driver = new RemoteWebDriver(
                new URL("http://172.31.30.116:4444/wd/hub"), option);

        logger.info("Connected to Grid...");

        //((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());

        //bsSessionID = ((RemoteWebDriver) driver).getSessionId().toString();

        //bsSessionInfoUrl = "https://" + username + ":" + accessKey + 
        "@api.browserstack.com/automate/sessions/"
        //  + bsSessionID;

        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(defaultImplicitWaitTime, TimeUnit.SECONDS);

        page = new Pages(driver);
        logger.info(url);

        driver.get(url);


        // Get Login page object and do login using userName/password

        page.getPageObject(LoginPage.class).loginToHome(EnvData.getValue("EP_USERNAME"),
                EnvData.getValue("EP_PASSWORD"));
        DROP_LOCATION = TestUtility.setDropLocation(driver);
        
    }

    
question from:https://stackoverflow.com/questions/65933111/only-before-method-code-is-executed-for-remotewebdriver-and-test-method-is-skip

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...