How to add dynamic fields in Angular 6

  • FormArray is one of the three basic building blocks to define forms in angular along with FormGroup, FormControl.
  • It works similar to FormGroup, where a FormArray status depends upon all its children status. That is if any one FormControl in FormArray is invalid then the status of the entire array becomes
  • A FormArray can hold any instances either it can be FormGroup, FormControl (or) even other
  • This is mostly used for adding dynamic controls in Reactive Forms.

Step1: Create a component

File: FormComponent.ts

Step2: Create a template

File: template.html

Step3: Adding FormsComponent in AppModule

File: app.module.ts

Step4: Bootstraping AppModule

File: main.ts

Step5: Creating Startup file. Add the required files for bootstrap in your directory.

File: index.html

Output:

Entry with Custom Border in Xamarin Forms

Introduction:

In Xamarin Forms Entry control allows a single line of text to be edited. This article demonstrates how to create a custom renderer for the Entry control, enabling developers to override the default native rendering with their own platform-specific customization.

Custom Renderer:

  1. This sample demonstrates a custom renderer for the Entry control, “Enabling developers to override the default native rendering” with their own platform-specific customization.
  2. Custom renderers provide a powerful approach for customizing the appearance and behavior of Xamarin Forms controls. They can be used for small styling changes or sophisticated platform-specific layout and behavior customization.

 

Step1: Create the Mobile App (Xamarin Forms) Project

Open VisualStudio 2017 à File à New à Project à Choose Cross-Platform Template à Choose MobileApp (Xamarin.Forms )à Name it as EntryLineWithanyColorà Click on OKà Chose .NetStanderdà Click OK

 

Step2: Creating CustomEntry.cs

Go to Project EntryLineWithanyColorà Right Click àAdd Class CustomEntry.cs

File Name: CustomEntry.cs

A custom Entry can be created by subclassing the Entry control, as shown in the following code

The CustomEntry control is created in the .NET Standard library project and is simply  ENTRY control. Customization of the control will be carried out in the custom renderer, so no additional implementation is required in the CustomEntry control.

 

Step 3:  Create a class in the Android directory and name it as CustomRenderer.cs

Go to EntryLineWithanyColor.Android à Right Click àAdd Class CustomRenderer.cs

 

File Name: CustomRenderer.cs

Brief Explanation of the above Code:

Here Added the ASSEMBLY attribute it means like declarations

  • CustomEntry is the name of the placeholder class in your common (PCL or Shared) Forms library.
  • ExportRenderer is the name of the actual platform specific implementation class in your iOS/Android/WP project.

Essentially, telling Forms, “when you need to render CustomEntry on Platform X, use the class CustomRenderer.”

  1. Create a subclass of the EntryRenderer class that renders the native control.
  2. Override the OnElementChangedmethod that renders the native control and write logic to customize the control. This method is called when the corresponding Xamarin Forms control is created.
  3. Added an ExportRendererattribute to the custom renderer class to specify that it will be used to render the Xamarin Forms control. This attribute is used to register the custom renderer with Xamarin Forms.

 

 

Step 4: Create UI for Border less Entry 

File Name: MainPage.xaml

Here for Example I have taken Login Form for better Understand

Here we have to declare the Local Refernce nameSpace in MainPage.xaml

 

 

Output: Run the program Ctrl+F5

 

Deploy ASP.NET MVC + Angular 4 + PostgreSQL into AWS

Hello guys hope you are doing good 🙂

From the past few days I was suffering to deploying my ASP.NET MVC application integrated with Angular 4 + PostgreSQL DB into AWS. After my serious deliberation I’ve goto know the procedure and wanted my friends to know about this. That might help you in future.

Step1: Create Elastic Beanstalk web application in AWS

  • Once you login into your account you can find the “Build a solution” section below
  • Choose on Build a web app

  • To create a new Application click on Create New Application, and fill the following required fields Application Name & Platform (.Net). And click on “Create application” button which will start creating the application

 

  • Once application is created with Environments, then you must be able to see HealthGreen

  • Now make sure that the user which is going to be used has the following permissions.

 

