Java 为什么我的测试JUnitCumber测试在一起运行时失败,但单独通过,在第二次测试中抛出一个没有这样ID的会话?
cucumber新手,我的两个场景都很好,但当我同时运行它们时,第二个场景失败了。第一个场景运行正常,然后关闭浏览器,然后再次启动浏览器第二个场景在打开浏览器后失败,其中的两个步骤会抛出无效的会话id 我试着更换chrome驱动程序,但仍然不起作用。 你知道为什么会这样吗 我更新了chrome exe文件,使之与我拥有的76版chrome浏览器相匹配。我在TestBase类和主项目中更新了它 特点:Jira主页测试Java 为什么我的测试JUnitCumber测试在一起运行时失败,但单独通过,在第二次测试中抛出一个没有这样ID的会话?,java,selenium,junit,cucumber,selenium-chromedriver,Java,Selenium,Junit,Cucumber,Selenium Chromedriver,cucumber新手,我的两个场景都很好,但当我同时运行它们时,第二个场景失败了。第一个场景运行正常,然后关闭浏览器,然后再次启动浏览器第二个场景在打开浏览器后失败,其中的两个步骤会抛出无效的会话id 我试着更换chrome驱动程序,但仍然不起作用。 你知道为什么会这样吗 我更新了chrome exe文件,使之与我拥有的76版chrome浏览器相匹配。我在TestBase类和主项目中更新了它 特点:Jira主页测试 验证主页标题,然后在project Shop4NASA下创建一个故事 验证该故
- 验证主页标题,然后在project Shop4NASA下创建一个故事
- 验证该故事是在Shop4NASA下创建的
- 将故事置于就绪、进行中、测试、完成和关闭状态,并进行验证
- 创建评论并附加此故事的屏幕截图
- 创建一个Bug,并将其置于就绪、进行中、测试、完成和关闭状态,并对其进行验证
- 为此错误创建注释并附加屏幕截图
Starting ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442}) on port 30443
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Oct 08, 2019 4:53:41 PM org.openqa.selenium.remote.ProtocolHandshake create Session
INFO: Detected dialect: W3C
10-08-2019 16:53:41 INFO TestBase:43 - Chrome browser is invoked
10-08-2019 16:53:42 INFO TestBase:74 - Driver is returned
ReadProperties - url: https://j*****
10-08-2019 16:53:47 INFO HomePage:120 - JIRA HomePage constructor is invoked
10-08-2019 16:53:50 INFO HomePage:126 - JIRA Home Page Title is returned
Were on Home page of Jira Stage and the title is: System Dashboard - JIRA Stage
10-08-2019 16:53:50 INFO HomePage:133 - Clicking on the Project Tab
10-08-2019 16:53:50 INFO HomePage:152 - Clicking on the QA Test Project 2 (QTP2) link
10-08-2019 16:53:53 INFO HomePage:157 - Clicking on the Create Button
10-08-2019 16:53:53 INFO CreateIssuePage:60 - Create Issue Page constructor is invoked
10-08-2019 16:53:56 INFO CreateIssuePage:117 - JIRA Create Issue Page Title is returned
Were on Create Issue Page of QAT project and the title is: Create Issue - JIRA Stage
10-08-2019 16:53:56 INFO HomePage:120 - JIRA HomePage constructor is invoked
10-08-2019 16:53:56 INFO CreateIssuePage:60 - Create Issue Page constructor is invoked
10-08-2019 16:53:56 INFO CreateIssuePage:123 - Clicking on the dropdown
10-08-2019 16:53:56 INFO HomePageStepDefinition:43 - Completed executing scenario : Create Story
------------------ runAfterScenario ------------------ : Status: Failed
***HomePageStepDefinition - runAfterScenario *** :Take screenshot
10-08-2019 16:53:57 INFO HomePageStepDefinition:61 - C:\Users\a\eclipse-workspace\Ji\target\surefire-reports\Screenshots\Failed\Create Story-10-08-2019-16-53-57.png
10-08-2019 16:53:57 INFO TestBase:69 - Driver is closed
[31mFailed scenarios:[0m
[31msrc/test/java/com/nasa/jira/feature/jira.feature:39 [0m# Scenario: Create Story
2 Scenarios ([31m1 failed[0m, [32m1 passed[0m)
36 Steps ([31m1 failed[0m, [36m17 skipped[0m, [32m18 passed[0m)
1m18.872s
org.openqa.selenium.NoSuchSessionException: invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'H', ip: '156', misname: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 77.0.3865.90, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: C:\Users\aa\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:59027}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 32d2bddbe968d1f7f5a8a46714f28b56
*** Element info: {Using=xpath, value=//div[@id='issuetype-single-select']//span[@class='icon aui-ss-icon noloading drop-menu']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy18.isDisplayed(Unknown Source)
at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:314)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:43)
at org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:300)
at org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:297)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
at com.nasa.testframework.helper.UtilClass.clickElement(UtilClass.java:34)
at com.nasa.jira.pages.CreateIssuePage.clickIssueType(CreateIssuePage.java:124)
at com.nasa.jira.stepDefinition.CreateIssuePageStepDefinition.userFillsOutTheAsterickFieldsOfStory(CreateIssuePageStepDefinition.java:47)
at ✽.And User fills out the asterick fields of Story(src/test/java/com/nasa/jira/feature/jira.feature:42)
应该能够很好地通过此测试,但在第二个场景开始后会抛出一个无会话Id。您如何打开/关闭浏览器?也许你需要确保它是一个干净的开始。Marit,我有一个测试基类,其中有一个包含driver.close的AfterMethod@AfterMethod public void tearDown(){driver.close();log.info(“driver is closed”);}public static WebDriver getDriver(){log.info(“driver is returned”);//System.out.println(“TestBase-Inside getDriver method:”;return driver;}}}好的,我的下一个问题是下次打开浏览器时它是否是“干净”的,或者它重新打开刚刚关闭的一个。我认为它正在打开刚刚关闭的一个,然后找到方法打开一个干净的,或者从上一个中清除会话/cookies/任何内容。(对不起,细节不清楚,前端有一段时间没有实现自动化)
#Test Case ID 003: JIRA -Create Story issue and go through workflow To Do-> Ready>In Progress->Ready for testing> Testing> Done->Closed->To Do
@End2End
Scenario: Create Story
When User clicks on create for an Story
And User fills out the asterick fields of Story
And User clicks Create
When User clicks on Story
Then User verifies Story was created
When User clicks on To Do
Then User verifies Status is To Do
When User clicks on Ready
Then User verifies Status is Ready
And User clicks on inprogress for story
Then User verifies Status is inprogress
When User clicks on Ready for Test
Then User verifies Status is Ready for Test
When User clicks on Testing
Then User verifies Status is Testing
When User clicks on WorkFlow Done
Then User verifies Status is DONE
When User clicks on Close button
Then User verifies Status is Closed
@And("^User fills out the asterick fields of Story$")
public void userFillsOutTheAsterickFieldsOfStory() throws Throwable {
// Write code here that turns the phrase above into concrete
actions
homePage = new HomePage(driver);
createIssuePage = new CreateIssuePage(driver);
createIssuePage.clickIssueType();
Thread.sleep(5000);
createIssuePage.clickCreateStoryIssueType();
Thread.sleep(5000);
createIssuePage.fillStorySummary();
Thread.sleep(5000);
//Thread.sleep(5000);
createIssuePage.fillStoryDescription();
Thread.sleep(5000);
}
Starting ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442}) on port 30443
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Oct 08, 2019 4:53:41 PM org.openqa.selenium.remote.ProtocolHandshake create Session
INFO: Detected dialect: W3C
10-08-2019 16:53:41 INFO TestBase:43 - Chrome browser is invoked
10-08-2019 16:53:42 INFO TestBase:74 - Driver is returned
ReadProperties - url: https://j*****
10-08-2019 16:53:47 INFO HomePage:120 - JIRA HomePage constructor is invoked
10-08-2019 16:53:50 INFO HomePage:126 - JIRA Home Page Title is returned
Were on Home page of Jira Stage and the title is: System Dashboard - JIRA Stage
10-08-2019 16:53:50 INFO HomePage:133 - Clicking on the Project Tab
10-08-2019 16:53:50 INFO HomePage:152 - Clicking on the QA Test Project 2 (QTP2) link
10-08-2019 16:53:53 INFO HomePage:157 - Clicking on the Create Button
10-08-2019 16:53:53 INFO CreateIssuePage:60 - Create Issue Page constructor is invoked
10-08-2019 16:53:56 INFO CreateIssuePage:117 - JIRA Create Issue Page Title is returned
Were on Create Issue Page of QAT project and the title is: Create Issue - JIRA Stage
10-08-2019 16:53:56 INFO HomePage:120 - JIRA HomePage constructor is invoked
10-08-2019 16:53:56 INFO CreateIssuePage:60 - Create Issue Page constructor is invoked
10-08-2019 16:53:56 INFO CreateIssuePage:123 - Clicking on the dropdown
10-08-2019 16:53:56 INFO HomePageStepDefinition:43 - Completed executing scenario : Create Story
------------------ runAfterScenario ------------------ : Status: Failed
***HomePageStepDefinition - runAfterScenario *** :Take screenshot
10-08-2019 16:53:57 INFO HomePageStepDefinition:61 - C:\Users\a\eclipse-workspace\Ji\target\surefire-reports\Screenshots\Failed\Create Story-10-08-2019-16-53-57.png
10-08-2019 16:53:57 INFO TestBase:69 - Driver is closed
[31mFailed scenarios:[0m
[31msrc/test/java/com/nasa/jira/feature/jira.feature:39 [0m# Scenario: Create Story
2 Scenarios ([31m1 failed[0m, [32m1 passed[0m)
36 Steps ([31m1 failed[0m, [36m17 skipped[0m, [32m18 passed[0m)
1m18.872s
org.openqa.selenium.NoSuchSessionException: invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'H', ip: '156', misname: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 77.0.3865.90, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: C:\Users\aa\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:59027}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 32d2bddbe968d1f7f5a8a46714f28b56
*** Element info: {Using=xpath, value=//div[@id='issuetype-single-select']//span[@class='icon aui-ss-icon noloading drop-menu']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy18.isDisplayed(Unknown Source)
at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:314)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:43)
at org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:300)
at org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:297)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
at com.nasa.testframework.helper.UtilClass.clickElement(UtilClass.java:34)
at com.nasa.jira.pages.CreateIssuePage.clickIssueType(CreateIssuePage.java:124)
at com.nasa.jira.stepDefinition.CreateIssuePageStepDefinition.userFillsOutTheAsterickFieldsOfStory(CreateIssuePageStepDefinition.java:47)
at ✽.And User fills out the asterick fields of Story(src/test/java/com/nasa/jira/feature/jira.feature:42)