- Create a Coded UI Test Project in Visual Studio.
- Window will pop up for recording the Coded UI or generate for MTM close it.
- Now go to the test method and start writing the code.
In my scenario i am writing a coded ui hand code for adding items to the cart and check out for "Tailspin Toys Application"
[TestMethod]
public void CodedUITestMethod1()
{
// Select the browser type Launch
BrowserWindow.CurrentBrowser = "IE";
//launch the browser and browse the application URL
BrowserWindow Scenario1 = BrowserWindow.Launch("http://localhost:8001");
//Maximise the window
Scenario1.Maximized = true;
//Define the action for Hyper Link control
UITestControl ModelAirplanes = new UITestControl(Scenario1);
ModelAirplanes.TechnologyName = "Web";
ModelAirplanes.SearchProperties[HtmlHyperlink.PropertyNames.InnerText] = "Model Airplanes";
ModelAirplanes.SearchProperties[HtmlHyperlink.PropertyNames.Href] = "http://localhost:8001/?slug=model";
ModelAirplanes.DrawHighlight();
Mouse.Click(ModelAirplanes);
//Define the action for Hyper Link control
UITestControl Viewplane = new UITestControl(Scenario1);
Viewplane.TechnologyName = "Web";
Viewplane.SearchProperties[HtmlHyperlink.PropertyNames.InnerText] = "View Plane";
Viewplane.SearchProperties[HtmlHyperlink.PropertyNames.Href] = "http://localhost:8001/home/show?sku=modtrr";
Viewplane.DrawHighlight();
Mouse.Click(Viewplane);
//Define the action for Button control
UITestControl addtocart = new UITestControl(Scenario1);
addtocart.TechnologyName = "web";
addtocart.SearchProperties[HtmlButton.PropertyNames.Class] = "add-cart";
Mouse.Click(addtocart);
//Define the action for Button control
UITestControl checkout = new UITestControl(Scenario1);
checkout.TechnologyName = "web";
checkout.SearchProperties[HtmlInputButton.PropertyNames.Class] = "checkout";
checkout.SearchProperties[HtmlButton.PropertyNames.Type] = "button";
Mouse.Click(checkout);
//Define the action for Enter the text control
UITestControl first = new UITestControl(Scenario1);
first.TechnologyName = "web";
first.SearchProperties[HtmlEdit.PropertyNames.Id] = "FirstName";
first.SetProperty("Text","Manu");
//Define the action for Enter the text control
UITestControl last = new UITestControl(Scenario1);
last.TechnologyName = "web";
last.SearchProperties[HtmlEdit.PropertyNames.Id] = "LastName";
last.SetProperty("Text", "Anu");
//Define the action for Enter the text control
UITestControl Email = new UITestControl(Scenario1);
Email.TechnologyName = "web";
Email.SearchProperties[HtmlEdit.PropertyNames.Id] = "Email";
Email.SetProperty("Text", "manuanu@nuvu.com");
//Email.DrawHighlight();
//Playback.Wait(1000);
//Define the action for Enter the text control
UITestControl Street1 = new UITestControl(Scenario1);
Street1.TechnologyName = "web";
Street1.SearchProperties[HtmlEdit.PropertyNames.Id] = "Street1";
Street1.SetProperty("Text", "Amalapuram");
//Define the action for Enter the text control
UITestControl City = new UITestControl(Scenario1);
City.TechnologyName = "web";
City.SearchProperties[HtmlEdit.PropertyNames.Id] = "City";
City.SetProperty("Text", "Chilkalurupeta");
UITestControl country = new UITestControl(Scenario1);
country.TechnologyName = "web";
country.SearchProperties[HtmlComboBox.PropertyNames.Id] = "countrySelect";
Mouse.Click(country);
country.SetProperty("SelectedItem", "USA");
//Define the action for Enter the text control
UITestControl stateSelect = new UITestControl(Scenario1);
stateSelect.TechnologyName = "web";
stateSelect.SearchProperties[HtmlComboBox.PropertyNames.Id] = "stateSelect";
Mouse.Click(stateSelect);
stateSelect.SetProperty("SelectedItem", "Texas");
//Define the action for Enter the text control
UITestControl Zip = new UITestControl(Scenario1);
Zip.TechnologyName = "web";
Zip.SearchProperties[HtmlEdit.PropertyNames.Id] = "Zip";
Zip.SetProperty("Text", "12345");
//Define the action for Button control
UITestControl revorder = new UITestControl(Scenario1);
revorder.TechnologyName = "web";
revorder.SearchProperties[HtmlButton.PropertyNames.Class] = "textbutton";
revorder.FilterProperties[HtmlButton.PropertyNames.Type] = "submit";
Mouse.Click(revorder);
//Define the action for Drop Down control
UITestControl CardType = new UITestControl(Scenario1);
CardType.TechnologyName = "web";
CardType.SearchProperties[HtmlComboBox.PropertyNames.Name] = "CardType";
Mouse.Click(CardType);
CardType.SetProperty("SelectedItem", "MasterCard");
//Define the action for Enter the text control
UITestControl cardno = new UITestControl(Scenario1);
cardno.TechnologyName = "web";
cardno.SearchProperties[HtmlEdit.PropertyNames.Id] = "AccountNumber";
cardno.SetProperty("Text", "0400 8110 8000 1095");
//Define the action for Enter the text control
UITestControl VerificationCode = new UITestControl(Scenario1);
VerificationCode.TechnologyName = "web";
VerificationCode.SearchProperties[HtmlEdit.PropertyNames.Id] = "VerificationCode";
VerificationCode.SetProperty("Text", "040");
//Define the action for Drop Down control
UITestControl ExpirationMonth = new UITestControl(Scenario1);
ExpirationMonth.TechnologyName = "web";
ExpirationMonth.SearchProperties[HtmlComboBox.PropertyNames.Name] = "ExpirationMonth";
Mouse.Click(ExpirationMonth);
ExpirationMonth.SetProperty("SelectedItem", "3");
//Define the action for Drop Down control
UITestControl ExpirationYear = new UITestControl(Scenario1);
ExpirationYear.TechnologyName = "web";
ExpirationYear.SearchProperties[HtmlComboBox.PropertyNames.Name] = "ExpirationYear";
Mouse.Click(ExpirationYear);
ExpirationYear.SetProperty("SelectedItem", "2016");
//Define the action for Button control
UITestControl PlaceOrder = new UITestControl(Scenario1);
PlaceOrder.TechnologyName = "web";
PlaceOrder.SearchProperties[HtmlButton.PropertyNames.Class] = "textbutton";
PlaceOrder.FilterProperties[HtmlButton.PropertyNames.Type] = "submit";
Mouse.Click(PlaceOrder);
Playback.Wait(1000);
}
0 comments:
Post a Comment