有人可以帮忙吗,我在eclipse上设置了一个maven项目,每次运行测试时,它在chrome上运行良好,但我在junit控制台上收到以下错误:
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '4.0.0-alpha-3', revision: '8c567de6dc'
System info: host: '04081W10', ip: '10.50.47.210', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:128)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:576)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:327)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:375)
at org.openqa.selenium.By$ById.findElement(By.java:196)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:319)
at Scenarios.NormanNrasProject.InternalNameReserve1YearTest.InternalNameReserve90DaysTest(InternalNameReserve1YearTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
这是我的代码:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\nrapoo\\Desktop\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait wait=new WebDriverWait(driver, 20);
driver.get("http://cedd-wb/enter.htm");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys("seden");
driver.findElement(By.xpath("//*[@id=\"pword\"]")).sendKeys("hello1");
driver.findElement(By.xpath("//*[@id=\"login_form\"]/div[3]/button")).click();
driver.findElement(By.xpath("//*[@id=\'menuDropdown-enq\']")).click();
Thread.sleep(300L);
driver.findElement(By.xpath("//ul[@class='list-unstyled di-block m-y-10']//a[contains(text(),'People')]")).click();
driver.switchTo().frame("browsePeopleFrame");
Thread.sleep(500L);
driver.findElement(By.xpath("//*[@id='quickselect']")).sendKeys("ATNS");
Thread.sleep(500L);
driver.findElement(By.xpath("//*[@id=\"peopleSelectFormBean\"]/div[2]/div[1]/div/div/div/span[2]/button/span")).click();
driver.switchTo().defaultContent();
WebElement namingwait;
namingwait = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//ul[@id='categories-tabs']//a[contains(text(),'Naming')]")));
namingwait.click();
driver.switchTo().defaultContent();
WebElement reservedname;
reservedname = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"category-114\"]/div[1]/a[1]")));
reservedname.click();
Thread.sleep(900L);
driver.findElement(By.xpath("//*[@id=\"content\"]/section[3]/div/article/header/ul/li/a")).click();
char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < 8; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
String name = sb.substring(0, 1).toUpperCase() + sb.substring(1);
driver.findElement(By.id("newName")).sendKeys("Cote" + name + name + name + "jay");
driver.findElement(By.xpath("//*[@id=\"proposedNameForm\"]/div/div/div[1]/span/button")).click();
driver.findElement(By.xpath("//textarea[@id='meaning']")).sendKeys("MEANING");
driver.findElement(By.xpath("//*[@id=\"reservationType2\"]")).click();
Thread.sleep(900L);
driver.findElement(By.xpath("//*[@id=\"nav-footer\"]/div/ul/li[1]/button")).click();
driver.findElement(By.xpath("//button[@name='_target10']")).click();
driver.findElement(By.xpath("//button[@name='_finish']")).click();
driver.findElement(By.xpath("//a[contains(text(),'Return to Enquire Name Reservations')]")).click();
Thread.sleep(900L);
driver.quit();