From last 15 days I started getting this line which is executing the command to print data to PDF, below is the details, I tried in local, its working perfectly fine, even in the VM where Test suite is running on running manually using Visual Studio, no error, but only in pipeline its failing, any help would be appreciated
**Exception Details : **
TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:54995/session/36a5bcb819c93c78746cf5eb6ca81796/goog/cdp/execute timed out after 60 seconds.
—-> System.Threading.Tasks.TaskCanceledException : The operation was canceled.
—-> System.IO.IOException : Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
—-> System.Net.Sockets.SocketException : The I/O operation has been aborted because of either a thread exit or an application request.
StackTrace: –TearDown
at OpenQA.Selenium.Remote.HttpCommandExecutor.ExecuteAsync(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.ExecuteAsync(Command commandToExecute)
at OpenQA.Selenium.WebDriver.ExecuteAsync(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary
2 parameters)
at OpenQA.Selenium.Chromium.ChromiumDriver.ExecuteCdpCommand(String commandName, Dictionary`2 commandParameters)
**Code :**
public static byte[] ConvertHtmlToPdf(string html)
{
int t = 0;
int timeout = 180;
byte[] pdf = new byte[] { };
DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
string baseDir = di.Parent.Parent.Parent.FullName;
string reportDir = Path.Combine(baseDir, "Report", BaseFixture.timestamp);
var filePath = Path.Combine(reportDir, $"{Guid.NewGuid()}.html");
File.WriteAllTextAsync(filePath, html);
var driverOptions = new ChromeOptions();
//In headless mode, PDF writing is enabled by default, hence switching to headless mode
driverOptions.AddArgument("headless");
using var driver = new ChromeDriver(driverOptions);
driver.Navigate().GoToUrl(filePath);
// Output a PDF of the first page in A4 size at 90% scale
var printOptions = new Dictionary<string, object>
{
{ "paperWidth", 210 / 5 },
{ "paperHeight", 150 / 5 },
{ "scale", 0.9 },
{ "pageRanges", "1-2" },
{ "preferCSSPageSize", true }
};
//while (t < timeout)
//{
// Thread.Sleep(60000);
// t = t + 60;
var printOutput = driver.ExecuteCdpCommand("Page.printToPDF", printOptions) as Dictionary<string, object>;
pdf = Convert.FromBase64String(printOutput["data"] as string);
//}
File.Delete(filePath);
return pdf;
}
I tried few solutions such as upgrading and downgrading the chromedriver version, adding –no-sandbox, adding –no-gpu, increasing the timeout for the line(which only took 60 sec after increasing also), updating selenium.support and selenium.WebDriver versions etc. But nothing worked
1