Step2: Create RDS (Postgres) in AWS

  • Go to RDS service, and choose PostgreSQL from Step1

 

  • Click on Next, in Step2 choose your case Production (or) Dev / Test
  • Provide the required details
    1. DB instance Class (1GB/ 2GB/…..)
    2. DB Instance Name
    3. Master Username & Password
  • Now make sure that your instance is publicly accessible – Yes, if not click on Modify in Details Section. And choose Public accessible – Yes. If it is not public accessible we will be not able to access this Database in PgAdmin.

 

Step3: Deploy the application into AWS

  • Firstly we need to install “AWS toolkit for Visual Studio 2017”. Once installed you can see the option “Publish to AWS Elastic Beanstalk” on right click the project.
  • Select “Publish to AWS Elastic Beanstalk”, it ask you to create Account Profile.
  • To get the Access Key Id & Secret Access Key, Go to IAM in AWS Console.
  • Select the user, then go to “Security Credentials”, where we can create the Access Key.

 

  • Once you create a new Access key, it gives you Access Key ID & Secret Access Key. Make sure to store your Secret Access Key in a secured place.
  • Now go back to VS 2017 and enter your credentials.
  • Now you can see the Web App we have created in AWS Console.
  • Now Go to View  Open AWS Explorer  Amazon EC2  Key Pairs  Create key pair

 

  • Creating a new Key Pair, will give you a <Key Pair Name>.pem
  • Select “Publish to AWS Elastic Beanstalk”, after selecting profile click on Next.
  • In the Application Options section add the key value pair. And click Next
  • Now click Deploy

 

Step4: Check database connections

  • Open PgAdmin4
  • Get the Host Name from the AWS Console  RDS  Instances  Copy the End Point (Host Name)
  • Now create New Server  Enter the Credentials of RDS.
  • Create your tables required for the application.

 

Step5: Install Angular Packages in EC2 instance using Remote Desktop

  • Go to EC2 Service
  • Click on “Instances”
  • Find your instance and right click on it, then choose “Get Windows Password”

  • Now it will ask you to upload “Key Pair Path” Get the <Key Pair Name>.pem file that we have created when deploying the Web App.
  • Once you upload it will generate the Password, make sure to store it a secured directory.
  • Now you can connect to the Remote desktop using that password.
  • Once you have connected go to C:\\inetpub\\wwwroot.
  • Open command prompt for wwwroot directory.
  • Download Node from the https://nodejs.org/en/ .
  • Now in the command prompt type “npm install”, this will install the packages required for angular.

  • Now run the application

 

Round Entry in Xamarin Froms

Introduction:

In Xamarin Forms Entry control allows a single line of text to be edited. This article demonstrates how to create a custom renderer for the Entry control, enabling developers to override the default native rendering with their own platform-specific customization.

Custom Renderer:

  1. This sample demonstrates a custom renderer for the Entry control, “Enabling developers to override the default native rendering” with their own platform-specific customization.
  2. Custom renderers provide a powerful approach for customizing the appearance and behavior of Xamarin Forms controls. They can be used for small styling changes or sophisticated platform-specific layout and behavior customization.

 

 

Step1: Create the Mobile App (Xamarin Forms) Project

Open VisualStudio 2017    File    New    Project    Choose Cross-Platform Template     Choose MobileApp (Xamarin.Forms )    Name it as RoundEntry    Click on OK    Chose .NetStanderd    Click OK

Step2: Creating CustomEntry.cs

Go to Project CustomEntry    Right Click    Add Class CustomEntry.cs

 

FileName:CustomEntry.cs

A custom Entry can be created by sub classing the Entry control, as shown in the following code

The CustomEntry control is created in the .NET Standard library project and is simply  ENTRY control. Customization of the control will be carried out in the custom renderer, so no additional implementation is required in the CustomEntry control.

 

Step2:  Create a class in the Android directory and name it as CustomRenderer.cs

Go to RoundEntry.Android  Right Click   Add Class CustomRenderer.cs

 

 

Brief Explanation of the above Code:

