เพิ่งเริ่มทดลองกับ Selenium 2.18 เหตุใด Selenium จึงสร้างอินสแตนซ์ใหม่ของ "การควบคุมระยะไกล" ระหว่างแต่ละรายการทดสอบ JUnit
ฉันสร้างการทดสอบหน่วยที่เรียกว่า testA, testB, testC และนี่คือสิ่งที่เกิดขึ้น:
setUp:
0. Create static instance of DefaultSelenium
testA:
1. Selenium starts instance of "Remote Control"
2. Selenium starts web browser an opens app
testB:
3. Selenium starts new instance of "Remote Control"
4. Selenium kills first instance of "Remote Control"
5. Script sends existing browser to a URL on the local system (probably
a temp file of some kind)
ดังนั้นคำถามของฉันคือเหตุใดฉันจึงไม่สามารถให้ Selenium มีอินสแตนซ์คงที่ของ "รีโมทคอนโทรล" เพียงอินสแตนซ์เดียวและยังมีอินสแตนซ์คงที่ของเว็บเบราว์เซอร์หนึ่งรายการตลอดทั้ง testA, testB และ testC
หมายเหตุ: ขั้นตอนที่ # 5 เกี่ยวข้องกับฉัน: หากขั้นตอนนั้นไม่เปลี่ยนเส้นทางไปยังไฟล์ในเครื่อง อาจเป็นไปได้ว่ารีโมทคอนโทรลในขั้นตอน # 4 อาจพบเนื้อหาในหน้านั้น สิ่งนี้เกิดขึ้นเพราะอินสแตนซ์ใหม่ของ "รีโมทคอนโทรล" ไม่ทราบเกี่ยวกับการมีอยู่ของเบราว์เซอร์ที่เริ่มต้นจากอินสแตนซ์แรกของ "รีโมทคอนโทรล" หรือไม่
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
@RunWith(Suite.class)
@SuiteClasses({ Tests.class })
public class AllTests {
static SeleniumServer seleniumserver;
@BeforeClass
public static void setUpClass() throws Exception {
RemoteControlConfiguration settings = new RemoteControlConfiguration();
settings.setTrustAllSSLCertificates(true);
seleniumserver=new SeleniumServer(settings);
seleniumserver.boot();
seleniumserver.start();
System.out.println("Finished suite setUpClass");
}
...
และสำหรับลูกค้าของฉัน:
public class Tests extends SeleneseTestBase {
private static DefaultSelenium selenium;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:8181/");
selenium.start();
}
public void testA() { System.out.println("TestA"); }
public void testB() { System.out.println("TestB"); }
public void testC() { System.out.println("TestC"); }