Selenium chromedriver does not close properly - java

I'm using chromedriver and Java to run automatic web tests. To be able to use extensions in Chrome I'm using my existing browser profile. Since then I'm experiencing following:
run a selenium test with green result
open Chrome manualy (or run some test)
get error message "chrome application did not close properly"
I'm closing browser and the driver with this:
#AfterClass public static void tearDownClass() {driver.quit();}
I've tried:
#AfterClass public static void tearDownClass() {driver.close();}
but this closes just browser, not the driver.
After some attempts to fix I simulate pressing CTRL+SHIFT+Q:
package SSO_CWP_APPROVAL;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.openqa.selenium.WebDriver;
public class Keyboard_events {
public static WebDriver driver;
public Keyboard_events(WebDriver driver) {Keyboard_events.driver = driver;}
public void ctrl_shift_q() throws AWTException, InterruptedException {
Robot rob = new Robot();
rob.keyPress(KeyEvent.VK_CONTROL);
rob.keyPress(KeyEvent.VK_SHIFT);
rob.keyPress(KeyEvent.VK_Q);
rob.keyRelease(KeyEvent.VK_CONTROL);
rob.keyRelease(KeyEvent.VK_SHIFT);
rob.keyRelease(KeyEvent.VK_Q);
Thread.sleep(1000);
}
}
The sleep is in this case neccessary. Sleeping less time and get the error again.
#AfterClass public static void tearDownClass() throws AWTException, InterruptedException {K_events.ctrl_shift_q();driver.quit();}
binaries:
Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200
chromedriver.exe 2.42
JDK 8u151
Chrome 69.0.3497.100
Is there any better way how to close browser and the driver?

It was propably bug in Google Chrome 69. In version 70 and 71 works driver.close();driver.quit(); just fine.

Related

Selenium server parallel tests error: invalid session id

Hi can somebody tell me please what am I doing wrong in running parallel tests on Selenium server?
I have this simple parallel tests in the class:
package tests;
import categories.Category1;
import com.google.code.tempusfugit.concurrency.ConcurrentTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
#RunWith(ConcurrentTestRunner.class)
#Category(Category1.class)
public class ParalelTest extends Base
{
protected String siteUrl = "/waitforit.php";
#Before
public void setUp()
{
driver.get(baseUrl + siteUrl);
}
#Test
public void test1()
{
System.out.println("test1() thread name: " + Thread.currentThread().getName());
}
#Test
public void test2()
{
System.out.println("test2() thread name: " + Thread.currentThread().getName());
}
#Test
public void test3()
{
System.out.println("test3() thread name: " + Thread.currentThread().getName());
}
#Test
public void test4()
{
System.out.println("test4() thread name: " + Thread.currentThread().getName());
}
}
Here is the screen with error:
What is wrong with that? Without server it works fine.
This error message...
org.openqa.selenium.NoSuchSessionException: no such session
...implies that the chromedriver=80.0 wasn't able to initiate/spawn a new Browsing Context with Chrome Browser v80.0.
Your main issue is the version incompatibility between the binaries you are using as follows :
Though you are using latest Selenium Client version 3.141.59, Chrome Driver version 80.0 and Chrome version v80.0.
Your JDK version is 1.8.0_65 which is pretty ancient.
Solution
A generic solution would be to:
Upgrade JDK to recent level of JDK 8u241.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test.
Update
However, the invalid session ID error is a WebDriver error that occurs when the server does not recognize the unique session identifier. This happens if the session has been deleted or if the session ID is invalid.
A WebDriver session can be deleted through either of the following ways:
Explicit session deletion: A WebDriver session is explicitly deleted when explicitly invoking the quit() method.
Implicit session deletion: A WebDriver session is implicitly deleted when you close the last window or tab invoking close() method.
Reference
You can find a relevant detailed discussion in:
selenium.common.exceptions.WebDriverException: Message: invalid session id using Selenium with ChromeDriver and Chrome through Python

selenium won't get URL?

