How can I get the WebDriver version during Testrun? - testing

I am writing on a testframework where the report should include the webdriver version of the test run. When using selenium there is the getEval("Selenium.version") method. But I find no way to read the version when using webdriver. Does anyone know a solution?

It's possible by reading the VERSION.txt properties file. This seems hacky, but it's what the WebDriver developers do in SeleniumServer.java:
final Properties p = new Properties();
p.load(getSeleniumResourceAsStream("/VERSION.txt"));
String rcVersion = p.getProperty("selenium.rc.version");
String rcRevision = p.getProperty("selenium.rc.revision");
String coreVersion = p.getProperty("selenium.core.version");
String coreRevision = p.getProperty("selenium.core.revision");
BuildInfo info = new BuildInfo();
String versionString = String.format("v%s%s, with Core v%s%s. Built from revision %s",
rcVersion, rcRevision, coreVersion, coreRevision, info.getBuildRevision());
Note that this requires a static import:
import static org.openqa.selenium.browserlaunchers.LauncherUtils.getSeleniumResourceAsStream;

Actual path to file with version in selenium is:
/META-INF/maven/org.seleniumhq.selenium/selenium-java/pom.properties
Properties p = new Properties();
p.load(LauncherUtils.class.getResourceAsStream("/META-INF/maven/org.seleniumhq.selenium/selenium-java/pom.properties"));
p.getProperty("version");`

Related

Issues Faced while saving one pdf file content into another pdf file using JMeter

I am using Beanshell sampler to save one pdf file content into another pdf file.
In Beanshell sampler I have put this following code:
FileInputStream in = new FileInputStream("C:\\Users\\Dey\\Downloads\\sample.pdf");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
for (int i; (i = in.read(buffer)) != -1; ) {
bos.write(buffer, 0, i);
}
in.close();
byte[] extractdata = bos.toByteArray();
bos.close();
vars.put("extractdata", new String(extarctdata));
using beanshell post processor I saved this variable ${extractdata} in another pdf file .
file is generated but when open the file it's empty means there is no content showing.
So , can someone please tell me how to resolve this issue ?? is there anything wrong in above code snippet ?? please guide me.
You made a typo
byte[] extractdata = bos.toByteArray();
and
vars.put("extractdata", new String(extarctdata));
so your test element is silently failing, check jmeter.log file it should contain some errors.
It's not possible to state what else is wrong because we don't see your Beanshell Post-Processor code, most probably there is an issue with encoding when converting the byte array to string and vice versa.
So I would suggest skipping this step and using vars.putObject() function instead like:
vars.put("extractdata", extractdata);
and then
byte [] extractdata = vars.getObject("extractdata");
If you just need to copy the file you can use the following snippet:
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
Path source = Paths.get("C:\\Users\\Dey\\Downloads\\sample.pdf");
Path target = Paths.get("/location/for/the/new/file.pdf")
Files.copy(source, target);
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy for scripting so you should switch to Groovy, in this case you will be able to do something like:
new File('/location/for/the/new/file.pdf').bytes = new File('C:\\Users\\Dey\\Downloads\\sample.pdf').bytes
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

How to disable SmartScreen (safebrowsing in edge) on C# Selenium Edge Chromium?

I'm trying to run some selenium C# end-to-end tests on Edge Chromium browser. One of the tests does a download check, basically it downloads a xml file and check whether it exists in the downloaded location.
I'm using Microsoft.Edge.SeleniumTools EdgeOptions to construct options for the EdgeDriver.
But the issue right now is that Edge blocks downloads.
Tried different sorts of things but none of them worked.
Same issue can be solved on Chrome by disabling "safebrowsing" on UserProfilePreferences in ChromeOptions.
I know for a fact that SmartScreen does the blocking, if that is so is there any profile preference that I can use to disable SmartScreen ?
Or any other workaround to force download without the block would be very helpful.
For testing purposes, I suggest you create HashMap objects and try to set Edge preferences like below.
static void Main(string[] args)
{
HashMap<String, Object> edgePrefs = new HashMap<String, Object>();
edgePrefs.put("profile.default_content_settings.popups", 0);
edgePrefs.put("profile.default_content_setting_values.notifications", 2);
edgePrefs.put("profile.default_content_setting_values.automatic_downloads" , 1);
edgePrefs.put("profile.content_settings.pattern_pairs.*,*.multiple-automatic-downloads",1);
var options = new EdgeOptions();
egdeOptions.setExperimentalOption("prefs",edgePrefs);
options.UseChromium = true;
options.BinaryLocation = #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"; // Here add the Edge browser exe path.
var driver = new EdgeDriver(#"Edge_driver_path_here...", options); // Here modify the selenium web driver path.
driver.Navigate().GoToUrl("http://website_URL_here...");
driver.FindElementById("lnk1").Click();
}
If the issue persists then I suggest you set the default download directory like below.
options.AddUserProfilePreference("download.default_directory", #"D://Folder1");
See whether it help to download the file.
I was trying to find the answer with the usage of W3C WebDriver Protocol, but it seems like the only possible way is to turn off XML Edge SmartScreen policies using Windows Registry:
public void SetEdgeXmlDownloadPolicy()
{
var keyName = #"HKEY_CURRENT_USER\Software\Policies\Microsoft\Edge\ExemptDomainFileTypePairsFromFileTypeDownloadWarnings";
var valueName = "AllowXmlDownload";
var valueData = #"{""domains"": ["" * ""], ""file_extension"": ""xml""}";
var currentValue = Registry.GetValue(keyName, valueName, string.Empty).ToString();
if (currentValue == string.Empty || !currentValue.Contains("xml"))
Registry.SetValue(keyName, valueName, valueData, RegistryValueKind.String);
}
Credits to this workaround goes to IndianCodeMaster

ExtentHtmlReporter can't create the report.html

Please help!!
I try to use the ExtentHtmlReporter to create a costume report name like "MyReport.html" but it generate an "index.html" file instead.
By the way I'm using ExtentReports 4.1.0. and C# in VS 2019.
Here is my code
//var htmlReporter = new ExtentHtmlReporter("C:\\DevEnvironment\\MyReport.html");
var htmlReporter = new ExtentHtmlReporter(#"C:\DevEnvironment\MyReport.html");
htmlReporter.Config.Theme = Theme.Standard;
htmlReporter.Config.DocumentTitle = "My Test Report";
htmlReporter.Config.ReportName = "Positive and Negative Test";
_extent.AddSystemInfo("Environment", "OS Widows");
_extent.AddSystemInfo("User Name", "Qlee");
_extent.AttachReporter(htmlReporter);
Thanks for your help.
This is the expected behavior with the version4 HtmlReporter. It creates upto 4 files depending upon the attributes that are created. This is also true for all new version4 reporters, to maximize performance and obviously to keep each file focused on its specific tasks.
If you would like the old behavior, use the version3 port of HtmlReporter:
var v3html = new ExtentV3HtmlReporter()

OutputType<X> is not getting resolved in Webdriver

I have below code:
TakesScreenshot sc = (TakesScreenshot)driver; File srcfile =
sc.getScreenshotAs(OutputType);
Here the Output is not getting resolved to a type.
Can anyone guide as to how to resolve this.
getScreenshotAs(); takes parameter value of a OutputType.
You should mention a OutputType among these available options FILE,BYTES or BASE64 as mentioned in OutputType<T> interface
Change your code to:
TakesScreenshot sc = (TakesScreenshot)driver;
File srcfile = sc.getScreenshotAs(OutputType.FILE);

Visual Studio 2015 Selenium C# 'Using' Library NOT Found

OpenQA.Selenium.Support.UI.SelectElement NOT Found
As you can see by the code image, I have entered the 'using' library I need to use. However, it is telling me that "SelectElement" does not exist. Does anyone here know how to go about adding the correct library?
By clicking the above link, you will see the code image.
Here is the code snippet:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Support.UI.SelectElement;
using NUnit.Framework;
namespace ToolsQA.Selenium_Basics
{
class DropDownAndSelectOperations
{
[Test]
public void Test()
{
// Create a new instance of the Firfox Driver
IWebDriver driver = new FirefoxDriver();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.
FromSeconds(10);
// Launch the URL
driver.Url = "http://toolsqa.wpengine.com/automation-practice-
form";
// Step 3: Select "Continents" drop down (Use Id to identify the
element)
// Find "Select" element of "Single Selection" using Id locator.
*SelectElement* oSelection = new
SelectElement(driver.FindElement(By.Id("continents")));
You need to add the Selenium Support package through NuGet. That should solve the problem.