Monday, November 19, 2018

Git Tags - what, why, when and how

Git TAGS - What | Why | When | How
Today We will learn: -------------------------------
1. What are tags / releases
2. Why should i create TAGs
3. When to create TAGs
4. How to create TAGs in git

create | show | publish | delete

Step 1:
Checkout the branch where you want to create the tag
git checkout "branch name"
example : git checkout master
________________________________________________________


Step 2:
Create tag with some name
git tag "tag name"
example : git tag v1.0
git tag -a v1.0 -m "ver 1 of .." (to create annotated tags)
________________________________________________________

Step 3:
Display or Show tags
git tag
git show v1.0
git tag -l “v1.*”
________________________________________________________

Step 4:
Push tags to remote
git push origin v1.0
git push origin --tags
git push --tags (to push all tags at once)
________________________________________________________

Step 5:
Delete tags (if required only) to delete tags from local :
git tag -d v1.0
git tag --delete v1.0

to delete tags from remote :
git push origin -d v1.0
git push origin --delete v1.0
git push origin :v1.0
to delete multiple tags at once:
git tag -d v1.0 v1.1 (local)
git push origin -d v1.0 v1.1 (remote)


________________________________________________________

Checking out TAGS

 We cannot checkout tags in git
We can create a branch from a tag and checkout the branch
git checkout -b "branch name" "tag name" example :
git checkout -b ReleaseVer1 v1.0
 ________________________________________________________
Creating TAGS from past commits
git tag "tag name" "reference of commit"
example : git tag v1.2 5fcdb03




source

how to see git log and diff

source
How to see logs and diff in Git

git log --stat


  • git log --stat
to show all where file was changed.
how may lines are modified added or deletion like this.


 new_file.txt | 1 +
 1 file changed, 1 insertion(+)


  • git log -p
You will see like this.
    new added p

diff --git a/new_file.txt b/new_file.txt
index 8646659..b5f7bcb 100644
--- a/new_file.txt
+++ b/new_file.txt
@@ -1 +1,2 @@
 this is new file
+now added p word
\ No newline at end of file


Different between commit 

after change the file , where is changed to show this. you need to check differ.
  • git diff
 $ git diff
diff --git a/new_file.txt b/new_file.txt
index b5f7bcb..7f6d181 100644
--- a/new_file.txt
+++ b/new_file.txt
@@ -1,2 +1,4 @@
 this is new file
-now added p word
\ No newline at end of file
+now added p word
+changed
+another
\ No newline at end of file


Only changes file show

  • git diff --word-diff
$ git diff --word-diff

diff --git a/new_file.txt b/new_file.txt
index b5f7bcb..b11d6b6 100644
--- a/new_file.txt
+++ b/new_file.txt
@@ -1,2 +1,4 @@
this is new file
now {+new+}  added p word
{+changed+}
{+another+}

Fetch and Pull


when you work a branch with team you need checkout branch.
before work or push you need to pull first.

if anyone change their branch you must pull first and then push.

but if you fatch all branch to your repository, you can write 'git fetch origin master'

  • git pull origin master
  • git push origin master

  • git checkout -b dev
  • git checkout -b dev-amirul
  •  
  • git checkout dev
  •  
  • git branch
  • git push origin dev.


















Thursday, November 15, 2018

Host file added windows 10, 8

For Windows 10 and 8
  1. Press the Windows key.
  2. Type Notepad in the search field.
  3. In the search results, right-click Notepad and select Run as administrator.
  4. From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes.
For Windows 7 and Vista
  1. Click Start > All Programs > Accessories.
  2. Right-click Notepad and select Run as administrator.
  3. Click Continue on the Windows needs your permission UAC window.
  4. When Notepad opens, click File > Open.
  5. In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
  6. Click Open.
  7. Make the necessary changes to the file.
  8. Click File > Save to save your changes.
For Windows NT, Windows 2000, and Windows XP
  1. Click Start > All Programs > Accessories > Notepad.
  2. Click File > Open.
  3. In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
  4. Click Open.
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes.

Wednesday, November 14, 2018

laravel project from github setup step by step




1. Pull Laravel/php project from git provider.
 
 
 
2. Rename .env.example file to .env inside your project root and fill the database information. (windows wont let you do it, so you have to open your console cd your project root directory and run mv .env.example .env )
 
windows: copy .env.exmple to .env
 
