Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: whenever i have to run the test case, i have to restart the container.. #1896

Closed
changan1111 opened this issue Jul 17, 2023 · 5 comments

Comments

@changan1111
Copy link

changan1111 commented Jul 17, 2023

What happened?

I am running the test case eg. after 1st Testcase if i am running again, then it is not running, it is stays on the same screen..

Jul 17, 2023 3:44:37 PM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer
INFO: Using OpenTelemetry for tracing

and if I restart container, then again I am able to run the testcase. Is this the behavior? I can not run back to back test cases?

Without restarting the container, i am unable to run the testcase multiple times or multiple test cases..

Is this behavior that after every run I need restart container to proceed to next test case run?

Command used to start Selenium Grid with Docker

docker run -d -p 4444:4444 --shm-size="2g" selenium/standalone-chrome

Relevant log output

2023-07-17 15:45:10 10:15:10.029 INFO [LocalNode.newSession] - Session created by the Node. Id: 1760689c760e5ee901c9c31130e7811f, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 114.0.5735.133, chrome: {chromedriverVersion: 114.0.5735.90 (386bc09e8f4f..., userDataDir: /tmp/.com.google.Chrome.sgKM35}, goog:chromeOptions: {debuggerAddress: localhost:33043}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.17.0.2:4444/sessio..., se:cdpVersion: 114.0.5735.133, se:vnc: ws://172.17.0.2:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.17.0.2:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
2023-07-17 15:45:10 10:15:10.032 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: 1760689c760e5ee901c9c31130e7811f 
2023-07-17 15:45:10  Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 114.0.5735.133, chrome: {chromedriverVersion: 114.0.5735.90 (386bc09e8f4f..., userDataDir: /tmp/.com.google.Chrome.sgKM35}, goog:chromeOptions: {debuggerAddress: localhost:33043}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.17.0.2:4444/sessio..., se:cdpVersion: 114.0.5735.133, se:vnc: ws://172.17.0.2:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.17.0.2:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
2023-07-17 15:47:13 10:17:13.209 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://172.17.0.2:7900
2023-07-17 15:48:22 10:18:22.498 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://172.17.0.2:7900
2023-07-17 15:51:58 10:21:58.500 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "5902d10ab2cc3e54a24d90153a7355dd","eventTime": 1689589318499620694,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "localhost:4444","http.method": "POST","http.request_content_length": "439","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession","http.user_agent": "selenium\u002f4.8.3 (java windows)"}}
2023-07-17 15:51:58 
2023-07-17 15:53:39 10:23:39.370 INFO [LocalNode.stopTimedOutSession] - Session id 1760689c760e5ee901c9c31130e7811f timed out, stopping...
2023-07-17 15:53:39 10:23:39.566 INFO [LocalSessionMap.lambda$new$0] - Deleted session from local Session Map, Id: 1760689c760e5ee901c9c31130e7811f
2023-07-17 15:53:39 10:23:39.567 INFO [GridModel.release] - Releasing slot for session id 1760689c760e5ee901c9c31130e7811f
2023-07-17 15:53:39 10:23:39.568 INFO [SessionSlot.stop] - Stopping session 1760689c760e5ee901c9c31130e7811f
2023-07-17 15:53:39 10:23:39.568 WARN [LocalNode.lambda$new$5] - Removing Downloads folder associated with 1760689c760e5ee901c9c31130e7811f
2023-07-17 15:53:39 10:23:39.569 WARN [LocalNode.lambda$new$6] - Removing Uploads folder associated with 1760689c760e5ee901c9c31130e7811f
2023-07-17 15:53:39 10:23:39.585 INFO [LocalDistributor.newSession] - Session request received by the Distributor: 
2023-07-17 15:53:39  [Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*], extensions: []}}]
2023-07-17 15:53:39 10:23:39.588 INFO [DriverService$Builder.getLogOutput] - Driver logs no longer sent to console by default; https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output
2023-07-17 15:53:40 10:23:40.273 INFO [LocalNode.newSession] - Session created by the Node. Id: 6cf376a76b9c424351b05adfd7202d25, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 114.0.5735.133, chrome: {chromedriverVersion: 114.0.5735.90 (386bc09e8f4f..., userDataDir: /tmp/.com.google.Chrome.9SoqL5}, goog:chromeOptions: {debuggerAddress: localhost:40549}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.17.0.2:4444/sessio..., se:cdpVersion: 114.0.5735.133, se:vnc: ws://172.17.0.2:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.17.0.2:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
2023-07-17 15:53:40 10:23:40.276 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: 6cf376a76b9c424351b05adfd7202d25 
2023-07-17 15:53:40  Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 114.0.5735.133, chrome: {chromedriverVersion: 114.0.5735.90 (386bc09e8f4f..., userDataDir: /tmp/.com.google.Chrome.9SoqL5}, goog:chromeOptions: {debuggerAddress: localhost:40549}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.17.0.2:4444/sessio..., se:cdpVersion: 114.0.5735.133, se:vnc: ws://172.17.0.2:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.17.0.2:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, web

Operating System

Windows 11

Docker Selenium version (tag)

4.10.0

@github-actions
Copy link

@changan1111, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@github-actions
Copy link

Hi, @changan1111.
Please follow the issue template, we need more information to reproduce the issue.

Either a complete code snippet and URL/HTML (if more than one file is needed, provide a GitHub repo and instructions to run the code), the specific versions used, or a more detailed description to help us understand the issue.

Note: If you cannot share your code and URL/HTML, any complete code snippet and URL/HTML that reproduces the issue is good enough.

Reply to this issue when all information is provided, thank you.

@changan1111
Copy link
Author

changan1111 commented Jul 19, 2023

package BotAutomationProject.DreamHotelSuite;


import java.io.File;
import java.io.IOException;
import java.util.HashMap;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.MediaEntityBuilder;
import com.aventstack.extentreports.model.Media;
import com.epam.healenium.SelfHealingDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
import java.net.URL;



import io.github.bonigarcia.wdm.WebDriverManager;
import junit.framework.Assert;

public class FirstTest {

	WebDriver driver;
	
	
    private ExtentTest test;
	
	
	@BeforeTest
	public void setup() {
		ExtentReportUtils.initializeExtentReport();

        // Create a new test instance
        test = ExtentReportUtils.createTest("My Test Chennai");
       

	}
	

	@Test
	public void DreamHotelTest1() throws IOException, InterruptedException {
		WebDriverManager.chromedriver().setup();
		//WebDriver delegate = new ChromeDriver();
        ChromeOptions options = new ChromeOptions();
        //URL gridUrl = new URL("http://localhost:4444/wd/hub");
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
		//driver = SelfHealingDriver.create(delegate);
		test.info("Opening the url");
		//driver.get("http://localhost:4200");
		driver.get("https://www.google.com/");
		System.out.println(driver.getTitle());
		test.info(driver.getCurrentUrl());
		driver.findElement(By.name("q")).sendKeys("Sachin Tendulkar");
		driver.findElement(By.name("btnK")).click();
		Thread.sleep(5000);
        /*SPALoadTimeTestListener.startTimer();
        SPALoadTimeTestListener.calculateLoadTime();
		driver.findElement(By.xpath("//input[@ng-reflect-name='text']")).clear();
		driver.findElement(By.xpath("//input[@ng-reflect-name='text']")).sendKeys("Chennai");
		driver.findElement(By.xpath("//button[text()='Search']")).click();
		test.info("Search value is Chennai");
		SPALoadTimeTestListener.startTimer();
	    SPALoadTimeTestListener.calculateLoadTime();		////*[@class='card']/div/div[2]/div[@class='font-superbig']
		String reviewcomment=driver.findElement(By.xpath("//*[@class='card']//div[@class='font-superbig']")).getText();
	    String screenshotPath = takeCaptureScreen(driver); // Capture the screenshot and get its path
	    //test.pass("Passed", MediaEntityBuilder.createScreenCaptureFromPath(screenshotPath).build());
		test.info("review comment is: "+reviewcomment);
	    Assert.assertEquals("3.1", reviewcomment);
		takeCaptureScreen(driver);
		driver.findElement(By.xpath("//input[@ng-reflect-name='text']")).clear();
		driver.findElement(By.xpath("//input[@ng-reflect-name='text']")).sendKeys("Chennai");
		driver.findElement(By.xpath("//*[text()='Search']")).click();
		SPALoadTimeTestListener.startTimer();
	    SPALoadTimeTestListener.calculateLoadTime();
		test.info("End of Dream Hotel Test1");*/

	}
	
	
	
	public static String takeCaptureScreen(WebDriver driver) throws IOException {
	    driver = ((SelfHealingDriver) driver).getDelegate();
	    TakesScreenshot screen = ((TakesScreenshot) driver);
	    File src = screen.getScreenshotAs(OutputType.FILE);
	    String dest = System.getProperty("user.dir") + "\\"
	            + System.currentTimeMillis() + ".png";
	    System.out.println(dest);
	    File target = new File(dest);
	    FileUtils.copyFile(src, target);
	    return dest; // Return the path of the captured screenshot
	}
	
	
	  @AfterTest
	    public void finalizeReport() {
	        // Flush the Extent Report after all test cases finish
		  System.out.println(test.getModel().getLogs());
		  HashMap<String, String> ExtentLogs = ExtentReportUtils.extractLogs(test.getModel().getLogs());
		  
		  System.out.println(ExtentLogs.get("LogDetails"));
		  ExtentReportUtils.flushReport();
		 driver.close();
		 // ExtentReportUtils.removeTest();
	       
	    }
	
}

this is the sample code written.. when I run first time it is working, again if i want to run just in case, i need to restart the container.. without that it is not working.. is this the design for this image?

@diemol
Copy link
Member

diemol commented Jul 19, 2023

A couple of things:

  • You do not need WebDriverManager.chromedriver().setup();, the images already have the browser driver configured.
  • driver.close(); does not end the session, just closes the browser. That is why for you it seems as if you need to restart the container. Use driver.quit().

@diemol diemol closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2023
Copy link

github-actions bot commented Dec 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants