There are more connected devices than ever before as IoT (Internet of Things) technology is gaining traction. IoT testing is conducted to test IoT technology based devices. The various types of testing for IoT systems are as follows:
Usability Testing – To test the usability of an IoT system
Compatibility Testing – To check the compatibility of devices in IoT system
Reports play a fundamental role when it comes to TESTING. Tester can now know the real-time reports of test suit execution. Reports made ease to know the ratio of Pass? Or Fail? Post-test suit execution and it is the only documentation to know about test execution results.
Everyone wish to see the detailed description of the test results. Don’t you? here is the solution for it. And, let us see how these reports can be achieved? in Selenium C# – NUnit framework automation testing.
To achieve detailed test execution results as HTML reports we need to rely on third party tool called => Extent Reports. These reports provide decent narration of test execution results and are depicted in PIE chart.
How to Reference Extent Reports in MS Visual Studio
Extent Reports can be directly referenced via NuGet Gallery:
Step 1) Project> Manage NuGet Packages
Step 2) In the next window
Search for ExtentReports
Select the search result
Click Install
Step 3) Install selenium support from NuGet package
Step 3) Click ‘I Accept’
Step 4)Create a new C# class with the below code for Extent Reports.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit;
using AventStack.ExtentReports.Reporter;
using AventStack.ExtentReports;
using System.IO;
namespace RnD
{
[TestFixture]
public class TestDemo1
{
public IWebDriver driver;
public static ExtentTest test;
public static ExtentReports extent;
[SetUp]
public void Initialize()
{
driver = new ChromeDriver();
}
[OneTimeSetUp]
public void ExtentStart()
{
extent = new ExtentReports();
var htmlreporter = new ExtentHtmlReporter(@"D:\ReportResults\Report" + DateTime.Now.ToString("_MMddyyyy_hhmmtt") + ".html");
extent.AttachReporter(htmlreporter);
}
[Test]
public void BrowserTest()
{
test = null;
test = extent.CreateTest("T001").Info("Login Test");
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://testing-ground.scraping.pro/login");
test.Log(Status.Info, "Go to URL");
//provide username
driver.FindElement(By.Id("usr")).SendKeys("admin");
//provide password
driver.FindElement(By.Id("pwd")).SendKeys("12345");
try
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(1));
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//h3[contains(.,'WELCOME :)')]")));
//Test Result
test.Log(Status.Pass, "Test Pass");
}
catch (Exception e)
{
test.Log(Status.Fail, "Test Fail");
throw;
}
}
[TearDown]
public void closeBrowser()
{
driver.Close();
}
[OneTimeTearDown]
public void ExtentClose()
{
extent.Flush();
}
}
}
Post running test method, the test execution report looks as shown below:
Step 3) The below screen will be displayed once the project is successfully created.
Set up Visual Studio with Selenium WebDriver:
Step 1) Navigate to Project-> Manage NuGet Packages
Step 2) In the next screen
Search for Selenium on the resultant screen
Select the first search result
Click on ‘Install’
Step 3) The below message will be displayed once the package is successfully installed
Steps to install NUnit Framework:
Step 1) Navigate to Project-> Manage NuGet Packages
Step 2) In the next window
Search for NUnit
Select the search result
Click Install
Step 3) The below message will appear once the installation is complete.
Steps to download NUnit Test Adapter
Please note that the below steps work only for 32-bit machines. For 64-bit machines, you need to download the ‘NUnit3 Test Adapter’ by following the same process as mentioned below.
Step 1) Navigate to Project-> Manage NuGet Packages
Step 2) In the next window
Search NUnitTestAdapter
Click Search Result
Click Install
Step 3) Once install is done you will see the following message
Steps to download Chrome Driver
Step 1) Navigate to Project-> Manage NuGet Packages
Step 2) In the next window
Search for Chromdriver
Select the search result
Click Install
Step 3) System may asked for permission. Click on ‘Yes to All’
Step 4) The below message will appear once the installation is complete.
Selenium and NUnit framework:
Selenium with NUnit framework allows differentiating between various test classes. NUnit also allows using annotations such as SetUp, Test, and TearDown to perform actions before and after running the test.
NUnit framework can be integrated with Selenium by creating a NUnit
test class and running the test class using NUnit framework.
The below are the steps needed to create and run a test class using NUnit framework.
Steps to create a NUnit Test class in Selenium:
Step 1) In the Solution Explorer, Right clicked on project > Add > Class
Step 2) Class creation window will appear
Provide a name to the class
Click on Add button
Step 3) The below screen will appear.
Step 4) Add the following code to the created class. Please note that you need to specify the location of ‘chromdriver.exe’ file during chrome driver initialization.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit;
namespace RnD
{
[TestFixture]
public class TestDemo1
{
public IWebDriver driver;
[SetUp]
public void Initialize()
{
driver = new ChromeDriver();
}
[Test]
public void BrowserTest()
{
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://www.google.com/");
}
[TearDown]
public void closeBrowser()
{
driver.Close();
}
}
}
Step 4) Click on ‘Build’ -> ‘Build Solution’ or keypress ‘Ctrl + Shift + B’
Step 5) Once the build is successful, we need to open the Test Explorer window. Click on Test -> Windows -> Test Explorer
Step 6) Test Explorer window opens with the list of available tests. Right-click on Test Explorer and select Run Selected Tests
Step 7) Selenium must open the browser with specified URL and close the browser. Test case status will be changed to ‘Pass’ on the Test Explorer window.
If someone wants to search by specific value in database, it’s difficult to search a value whole database. Below code easy way to find out
DECLARE @SearchStr nvarchar(100)
SET @SearchStr = 'test@test.com.au'
CREATE TABLE #Output (TableLocation nvarchar(370), Details_Information nvarchar(3630))
SET NOCOUNT ON
DECLARE @SearchTableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @SearchTableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
WHILE @SearchTableName IS NOT NULL
BEGIN
SET @ColumnName = ''
SET @SearchTableName =
(
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @SearchTableName
AND OBJECTPROPERTY(
OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
), 'IsMSShipped'
) = 0
)
WHILE (@SearchTableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
BEGIN
SET @ColumnName =
(
SELECT MIN(QUOTENAME(COLUMN_NAME))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = PARSENAME(@SearchTableName, 2)
AND TABLE_NAME = PARSENAME(@SearchTableName, 1)
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar', 'int', 'decimal')
AND QUOTENAME(COLUMN_NAME) > @ColumnName
)
IF @ColumnName IS NOT NULL
BEGIN
INSERT INTO #Output
EXEC
(
'SELECT ''' + @SearchTableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) FROM ' + @SearchTableName + ' (NOLOCK) ' +
' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
)
END
END
END
SELECT TableLocation, Details_Information FROM #Output
DROP TABLE #Output
SELECT [rs].[destination_database_name],
[rs].[restore_date],
[bs].[backup_start_date],
[bs].[backup_finish_date],
[bs].[database_name] as [source_database_name],
[bmf].[physical_device_name] as [backup_file_used_for_restore]
FROM msdb..restorehistory rs
INNER JOIN msdb..backupset bs
ON [rs].[backup_set_id] = [bs].[backup_set_id]
INNER JOIN msdb..backupmediafamily bmf
ON [bs].[media_set_id] = [bmf].[media_set_id]
ORDER BY [rs].[restore_date] DESC
A CSV file is a comma-separated file, that is used to store data in an organized way.
Data.csv
A,B,C
Example
using System;
using System.IO;
using System.Collections.Generic;
class Program
{
public static void Main()
{
string FilePath = @"C:\Sample\Data.csv";
StreamReader reader = null;
if (File.Exists(FilePath))
{
reader = new StreamReader(File.OpenRead(FilePath));
List<string> listData = new List<string>();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
foreach (var item in values)
{
listData.Add(item);
}
foreach (var row1 in listData)
{
Console.WriteLine(row1);
}
}
}
else
{
Console.WriteLine("File doesn't exist");
}
Console.ReadLine();
}
}