3.  create database name and set .env file as your phpmyadmin setting.

4. Open the console and cd your project root directory

Run composer install or php composer.phar install
 
 
5. Run php artisan key:generate
6. Run php artisan migrate
7. Run php artisan db:seed to run seeders, if any.
8. Run php artisan serve

Tuesday, November 13, 2018

use back4app.com for parsing data from server very easy







Step 1 - Set up

At the beginning of each Parse activity, import the following:
1
2
3
4
5
6
7
8
9
10
11
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseUser;  


Step 2 - Sign Up

Signing up basically involves saving a new object of class ParseUser, shown as “User” in your app Dashboard, and setting at least two of its pre-defined attributes: username and password. In order to set these attributes, two specific methods of this class are used: ParseUser.setUsername() and ParseUser.setPassword().
The method used for saving the new user on the Dashboard is ParseUser.signUpInBackground(), which may come together with a callback function.
Note: Objects of this special class are not saved on the Dashboard with ParseObject.save() method.
To make SignUpActivity work, follow these steps:
  1. Import into your SignUpActivity, in addition to the dependencies imported in Step 1:
    1
    import com.parse.SignUpCallback;
    
  2. To implement user registration, simply use the following code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ParseUser user = new ParseUser();
    // Set the user's username and password, which can be obtained by a forms
    user.setUsername(<Insert Username Here>);
    user.setPassword(<Insert User Password Here>);
    user.signUpInBackground(new SignUpCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {
                alertDisplayer("Sucessful Sign Up!","Welcome" + <Insert Username Here> + "!");
            } else {
                ParseUser.logOut();
                Toast.makeText(SignUpActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
           }
        }
    });
    
    In the example project, this code is placed inside a SIGN UP button callback.
    Also, username and password are caught using Edit Texts.
  3. It’s interesting to add an additional method to display Alert Dialogs and make the process look more professional. The method below do this:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    private void alertDisplayer(String title,String message){
           AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this)
                   .setTitle(title)
                   .setMessage(message)
                   .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                       @Override
                       public void onClick(DialogInterface dialog, int which) {
                           dialog.cancel();
                           // don't forget to change the line below with the names of your Activities
                           Intent intent = new Intent(SignUpActivity.this, LogoutActivity.class);
                           intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                           startActivity(intent);
                       }
                   });
           AlertDialog ok = builder.create();
           ok.show();
       }
    

Step 3 - Log in

