我收到Session Not found异常,不知道为什么我错过了。 我在另一个方法TestCase1中调用方法Acti_05CreateNewCUst,然后通过main函数访问它。
显示错误消息时,它正常工作。 如果没有错误消息,则执行BUt,执行失败并显示异常
WARN [main] (Log.java:42)- The exception thrown here is :org.openqa.selenium.remote.SessionNotFoundException: no such session
//A method
public class Acti_05CreateNewCust
{
private static WebElement element = null;
static WebDriverWait wait;
//Error Message
public static WebElement errorMsgCust(WebDriver driver)
{
try
{
wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='customerLightBox_footer']/table/tbody/tr/td[1]/div/span")));
Log.warn("Error message element has been identifeid");
}
catch(Exception e)
{
Log.debug("The exception here for error msg is "+e);
}
return driver.findElement(By.xpath(".//*[@id='customerLightBox_footer']/table/tbody/tr/td[1]/div/span"));
}
}
//Calling the method under This method
public static void TestCase1() throws Exception
{
ExcelUtils.setExcelFile(Constant.Path_TestData+Constant.File_TestCaseExecSheet, Constant.Sheet2_TestCaseExecSheet);
driver=ActiAction_03OpenBrowser.openBrowser("Chrome");
if(Acti_01LoginPage.val_LoginPage(driver)==true)
{
ActiAction_01Login.Execute(driver);
Log.info("Customer has logged in and navigated to Home page");
takeSnapShot(driver, "TC1");
Acti_02HmePage.click_linkTasktab(driver).click();
Log.info("Task Tab has been clicked");
takeSnapShot(driver, "TC1");
if(Acti_02HmePage.val_suc_click_linkTasktab(driver)==true)
{
Acti_03TaskPage.click_linkProjectCust(driver).click();
Log.info("Project and Customer link has been clicked");
takeSnapShot(driver, "TC1");
if(Acti_03TaskPage.valsuc_click_linkProjectCust(driver)==true)
{
Acti_04ProjandCust.click_BtnCreateCust(driver).click();
Log.info("Create Customer Button has been clicked");
takeSnapShot(driver, "TC1");
ExcelUtils.setExcelFile(Constant.Path_TestData+Constant.File_TestCaseExecSheet, Constant.Sheet3_TestCaseExecSheet);
Log.info("The excelsheet is opened::"+(Constant.Path_TestData+Constant.File_TestCaseExecSheet)+Constant.Sheet3_TestCaseExecSheet);
int rownum=ExcelUtils.getrownum(Constant.Sheet3_TestCaseExecSheet);
Log.info("The total number of row in::"+Constant.Sheet3_TestCaseExecSheet+" is "+rownum);
for(int i=1;i<rownum+1;i++)
{
Acti_05CreateNewCust.input_TxtCustname(driver).sendKeys(ExcelUtils.getCellData(i,0));
Log.info("Customer name has been entered from excelsheet");
Acti_05CreateNewCust.input_TxtCustDesc(driver).sendKeys(ExcelUtils.getCellData(i,1));
Log.info("Customer Desc has been entered from excelsheet");
if(Acti_05CreateNewCust.click_chceckbox1(driver).isSelected())
{
Acti_05CreateNewCust.click_chceckbox1(driver).click();
Log.info("Checkbox 1 has been unselecetd");
}
if(Acti_05CreateNewCust.click_chceckbox2(driver).isSelected())
{
Acti_05CreateNewCust.click_chceckbox2(driver).click();
Log.info("Checkbox 2 has been unselecetd");
}
if(Acti_05CreateNewCust.click_chceckbox3(driver).isSelected())
{
Acti_05CreateNewCust.click_chceckbox3(driver).click();
Log.info("Checkbox 3 has been unselecetd");
}
Acti_05CreateNewCust.click_BtnCreateCust1(driver).click();
Log.info("Create Button has been clicked on New Customer Creation Page");
takeSnapShot(driver, "TC1");
try
{
if(Acti_05CreateNewCust.errorMsgCust(driver).isDisplayed())
{
Log.warn("The error msg exist ");
takeSnapShot(driver, "WarnOmCustomerCreation Page");
Acti_05CreateNewCust.click_BtnCancel(driver).click();
Acti_05CreateNewCust.close_popup(driver);
Log.warn("Customer has not been created successfully");
}
else
{
if(Acti_04ProjandCust.val_newcustomer(driver, ExcelUtils.getCellData(i,0))==true)
{
Log.info("Customer has been created successfully");
}
else
{
Log.fatal("Customer has not been created successfully");
}
}
}catch(Exception e)
{
Log.debug("The exception is thrown here"+e);
}
driver.close();
}
}
else
{
Log.fatal("There is someissue with Project&Customer tab, please check it");
driver.close();
}
}
else
{
Log.fatal("There is someissue with task tab, please check it");
driver.close();
}
ActiAction_02LogOut.Execute(driver);
}
else
{
Log.fatal("The Login Page is not displayed");
takeSnapShot(driver, "FailLogin");
driver.close();
}
}
//Callin the same through main
public class MainDriveScenario
{
public static void main(String []args) throws Exception
{
//ExcelUtils obj1=new ExcelUtils();
ScenarioDetails.setuplog();
ExcelUtils.setExcelFile(Constant.Path_TestData+Constant.File_TestCaseExecSheet,Constant.Sheet1_TestCaseExecSheet);
int rownum1=ExcelUtils.getrownum(Constant.Sheet1_TestCaseExecSheet);
for(int i=1;i<rownum1+1;i++)
{
String Action_Execute=ExcelUtils.getCellData(i, 2);
if(Action_Execute.equalsIgnoreCase("YES"))
{
String Action_testcaseId=ExcelUtils.getCellData(i, 0);
switch(Action_testcaseId)
{
case "TC1":
ScenarioDetails.TestCase1();
break;
case "TC2":
ScenarioDetails.TestCase2();
break;
case "TC3":
ScenarioDetails.TestCase3();
break;
default:
System.out.println("Default value");
break;
}
ExcelUtils.setExcelFile(Constant.Path_TestData+Constant.File_TestCaseExecSheet,Constant.Sheet1_TestCaseExecSheet);
ExcelUtils.setCellData("Executed",Constant.Path_TestData+Constant.File_TestCaseExecSheet, i, 4);
}
else
{
ExcelUtils.setExcelFile(Constant.Path_TestData+Constant.File_TestCaseExecSheet,Constant.Sheet1_TestCaseExecSheet);
ExcelUtils.setCellData("NotExecuted",Constant.Path_TestData+Constant.File_TestCaseExecSheet, i, 4);
}
}
}
}
The message displayed in console:
WARN [main] (Log.java:42)- The exception thrown here is :org.openqa.selenium.remote.SessionNotFoundException: no such session
(Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 188 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'A4ML10736', ip: '172.23.38.47', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_45'
*** Element info: {Using=id, value=logoutLink}
答案 0 :(得分:0)
有时候这个问题是由于驱动程序过时造成的,但是我发现如果maven中的pom文件没有在其他依赖项(例如AShot,使用它)之前没有首先列出Selenium,也会发生这种情况。