{"id":172,"date":"2024-10-20T17:02:18","date_gmt":"2024-10-20T17:02:18","guid":{"rendered":"https:\/\/nestedflowautomation.com\/?p=172"},"modified":"2024-10-20T17:02:18","modified_gmt":"2024-10-20T17:02:18","slug":"ai-topic-2-failover-testing-auto-download-of-drivers","status":"publish","type":"post","link":"https:\/\/nestedflowautomation.com\/index.php\/2024\/10\/20\/ai-topic-2-failover-testing-auto-download-of-drivers\/","title":{"rendered":"AI -Topic 2 \u2013 Failover Testing &#8211; Auto Download of Drivers"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Objective<\/h2>\n\n\n\n<p>The objective of this post is to auto find the need for new driver download with the real time analysis of errors during web page launching. All examples om this post are based on C# and we will look into Chrome and Edge browsers. auto download feature is already part of Selenium Grid now a days but we can extend it to local setup as well<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Case 1: Edge<\/h2>\n\n\n\n<p>This is a chromium based browser created by Microsoft. below sample is launch of webpage code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DriverPath = \"&lt;path of the msedgedriver.exe>\";\nvar optiones = new EdgeOptions();\noptiones.AddArgument(\"--no-sandbox\");\nIWeb = new EdgeDriver(DriverPath,optiones);<\/code><\/pre>\n\n\n\n<p>In case of wrong msedgedriver.exe which is not matching the actual browsers we will get the error message like: <strong> This version of MSEdgeDriver only supports MSEdge version 84 (SessionNotCreated)<\/strong><\/p>\n\n\n\n<p>We have to check if the error string contains &#8220;only supports MSEdge version &#8220;<\/p>\n\n\n\n<p>If the above test we can follow below steps to download the correct driver versions.<\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Step 1: Check existing browser version on the machine<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var path = Registry.GetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\msedge.exe\", \"\", null);\nstring <strong>version <\/strong>= FileVersionInfo.GetVersionInfo(path.ToString()).FileVersion;<\/code><\/pre>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Step 2: Use the version from above code to run an API<\/span><\/strong><\/p>\n\n\n\n<p>Method: GET<\/p>\n\n\n\n<p>URL: <a href=\"https:\/\/msedgedriver.azureedge.net\/{:VERSION}\/edgedriver_win32.zip\">https:\/\/msedgedriver.azureedge.net\/<strong>version<\/strong>\/edgedriver_win32.zip<\/a><\/p>\n\n\n\n<p>Content-Type: application\/x-www-form-urlencoded<\/p>\n\n\n\n<p>Keep Alive: True<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>This will download the right version of msedgedriver.exe<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Case 2: Chrome<\/h2>\n\n\n\n<p>This is a chromium based browser created by Google. below sample is launch of webpage code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DriverPath = \"&lt;path of the chromedriver.exe>\";\nvar optiones = new ChromeOptions();\noptiones.AddArgument(\"--no-sandbox\");\nIWeb = new ChromeDriver(DriverPath,optiones);<\/code><\/pre>\n\n\n\n<p>We will get similar error as in the case of mismatched edge driver for chrome as well. In case the error is encountered use below code to fetch the current chrome version<\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Step 1: Get Correct Chrome version Installed<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var path = Registry.GetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe\", \"\", null);\n\nstring <strong>version<\/strong> = FileVersionInfo.GetVersionInfo(path.ToString()).FileVersion;<\/code><\/pre>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Step 2: Based on the version from Step 1 get mapped driver version<\/span><\/strong><\/p>\n\n\n\n<p>Use below code to get version mappings<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \/\/URL's originates from here: https:\/\/googlechromelabs.github.io\/chrome-for-testing\/latest-versions-per-milestone-with-downloads.json\nstring html = string.Empty;\nstring urlToPathLocation = @\"https:\/\/googlechromelabs.github.io\/chrome-for-testing\/latest-versions-per-milestone-with-downloads.json\";\n\nHttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlToPathLocation);\n\n                request.Method = \"GET\";\n                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())\n                using (Stream stream = response.GetResponseStream())\n                using (StreamReader reader = new StreamReader(stream))\n                {\n                    html = reader.ReadToEnd();\n                }\n\nstring VerJSON = html;\n                JObject jobj = JObject.Parse(VerJSON);\n                string vmaJOR = <strong>version<\/strong>.Split('.')&#91;0];\n                dynamic JT = jobj&#91;\"milestones\"]&#91;vmaJOR]&#91;\"downloads\"]&#91;\"chromedriver\"];\n                string vversion = version;\n                for(int y=0;y&lt;JT.Count;y++)\n                {\n                    if((JT&#91;y]&#91;\"platform\"].Value).ToString()==\"win32\")\n                    {\n                        <strong>vversion <\/strong>= ((JT&#91;y]&#91;\"url\"].Value).ToString().Replace(\"https:\/\/storage.googleapis.com\/chrome-for-testing-public\/\", \"\").Replace(\"\/win32\/chromedriver-win32.zip\", \"\"));\n                    }\n                }<\/code><\/pre>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Step 3: Download Verion of chromedriver.exe <\/span><\/strong><\/p>\n\n\n\n<p>Method: GET<\/p>\n\n\n\n<p>URL: <a href=\"https:\/\/storage.googleapis.com\/chrome-for-testing-public\">https:\/\/storage.googleapis.com\/chrome-for-testing-public<\/a>\/\/<strong>vversion <\/strong>\/win32\/chromedriver-win32.zip<\/p>\n\n\n\n<p>Content-Type: application\/x-www-form-urlencoded<\/p>\n\n\n\n<p>Keep Alive: True<\/p>\n\n\n\n<p>This will download the right version of chromedriver.zip<\/p>\n\n\n\n<p><strong>fpath<\/strong> = &#8220;path of the zip file&#8221;;<\/p>\n\n\n\n<p>try<br>{<br>System.IO.Compression.ZipFile.ExtractToDirectory(fpath + &#8220;\/\/&#8221; + &#8220;chromedriver.zip&#8221;, fpath);<br>if(File.Exists(fpath + &#8220;\/\/&#8221; + &#8220;chromedriver-win32\/chromedriver.exe&#8221;))<br>{<br>File.Delete(fpath + &#8220;\/\/&#8221; + &#8220;chromedriver.exe&#8221;);<br>File.Copy(fpath + &#8220;\/\/&#8221; + &#8220;chromedriver-win32\/chromedriver.exe&#8221;, fpath + &#8220;\/\/&#8221; + &#8220;chromedriver.exe&#8221;);<br>}<br>File.Delete(fpath + &#8220;\/\/&#8221; + &#8220;chromedriver.zip&#8221;);<br>Directory.Delete(fpath + &#8220;\/\/&#8221; + &#8220;chromedriver-win32&#8221;, true);<br>}<br>catch(Exception E)<br>{<br>MessageBox.Show(E.Message + &#8220;\\r\\n&#8221; + &#8220;Please Refer https:\/\/googlechromelabs.github.io\/chrome-for-testing\/#stable for Downloading&#8221;, &#8220;Error Processing Chromedriver: &#8220;, MessageBoxButton.OK,MessageBoxImage.Stop);<br>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Objective The objective of this post is to auto find the need for new driver download with the real time analysis of errors during web page launching. All examples om this post are based on C# and we will look into Chrome and Edge browsers. auto download feature is already part of Selenium Grid now [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-172","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/posts\/172"}],"collection":[{"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/comments?post=172"}],"version-history":[{"count":1,"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/posts\/172\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/media?parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/categories?post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nestedflowautomation.com\/index.php\/wp-json\/wp\/v2\/tags?post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}