Disable and Enable Features Using Dism

Dism- Deployment Image Servicing and Management used to service a windows image (.wim) or a virtual hard disk. It can be also used to enable and disable features in windows.

Start the cmd as administrator and supply below commands-

#It gives the list of all features

C:Windows\system32>Dism /online /Get-Features

#It enable the feature

C:Windows\system32>Dism /online /Enable-Feature /FeatureName:<FeatureName> /All


#It disable the feature

C:Windows\system32>Dism /online /Disable-Feature /FeatureName:<FeatureName>


Reading and Writing Text File using PowerShell

Here I am listing some of the common cmdlets which help to operate with text file-

How to create text file using PowerShell?
New-Item <File Path>
How to open text file or any folder sturcture using PowerShell?
Invoke-Item <File Path>
How to add or append contents in text file using PowerShell?
Add-Content <File Path> Text with single quote
How to clear contents in text file using PowerShell?
Clear-Content <File Path>
How to clear contents and add new contents in text file using PowerShell?
Set-Content <File Path> Text with single quote
How to read file contents using PowerShell?
Get-Content <File Path>
How to save cmdlets outputs directly to text file?
Cmdlets | Out-File <File Path>. Example: Get-Process | Out-File D:\PowerShell
How to remove text file using PowerShell?
Remove-Item <File Path>

How to create generation 2 virtual machine using PowerShell?

Below script would help to create virtual machine in Hyper-V using PowerShell-

  1. Open PowerShell window as admin.
  2. Paste below script and hit enter.
  3. VM would be created.
  4. Open Hyper-V Manager and verify it.

# Set VM Name, Switch Name, and Installation Media Path.
$VMName = ‘TestVM’
# Switch is nothing but network adapter
$Switch = ‘My New Virtual Switch’
#OS Iso file should be assigned to InstallMedia
$InstallMedia = ‘D:\Softwares\en_windows_10_enterprise_version_1607_updated_jul_2016_x64_dvd_9054264.iso’

# Create New Virtual Machine
# MemoryStartupBytes contents the RAM size of VM.
# NewVHDSizeBytes contents the size of HD.
New-VM -Name $VMName -MemoryStartupBytes 1073741824 -Generation 2 -NewVHDPath “C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\$VMName.vhdx” -NewVHDSizeBytes 53687091200 -Path “C:\ProgramData\Microsoft\Windows\Hyper-V\$VMName” -SwitchName $Switch

# Add DVD Drive to Virtual Machine
Add-VMScsiController -VMName $VMName
Add-VMDvdDrive -VMName $VMName -Path $InstallMedia

# Mount Installation Media
$DVDDrive = Get-VMDvdDrive -VMName $VMName

# Configure Virtual Machine to Boot from DVD
Set-VMFirmware -VMName $VMName -FirstBootDevice $DVDDrive

Extension Method in Selenium, what, why, and how???

An Extension Method enable us to add methods to existing   types without creating a new derived type, recompile, or modify the original types.

Alright, confusing???


Now consider you don’t have access for Car class and if I ask you to add a method for Car class, how would you do that?

In this kind of circumstances you can use Extension method concept to add a method for existing type without creating new class.


If I ask you write a program which should give today date, probably you would write below lines of code-


Now if I ask you to give 1 month back date, probably you would write below method to get 1 month back date-


Certainly you would write this method in a class and to call this method you would create object.


How it would be if you get same method like this-


You can achieve above line of code using Extension Method concept.


Now you will see your extension method in below manner-


OK, there are some rules also-

  • It should be static method.
  • It must be located in a static class.
  • It should use the “this” keyword as the first parameter with a type in .NET and this method will be called by a given type instance on the client side.
  • An extension method should be in the same namespace as it is used or you need to import the namespace of the class by a using statement.
  • You can give any name for the class that has an extension method but the class should be static.
  • If you want to add new methods to a type and you don’t have the source code for it, then the solution is to use and implement extension methods of that type.


