简体   繁体   English

WebDriver测试用例的问题

[英]Issue with WebDriver test case

I have written a test case using WebDriver, I closed the browser in one method and again I am opening the browser not able to invoke 我已经使用WebDriver编写了一个测试案例,用一种方法关闭了浏览器,然后再次打开无法调用的浏览器

driver.close(); i closed the browser through above command for again opening a browser i driver.get(url) but i am getting error 'Error communicating with the remote browser It may have died' 我通过上述命令关闭了浏览器,再次打开了我的浏览器driver.get(url)但出现错误“与远程浏览器通信出错,可能已死亡”

Well you killed the browser with your driver.close(); 好吧,您用driver.close();杀死了浏览器driver.close(); In order to use the driver you must create a new one using something like driver = new FirefoxDriver(capabilities); 为了使用该驱动程序,您必须使用driver = new FirefoxDriver(capabilities);类的东西来创建一个新driver = new FirefoxDriver(capabilities);

If you really want to close the browser before navigating to the new URL, then do: 如果您确实要在导航到新URL之前关闭浏览器,请执行以下操作:

driver.quit();
driver = new FirefoxDriver();
driver.get(url);

However, why would you want to close the browser before navigating to the new URL in the first place? 但是,为什么要先导航到新URL之前关闭浏览器?

I can think of either one of two reasons: 我可以想到以下两个原因之一:

  1. You want to go to the next URL with your browser's history cleaned. 您想转到下一个URL,并清除浏览器的历史记录。

    If this is indeed the case, then deleteAllCookies will do the job. 如果确实如此,那么deleteAllCookies将完成此工作。

  2. You cannot go to the next URL because some popup alert is preventing you doing it. 您无法转到下一个URL,因为某些弹出警报阻止您执行此操作。

    If this is indeed the case, then neither close not quit will do the job. 如果事实确实如此,那么既不closequit将做的工作。

Moving to answer from comment. 从评论开始回答。

I think I got your issue. 我想我有你的问题。 Though you have called the close() and it only should close the current window, you should use this if you want to shift between multiple windows. 尽管您已经调用close(),并且它仅应关闭当前窗口,但是如果要在多个窗口之间切换,则应使用此方法。

For your case just don't close the driver it will use the same window to open the url. 对于您的情况,只是不要关闭驱动程序,它将使用相同的窗口打开URL。

You have to use following way if you want to close the current browser and open 
a new one:    

webDriver.Close();
//Goto the Target website
WebDriver.Navigate().GoToUrl("url");

And you can use following way if you want to close the browser and kill the
web driver:

webDriver.Close();
webDriver.Quit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium Webdriver中的测试用例西装执行错误 - Test Case Suit Execution Error in selenium Webdriver Selenium WebDriver:如何在失败的测试用例中在testNG中执行完整的测试 - Selenium WebDriver: How to execute complete Test in testNG for a failed test case Selenium Webdriver中方法(测试用例)的问题 - Issue with methods ( Test cases ) in Selenium Webdriver 执行正常测试用例时,Selenium WebDriver中出现错误 - Error in selenium webDriver while executing the normal test case 使用最新的 Selenium IDE 将测试用例导出为 Java/JUnit/Webdriver - Export test case as - Java / JUnit /Webdriver using latest Selenium IDE 如何在Selenium Webdriver中将值从一个测试用例传递到另一个 - how to pass a value from one test case to another in selenium webdriver 如何在Linux中运行Selenium WebDriver测试用例项目(在Java中完成) - How to run the selenium webdriver test case project(done in java) into Linux 在Selenium Webdriver中,您如何使用测试用例文件? - In Selenium Webdriver what do you usel for test case document? Selenium Webdriver和Eclipse Java登录GMAIL的测试用例 - Test case for Selenium Webdriver and Eclipse java to login GMAIL 启动多个测试用例时,WebDriver 为 NULL - WebDriver is NULL when start more then one test case
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM