如何使用不同的测试用例同硒会议?(How to use the same selenium sess

2019-10-17 07:20发布

我使用JUnit和硒。 我想一次登录到网页,运行后我运行两个测试用例,而无需打开一个新的浏览器/会话。 如果我做了“注册”的setUp()方法,那么这个所谓的测试用例之前每次。 我怎么可以只用一个setUp()方法对我所有的测试用例?

Answer 1:

我认为它可以通过以下方式来实现

package com.java;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class TestAnnt {

    public static Selenium sel;

    @BeforeClass
    public static void beforeClass() {
        sel = new DefaultSelenium("localhost", 5555, "*firefox",
                "http://www.google.com");
        sel.start();
        System.out.println("Before Class");
    }

    @Before
    public void beforeTest() {

        System.out.println("Before Test");

        // Actions before a test case is executed
    }

    @Test
    public void testone() {
        sel.open("/");
        sel.waitForPageToLoad("30000");
        System.out.println("Test one");
        // Actions of test case 1
    }

    @Test
    public void testtwo() {
        sel.open("http://au.yahoo.com");
        sel.waitForPageToLoad("30000");
        System.out.println("test two");
        // Actions of test case 2
    }

    @After
    public void afterTest() {
        System.out.println("after test");
        // Actions after a test case is executed
    }

    @AfterClass
    public static void afterClass() {
        sel.close();
        sel.stop();
        sel.shutDownSeleniumServer();
        System.out.println("After Class");
    }

}


文章来源: How to use the same selenium session with different test cases?