Logging in creates a Session object, which points to the User logged in. If login is successful, ParseUser.getCurrentUser() returns a User object, and a Session object is created in the Dashboard. Otherwise, if the target username does not exist, or the password is wrong, it returns null.
The method used to perform the login action is ParseUser.logInInBackground(), which requires as many arguments as the strings of username and password, and may call a callback function.
Note: After signing up, login is performed automatically.
To make LoginActivity work, follow these steps:
  1. Import into your LoginActivity, in addition to the dependencies imported in the Step 1:
    1
    import com.parse.LogInCallback;
    
  2. To implement user login function, simply use the code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ParseUser.logInInBackground(<Insert Username Here>, <Insert User Password Here>, new LogInCallback() {
        @Override
        public void done(ParseUser parseUser, ParseException e) {
            if (parseUser != null) {
                alertDisplayer("Sucessful Login","Welcome back" + <Insert Username Here> + "!");
            } else {
                ParseUser.logOut();
                Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    });
    
    In the example project, this code is placed inside a LOG IN button callback.
    Also, username and password are caught using Edit Texts.
    The method alertDisplayer is the same that you added in the SignUpActivity, don’t forget to change its Intent arguments though.

Step 4 - Log Out

Logging out deletes the active Session object for the logged User. The method used to perform log out is ParseUser.logOut().
To implement user log out, simply use the code below, in the LogoutActivity:
1
2
3
// logging out of Parse
ParseUser.logOut();
alertDisplayer("So, you're going...", "Ok...Bye-bye then");
In the example project, this code is placed inside a LOG OUT button callback.
The method alertDisplayer is the same that you added in the LoginActivity and SignUpActivity, don’t forget to change its Intent arguments though.

Step 5 - Test your app

  1. Run your app and create a couple of users, also try logging in again after registering them.
  2. Login at Back4App Website.
  3. Find your app and click on Dashboard > Core > Browser > User.
At this point, you should see your users as displayed below:
Note: Using the codes displayed above, every time you log in with a user, a Session is opened in your Dashboard, but when the user logs out that particular Session ends. Also, whenever an unsuccessful login or sign up attempt occurs, the Session opened in Parse Server Dashboard is deleted.

It’s done!

At this stage, you can log in, register or log out of your app using Parse Server core features through Back4App!


Login RegistrationSource

back4app CRUD operation

Adminca

Monday, November 12, 2018

Creating and sharing your own Android Library

Login pase Testing Using Expresso Android studio.



Source

1. build.gradle(module.app)


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
/*Espresso testing */
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
//full code of this section
//Start from here
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.amirul.loginespressotesting"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
/*Espresso testing */
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
//end
view raw login_1.java hosted with ❤ by GitHub


2. MainActivity.java


package com.amirul.loginespressotesting;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
/*
* ****************************************************************************
* * Created by : Md Amirul Islam on 11/9/2018 at 8.11 PM.
* * Email : amirul.csejust@gmail.com
* *
* * Purpose: To test all element of UI
* *
* * Last edited by : Md Amirul Islam on 11/11/2018.
* *
* * Last Reviewed by : <Reviewer Name> on <mm/dd/yy>
* ****************************************************************************
*/
public class MainActivity extends AppCompatActivity {
private EditText mEmailEditText, mPasswordEditText;
private TextView show;
private Button btnSubmit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEmailEditText = (EditText)findViewById(R.id.etEmailInput);
mPasswordEditText = (EditText)findViewById(R.id.etPassInput);
mPasswordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId ==R.id.login || actionId == EditorInfo.IME_NULL){
login();
return true;
}
return false;
}
});
btnSubmit = (Button)findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login();
}
});
}
private void login() {
/*Reset errors */
mEmailEditText.setError(null);
mPasswordEditText.setError(null);
/*getting value from email and pass*/
String email = mEmailEditText.getText().toString();
String password = mPasswordEditText.getText().toString();
boolean cancel = false;
View focusView = null;
/*check for a valid Email*/
if (TextUtils.isEmpty(email)){
mEmailEditText.setError("This field is required");
focusView = mEmailEditText;
cancel = true;
}else if (!isEmailVaild(email)){
mEmailEditText.setError(getString(R.string.error_invalid_email));
focusView = mEmailEditText;
cancel = true;
}
// Check for a valid password.
if (TextUtils.isEmpty(password)) {
mPasswordEditText.setError(getString(R.string.error_field_required));
focusView = mPasswordEditText;
cancel = true;
} else if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
mPasswordEditText.setError(getString(R.string.error_invalid_password));
focusView = mPasswordEditText;
cancel = true;
}
if (cancel) {
focusView.requestFocus();
} else {
if (email.equals("amir@gmail.com") && password.equals("123456")) {
loginSuccessfully(email);
} else {
Toast.makeText(getApplicationContext(), getString(R.string.error_login_failed), Toast.LENGTH_SHORT).show();
}
}
}
private boolean isEmailVaild(String email) {
return Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
private boolean isPasswordValid(String password) {
return password.length() > 4;
}
private void loginSuccessfully(String email) {
Intent intent = new Intent(MainActivity.this, Welcome.class);
intent.putExtra("email", email);
startActivity(intent);
finish();
Toast.makeText(getApplicationContext(), getString(R.string.login_successfully), Toast.LENGTH_SHORT).show();
}
}
//full code : https://github.com/amirul12/loginAndroidEspresso


3. xml layout of the mainActivity class activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login_bg"
tools:context=".MainActivity">
<LinearLayout
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="200dp"
android:layout_height="50dp"
android:src="@drawable/logo"
android:transitionName="logo" />
</LinearLayout>
<TextView
android:text="Email"
android:layout_marginTop="30dp"
android:textSize="18dp"
android:textColor="#ffffff"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/etEmailInput"
android:layout_marginTop="10dp"
android:hint="Enter Email"
android:textColor="#ffffff"
android:textColorHint="#A9A9A9"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_marginTop="10dp"
android:textSize="18dp"
android:text="Password"
android:textColor="#ffffff"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/etPassInput"
android:layout_marginTop="10dp"
android:hint="Enter Password"
android:textColorHint="#A9A9A9"
android:imeActionId="@+id/login"
android:imeActionLabel="Login"
android:imeOptions="actionUnspecified"
android:inputType="textPassword|numberPassword"
android:textColor="#ffffff"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:clickable="true"
android:id="@+id/btnSubmit"
android:layout_marginTop="10dp"
android:text="Submit"
android:focusable="true"
android:elevation="20dp"
android:background="@drawable/button_bg"
android:textColor="@android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_marginTop="20dp"
android:id="@+id/show"
android:text="show"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>