Here Added the ASSEMBLY attribute it means like declarations

  • Custom Entry is the name of the placeholder class in your common (PCL or Shared) Forms library.
  • Export Renderer is the name of the actual platform specific implementation class in your iOS/Android/WP project.

Essentially, telling Forms, “when you need to render Custom Entry on Platform X, use the class CustomRenderer.”

  1. Create a subclass of the EntryRenderer class that renders the native control.
  2. Override the OnElementChangedmethod that renders the native control and write logic to customize the control. This method is called when the corresponding Xamarin Forms control is created.
  3. Added an ExportRendererattribute to the custom renderer class to specify that it will be used to render the Xamarin Forms control. This attribute is used to register the custom renderer with Xamarin Forms.

 

Step 3: Create UI for Round Entry 

File Name: MainPage.xaml

Here for Example I have taken Login Form for better Understand

Here we have to declare the Local Refernce nameSpace in MainPage.xaml

Output: Here we go.. Press Ctrl+F5

Border less Entry in Xamarin Forms

Introduction:

In Xamarin Forms Entry control allows a single line of text to be edited. This article demonstrates how to create a custom renderer for the Entry control, enabling developers to override the default native rendering with their own platform-specific customization.

Custom Renderer:

  1. This sample demonstrates a custom renderer for the Entry control, “Enabling developers to override the default native rendering” with their own platform-specific customization.
  2. Custom renderers provide a powerful approach for customizing the appearance and behavior of Xamarin Forms controls. They can be used for small styling changes or sophisticated platform-specific layout and behavior customization.

 

Step1: Create the Mobile App (Xamarin Forms) Project

Open VisualStudio 2017    File   New   Project   Choose Cross-Platform Template   Choose MobileApp (Xamarin.Forms )   Name it as BorderLessEntry   Click on OK   Choose .NetStanderd   Click OK

 

Step2: Creating CustomEntry.cs

Go to project BorderLessEntry   Right Click   Add Class CustomEntry.cs

File Name: CustomEntry.cs

A custom Entry can be created by subclassing the Entry control, as shown in the following code

The CustomEntry control is created in the .NET Standard library project and is simply an Entry control. Customization of the control will be carried out in the custom renderer, so no additional implementation is required in the CustomEntry control.

 

Step 3: Create a class in the Android directory and name it as CustomRenderer.cs

Go to BorderlessEntry.Android   Right Click   Add Class CustomRenderer.cs

 

File Name: CustomRenderer.cs

Brief Explanation of the above Code:

Here Added the ASSEMBLY attribute it means like Declarations

  • CustomEntry is the name of the placeholder class in your common (PCL or Shared) Forms library.
  • ExportRenderer is the name of the actual platform specific implementation class in your iOS/Android/WP

 

Essentially, telling Forms, “When you need to render CustomEntry on Platform X, use the class CustomRenderer

  1. Create a subclass of the EntryRenderer class that renders the native control.
  2. Override the OnElementChangedmethod that renders the native control and write logic to customize the control. This method is called when the corresponding Xamarin.Forms control is created.
  3. Added an ExportRendererattribute to the custom renderer class to specify that it will be used to render the Xamarin Forms control. This attribute is used to register the custom renderer with Xamarin Forms.

 

Step 4: Create UI for Border less Entry 

File Name: MainPage.xaml

I have taken example as Registration Form for better Understand

Here we have to declare the Local Reference namespace in MainPage.xaml

 

Output: Tadaa, here is the expected output

Pinch and Pan Image in Xamarin Forms

ZoomImage (PINCH and PAN) In Xamarin Forms

Step1: Create the Mobile App (Xamarin Forms) Project

Open VisualStudio 2017    File    New    Project    Choose Cross-Platform Template    Choose MobileApp (Xamarin.Forms )    Name it as ZoomImageApp    Click on OK    Chose .NetStanderd    Click OK

Step2: Creating DoubleExtension.cs

Go to PCF file In ZoomImageApp    Right Click    Add Class DoubleExtention.cs

File Name: DoubleExtensions.cs

Step 3: Creating Pinch & Pan Container

Create a class in the root directory and name it as PinchAndPanContainer.cs

File Name: PinchAndPanContainer.cs

Step 5: Copy any source image to Zoom it.