this my code open fire fox and get google
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class auto {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "//root//Desktop//jarselenium//geckodriver-v0.20.1-linux64/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
//driver.get("https://www.easybooking.lk/login");
//driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("https://www.google.com");
}
}
but when i run this code selenium open fire fox but wont get url im running this code in linux
As per the current implementation of Selenium v3.11.0, GeckoDriver 0.20.1 I don't see any major issue in your code block perhaps the trace logs would have helped us to understand your issue better. Having said that you need to follow the below mentioned steps :
As you are using Linux based System you need to pass the absolute path of the GeckoDriver within single forward slashes i.e. / as follows :
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver-v0.20.1-linux64/geckodriver");
As GeckoDriver opens Firefox Browser client in maximized mode you need to omit the line of code :
driver.manage().window().maximize();

The driver executable does not exist: Selenium Firefox

I've been struggling with this for the past few hours. I'm trying to install Selenium web driver and have been running into a bunch of errors which prevent me from running the test page. I'm pretty sure my most recent issue is with this code:
public static void main(String[] args) throws InterruptedException{
System.setProperty("webdriver.gecko.driver","C:/Users/theone/Downloads/geckodriver 2.exe");
Would really appreciate any feedback on second steps!
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstTestCase {
public static void main(String[] args) throws InterruptedException{
System.setProperty("webdriver.gecko.driver","C:/Users/theone/Downloads/geckodriver 2.exe");
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
//Launch the Online Store Website
driver.get("http://www.store.demoqa.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website www.Store.Demoqa.com");
//Wait for 5 Sec
Thread.sleep(5);
// Close the driver
driver.quit();
}
}
You can setup Selenium with GeckoDriver either with webdriver.gecko.driver property or using environment properties. It would be good if you the latest version of Firefox, GeckoDriver and Selenium 3.0
Check out this article which provides setup using both these ways -
http://automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/
C:/Users/theone/Downloads/geckodriver 2.exe
There's a space in the path, it may work if you rename your file geckodriver2.exe.

Running Internet Explorer with selenium WebDriver.quit(); does not work

I am running the following code and the browser does not close.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class _getPageIE {
public static void main(String[] args) throws InterruptedException {
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
System.setProperty("webdriver.ie.driver", "C:\\WebDriver\\IEDriverServer.exe");
WebDriver ieDriver = new InternetExplorerDriver(capabilities);
ieDriver.manage().window().maximize();
ieDriver.get("http://google.com");
ieDriver.quit();
System.out.println("end");
}
}
The Browser opens, then is maximized and the Google page is displayed. Then the System.out.printlin is executed and the program ends, but the browser remains open.
I am running Eclipse with Selenium 2.44 on Windows 8.1 64 bit with the 64 bit IEDriverServer.exe.
The Console output is as follows.
Started InternetExplorerDriver server (64-bit)
2.44.0.0
Listening on port 46733
end
Any help is appreciated.

selenium RC basic test doesn't work with iexplore, but works with FF, and more

The classic google test here from selenium website, it works in FF on vista. On IE7, apparently doesn't find the window object. Selnm gets farther in the test (On IE) when I change config to using "*iexploreproxy", (instead of "*iexplore") but I cannot use that because it causes untrusted security certificate warnings. I installed selenium RC 1.0.1, and checked it is running on my box, I am not using any other tools such as bromine. I am running on Eclipse.
public class NewTest extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.google.com/", "iexplore");
// We instantiate and start the browser
}
public void testNew() throws Exception {
selenium.open("/");
selenium.type("q", "selenium rc");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");
if(! selenium.isTextPresent("Results * for selenium rc"))
throw new Exception("failed");
}
}
I found this error to occur when IE was running in protected mode. You can disable protected mode by going to IE Tools->Internet Options->Security and click the check box.
I found that the internet options, connections, LAN settings has a automatic configuration script/custom profile that was interfering somehow in IE. It works now!
Here was the path just for history.
file://C:/Users/myname/AppData/Local/Temp/customProfileDir4b9b53c99d684ec4952cf8a721790c85/proxy.pac

Categories

Resources