4. welcome Activity and this layout


package com.amirul.loginespressotesting;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class Welcome extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
String welcomeMessage = String.format("Hi %s!", getIntent().getStringExtra("email"));
TextView tvEmail = (TextView) findViewById(R.id.tv_welcome);
tvEmail.setText(welcomeMessage);
}
}
===================
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Welcome">
<TextView
android:id="@+id/tv_welcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Welcome"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>


5. Testing MainActivity which is Login form .


package com.amirul.loginespressotesting;
import android.support.annotation.StringRes;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.widget.EditText;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.provider.Settings.System.getString;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.clearText;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.*;
/*
* ****************************************************************************
* * Created by : Md Amirul Islam on 11/9/2018 at 8.11 PM.
* * Email : amirul.csejust@gmail.com
* *
* * Purpose: To test all element of UI
* *
* * Last edited by : Md Amirul Islam on 11/11/2018.
* *
* * Last Reviewed by : <Reviewer Name> on <mm/dd/yy>
* ****************************************************************************
*/
@RunWith(AndroidJUnit4.class)
public class MainActivityTest2 {
// To launch the mentioned activity under testing
@Rule
public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class);
@Test
public void emailIsEmpty() {
delay(2000);
onView(withId(R.id.etEmailInput)).perform(clearText());
delay(2000);
onView(withId(R.id.btnSubmit)).perform(click());
delay(2000);
onView(withId(R.id.etEmailInput)).check(matches(withError(getString(R.string.error_field_required))));
delay(2000);
}
@Test
public void passwordIsEmpty() {
delay(2000);
onView(withId(R.id.etEmailInput)).perform(typeText("email@email.com"), closeSoftKeyboard());
delay(2000);
onView(withId(R.id.etPassInput)).perform(clearText());
delay(2000);
onView(withId(R.id.btnSubmit)).perform(click());
delay(2000);
onView(withId(R.id.etPassInput)).check(matches(withError(getString(R.string.error_field_required))));
delay(2000);
}
@Test
public void emailIsInvalid() {
delay(2000);
onView(withId(R.id.etEmailInput)).perform(typeText("invalid"), closeSoftKeyboard());
delay(2000);
onView(withId(R.id.btnSubmit)).perform(click());
delay(2000);
onView(withId(R.id.etEmailInput)).check(matches(withError(getString(R.string.error_invalid_email))));
delay(2000);
}
@Test
public void passwordIsTooShort() {
delay(2000);
onView(withId(R.id.etEmailInput)).perform(typeText("amir@email.com"), closeSoftKeyboard());
delay(2000);
onView(withId(R.id.etPassInput)).perform(typeText("1234"), closeSoftKeyboard());
delay(2000);
onView(withId(R.id.btnSubmit)).perform(click());
delay(2000);
onView(withId(R.id.etPassInput)).check(matches(withError(getString(R.string.error_invalid_password))));
delay(2000);
}
@Test
public void loginFailed() {
delay(2000);
onView(withId(R.id.etEmailInput)).perform(typeText("incorrect@email.com"), closeSoftKeyboard());
onView(withId(R.id.etPassInput)).perform(typeText("123456"), closeSoftKeyboard());
delay(2000);
onView(withId(R.id.btnSubmit)).perform(click());
onView(withText(getString(R.string.error_login_failed)))
.inRoot(withDecorView(not(activityTestRule.getActivity().getWindow().getDecorView())))
.check(matches(isDisplayed()));
delay(2000);
}
@Test
public void loginSuccessfully_shouldShowWelcomeMessage() {
delay(2000);
onView(withId(R.id.etEmailInput)).perform(typeText("amir@gmail.com"), closeSoftKeyboard());
onView(withId(R.id.etPassInput)).perform(typeText("123456"), closeSoftKeyboard());
delay(2000);
onView(withId(R.id.btnSubmit)).perform(click());
onView(withId(R.id.tv_welcome)).check(matches(withText("Hi amir@gmail.com!")));
}
@Test
public void loginSuccessfully_shouldShowToast() {
delay(2000);
onView(withId(R.id.etEmailInput)).perform(typeText("amir@gmail.com"), closeSoftKeyboard());
onView(withId(R.id.etPassInput)).perform(typeText("123456"), closeSoftKeyboard());
delay(2000);
onView(withId(R.id.btnSubmit)).perform(click());
onView(withText(getString(R.string.login_successfully)))
.inRoot(withDecorView(not(activityTestRule.getActivity().getWindow().getDecorView())))
.check(matches(isDisplayed()));
delay(2000);
}
private String getString(@StringRes int resourceId) {
return activityTestRule.getActivity().getString(resourceId);
}
private static Matcher<View> withError(final String expected) {
return new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View item) {
if (item instanceof EditText) {
return ((EditText)item).getError().toString().equals(expected);
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("Not found error message" + expected + ", find it!");
}
};
}
private void delay(long item) {
try {
Thread.sleep(item);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//full code : https://github.com/amirul12/loginAndroidEspresso


GitHub Link



Espresso Resources

Sunday, November 11, 2018

selectable button in android studio | click a button show hovor in android studio

Today I will discuss about android studio button selection. How we can use a hover effect in this button. .

here the code , you use this code snap to your drawer folder and give a name as you want.
then you use this as a background in your button which is stayed in layout section.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="40dp"></corners>
<size android:width="200dp" android:height="50dp"></size>
<gradient android:centerColor="#FB9491" android:endColor="#FC73C4" android:startColor="#FAC943"></gradient>
</shape>
</item>
<item android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="40dp"></corners>
<size android:width="200dp" android:height="50dp"></size>
<stroke android:width="1dp" android:color="@color/color_divider"></stroke>
</shape>
</item>
</selector>


thanks , I will talk to you another topics later.

Friday, November 9, 2018

Espresso dependencies

/*Espresso testing */
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

Full code of dependency:CODE

apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "app.itech.com.myapplication"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
/*Espresso testing */
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
view raw espresso.java hosted with ❤ by GitHub


Toast message check


/*
* ****************************************************************************
* * Created by : Md Amirul Islam on 11/3/2018 at 8.11 PM.
* * Email : amirul.csejust@gmail.com
* *
* * Purpose: To test all element of UI
* *
* * Last edited by : Md Amirul Islam on 11/3/2018.
* *
* * Last Reviewed by : <Reviewer Name> on <mm/dd/yy>
* ****************************************************************************
*/
public class ToastMegCheckTest {
@Rule
public ActivityTestRule<ToastMegCheck> mToastMegCheckTest = new ActivityTestRule<>(ToastMegCheck.class);
/*
* Below two method needs if want some DB (Database) or network operation and we need setup some
* important things like DB connection established or DB close.
* But now we are not use it
* */
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void showEditTextName() {
// now write in edit text
onView(withId(R.id.etTest)).perform(typeText("amirul"));
delay(500);
// now press b Button
onView(withId(R.id.btnSubmit)).perform(click());
// now check toast is properly showing or not
onView(withText("amirul")).inRoot(withDecorView(not(is(mToastMegCheckTest.getActivity().getWindow().getDecorView())))).check(matches(isDisplayed()));
}
private void delay(long item) {
try {
Thread.sleep(item);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}


Code END




Saturday, November 3, 2018

how to create custome Matcher in Espresso android studio

Create a class name  ErrorMatcher in androidTest folder.


public class ErrorMatcher {



@NonNull

public static Matcher withError(final Matcher stringMatcher) {

return new BoundedMatcher(TextView.class) {


@Override

public void describeTo(final Description description) {
description.appendText("error text: ");
stringMatcher.describeTo(description);
}


@Override

public boolean matchesSafely(final TextView textView) {
return stringMatcher.matches(textView.getError().toString());
}
};
}
}


# Maching logic is to match the subtext of the textview with only the error message.

#describeTo method only for debug.

# you can use this as your custom matcher in the test case as shown in below.

===================


@Test 

public void testLoginMandatory()
{
    onView(withId(R.id.email_sign_in_button)).perform(click());
    onView(ErrorMatcher.withError(Matchers.
            containsString("The field is required"))).check(matches(isDisplayed()));

}



Source