Go to ZoomimageApp.Android    Resources    Drawable    In my case I’ve taken slip.png

Step 6:  Creating UI for Pinch & Pan Container

File: MainPage.xaml

Output: Tadaaa, Run the program Ctrl+F5

XPath Selenium Selectors

XPath Selenium Selectors

We can find the location of any element on a web page using XML path expressions. The basic syntax for XPath is shown below:

Example = //input[@id=’user-message‘]

Absolute and Relative XPath

Generally, in some test automation engineer interviews, I asked the difference between absolute and relative XPath. Actually, it is the answer is very easy.

Absolute XPath

  • It is a direct way to locate an element.
  • It is very brittle.
  • Starts with single slash “/” that means starting to search from the root.

Example: /html/body/div[2]/div/div[2]/div[1]/div[2]/form/div/input

Relative XPath

  • Starts from the middle of the HTML DOM.
  • Starts with a double slash “//” that means it can start to search anywhere in the DOM structure.
  • Shorter than Absolute XPath.
  • Less fragile.

Example: //div[@class=’form-group’]//input[@id=’user-message’]

Example: //*[@class=’panel-body’]//li[contains(text(),’entered in input field’)]

Writing Smart XPaths for Complex and Dynamic Elements

1) Writing XPath with Tag & Attribute & Value Trio

Example: //input[@id, ‘user-message’]

Examples:

2) Writing XPath with contains()

It is very handy XPath Selenium locator and sometimes it saves the life of a test automation engineer. When an attribute of an element is dynamic, then you can use contains() for the constant part of the web element but also you can use contains() in any condition when you need.

Example: //input[contains(@id, ‘er-messa’)]

Examples:

3) Writing XPath with starts-with

This method checks the starting text of an attribute. It is very handy to use when the attribute value changes dynamically but also you can use this method for non-changing attribute values.

Example: //input[starts-with(@id, ‘user’)]

4) Writing XPath with Chained XPaths Declerations

We can chain multiple relative XPath declarations with “//” double slash to find an element location as shown below.

Example: //div[@class=’form-group’]//input[@id=’user-message’]

5) Writing XPath with “and Statement

In this method, we use two interrogation conditions such as A and B and return a result-set as shown below:

Example: //*[@id=’user-message’ and @class=’form-control’]

6) Writing XPath with text()

We can find an element with its exact text.

Example: .//label[text()=’Enter message’]

 

$emit, $broadcast, $on – Part2

$emit: It dispatches an event name upwards through the scope hierarchy and notify to the registered $rootScope.Scope listeners. The event life cycle starts at the scope on which $emit was called. The event traverses upwards toward the root scope and calls all registered listeners along the way. The event will stop propagating if one of the listeners cancels it.

$broadcast: It dispatches an event name downwards to all child scopes (and their children) and notify to the registered $rootScope.Scope listeners. The event life cycle starts at the scope on which $broadcast was called. All listeners for the event on this scope get notified. Afterwards, the event traverses downwards toward the child scopes and calls all registered listeners along the way. The event cannot be canceled.

$on: It listen on events of a given type. It can catch the event dispatched by $broadcast and $emit.

  • And now creating the script, here myController is the controller which is going to emit/broadcast an event with some arguments.
  • parentController1, parentController2 will listen to event which is dispatched from myController by $broadcast.
  • childController1, childController2 will listen to event which is dispatched from myController by $emit.

 

output

  • In this example we have used $scope context to $emit/$broadcast the events, and $on has listened all the events by using $scope.$on().
  • Now if we have used $rootscrope context to $emit/$broadcast, it will not work same as that works with $scope.
  • Because $rootscope is the parent scope and it doesn’t have any parent, when we emit using $rootscope.$emit(), only $rootscope.$on() can listen to that events. Whereas when we broadcast using $rootscope.$broadcast(), all the $rootscope.$on() and $scope.$on() can listen to that event.

 

 

Cancelling Events:

Canelling event is possible when event is emitted, but we cannont cancel the event when it is broadcasted.

  • If the event is dispatched by using $scope.$emit( ) then any of the $rootscope/$scope listeners can cacel it.
  • If the event is dispatched by using $rootscope.$emit() then any of the $rootscope listeners can cancel it.