Now you will see your selenium extension method in below manner-


Alright, now we will see a real time example-

While automating an application sometimes we all observed that click action performs the operation but button does not get clicked.

In that scenario, mostly we write different line of codes or methods to achieve our goal.

So instead of writing code each time for specific click, we can write different extension methods to handle all possible click actions and if one click is not working out we can call another IWebElement click methods (Extension Method).

It’s a right approach in any Automation framework to keep extension methods to perform the similar kind of actions using different ways.


How to identify Windows ToolBar using CodedUI

Below code will help to click on buttons on tool bar which generally comes when we try to login into the application or try to download any file from the application.

As first action we do on the webpage so first we have to identify the webpage and then tool bar which pop-ups after performing the some actions. We have to use WinToolBar class to identify Tool Bar. So here you go-

BrowserWindow MainWin = new BrowserWindow();
MainWin.SearchProperties[BrowserWindow.PropertyNames.Name] = “Page Title Name”;
WinToolBar ToolStrip = new WinToolBar(MainWin);
ToolStrip.SearchProperties[WinToolBar.PropertyNames.Name] = “Notification”;
WinButton No= new WinButton(ToolStrip);
No.SearchProperties[WinButton.PropertyNames.Name] = “No”;



Difference between @Factory and @DataProvider annotations

Both the annotations belong to TestNg testing framework. Many people get confused while reading about these two annotations that why and where we have to use these two?

Very basic difference between these two are-

@DataProvider- DataProvider annotations parameterize the particular test method and execute the test number of times based on data provided by DataProvider method. So if two parameters are there then test will execute twice.

@Factory- Factory executes all the test methods present inside any test class file using separate instance of the respective class.

Still confused???

Let’s have look on some programs-

public Object[][] message(){
return new Object [][]{{“Mayank” , new Integer (321)}, {“Dileep”, new Integer (282)}};

@Test (dataProvider=”message”)
public void PrintMsg(String name, Integer id){
System.out.println(“Names are: “+name+” “+id);

As above program states that there are two data and if I run this program result will be-


So, it proves that if you increase the number of data in message method, PrintMsg method will execute same number of times.

Now we will see Factory and how it is different from DataProvider-

public class TestFactory {
public Object[] factorymethod(){
return new Object[]{new DPandFactoryExaple(), new DPandFactoryExaple()};

public class DPandFactoryExaple {
public Object[][] message(){
return new Object [][]{{“Mayank” , new Integer (321)}, {“Dileep”, new Integer (282)}};
@Test (dataProvider=”message”)
public void PrintMsg(String name, Integer id){
System.out.println(“Names are: “+name+” “+id);
public void PrintSuccessfullMessage(){
System.out.println(“Print the successfull message”);

So if we see DPandFactoryExaple class then you will find there are two @Test methods and 1 @Test method has to execute twice and 1 @Test method has to execute once. So there should be 3 messages.

Now if you see @Factory method it is calling the same class twice and in that case there should be 6 messages. See the results below-


So did it clear the doubts?? No, then comment it out we will discuss it.


How to run Selenium + TestNG script from Command Line?

This is an alternate way to execute our selenium script from command prompt. Here, I am considering few points-

  • Your project is already set-up in Eclipse
  • Project already has testng.xml file.
  • All selenium and other third party jar files are located under project home folder (lib folder).
  • You are able to execute your script by running testng.xml file.


If above conditions are matching then very few steps are there to execute same script from command prompt. Follow the below steps-

Open Command Prompt and Go to Project home directory-


Set the class path and libraries path by running below command-

set classpath=<Project Home Path>\bin;<Project Home Path>\lib\*


Now run the testng.xml file by running below command-

java org.testng.TestNG testng.xml—-Make sure “org.testng.TestNG” TestNG word should have ‘T’ and ‘NG’ in caps.


I hope it would help people to run testng.xml file from the command prompt.