$emit, $broadcast, $on – Part1

$emit, $broadcast, $on – Part1

How to use $rootScope:

As we know that $rootScope is the parent for $scope, to override the $rootScope we need to re-initialize the $rootScope variable with $scope

Let us see an example

In this example we have injected $rootScope in both parent and child controllers.

As $rootScope variables will be available throughout the application we can now access the $rootScope variable anywhere in the application by just injecting the $rootScope

Output:

  • Now if we remove the $rootScope from Parent and initialize it in child controller, it works same.

Output:

How to pass data from parent controller to child

To pass the data from Parent Controller to Child, we need to extract parent controller $scope variable using $parent.

Example: In this example we will use only $scope.

How to pass data from child controller to parent

To pass data from child to parent controllers using $scope we don’t have $child to take from child controller. But here I’ll show you one of the possible way to transfer data.

  • In child controller initialize the empName in an object as $scope.employee.empName.
  • In parent controller declare an empty object naming with same object as $scope.employee = {}

Output:

$emit, $broadcast, $on – Part2

Automation Test Life Cycle

Once you start automating test script you will get this work often. We talk about life cycle it mean end to end picture of that scenario, like we have a life cycle for development, for manual testing similarly we have in Automation as well. Today in this post we will discuss Automation test life cycle in short ATLC.

You all must be familiar with SDLC ( Software development life cycle ), STLC ( Software test life cycle ), so lets discuss ATLC ( Automation test life cycle ).

Please refer  below image is the ATLC (Automation test life cycle diagram)

Automation test life cycle has 6 section

1- Automation feasibility analysis

2- Test Plan/Test Design

3- Environment Setup/Test lab setup

4-Test Script development/ Automation test case development

5-Test script execution

6- Generate test result / Analyses of  result

 

Lets start  each of the phase of Automation test life cycle

1- Automation feasibility analysis

  • The main objective of this phase will be to check feasibility of automation. 
  • Which test case can be automated and how we can automate them.
  • Which module of your application can be tested and which can not be automated
  • Which tools we can use for our application (like Selenium, QTP, Sahi, OATS, Telrik etc) and which tools will be best of our application
  • Take following factors into consideration like Team size, Effort and cost involved for tools which we will use.

2- Test Plan/Test Design

  • In this phase you have to create a Test plan by considering below point into considerations.
  • Fetch  all the manual test case from test management tool that which TC has to automate.
  • Which framework to use and what will be advantage and disadvantage  of the framework which we will use.
  • Create a test suite for Automation test case in Test Management tool.
  • In test plan you can mention background, limitation, risk and dependency between application and tools.
  • Approval from client/ Stack holders.

3- Environment Setup/Test lab setup 

By name itself you can understand that we need to setup machine or remote machine where our test case will execute.

  • In this section you can mention how many machine you want.
  • What should be the configuration in terms of hardware and software

4- Test Script development/ Automation test case development

In this phase you have to start develop automation script and make sure all test script is running fine and should be stable enough.

  • Start creating test script based on your requirement
  • Create some common method or function that you can reuse throughout your script
  • Make your script easy, reusable,well structured and well documented so if third person check your script then he/she can understand your scripts easily.
  • Use better reporting so in case of failing you can trace your code
  • Finally review your script and your script should be ready before consumption.

5 – Test script execution
Now its time for execution of test scripts, in this phase you have to execute all your test script.
Some points to remember while execution

  • Your script should cover all the functional requirement as per test case.
  • Your script should be stable so it should run in multiple environment and multiple browsers (depends on your requirement)
  • You can do batch execution also if possible so it will save time and effort.
  • In case of failure your script should take screen shots.
  • If test case is failing due to functionality, you have to raise a bug/defect.

 6- Generate test result / Analyses of  result

This is the last phase of Automation test life cycle in which we will gather test result and will share with team/client/stack holders.

  • Analyze the output and calculate how much time it take to complete the testcase.
  • You should have good report generation like XSLT report, TestNG report, ReporterNG etc.