Tuesday, 31 March 2015

How to validate a Credit Card Number?

How to validate a Credit Card Number?

Most credit card number can be validated using the Luhn algorithm, which is more or a less a glorified Modulo 10 formula!

The Luhn Formula:

  • Drop the last digit from the number. The last digit is what we want to check against
  • Reverse the numbers
  • Multiply the digits in odd positions (1, 3, 5, etc.) by 2 and subtract 9 to all any result higher than 9
  • Add all the numbers together
  • The check digit (the last number of the card) is the amount that you would need to add to get a multiple of 10 (Modulo 10)

Luhn Example:

Step Total
Original Number: 4 5 5 6 7 3 7 5 8 6 8 9 9 8 5 5
Drop the last digit: 4 5 5 6 7 3 7 5 8 6 8 9 9 8 5
Reverse the digits: 5 8 9 9 8 6 8 5 7 3 7 6 5 5 4
Multiple odd digits by 2: 10 8 18 9 16 6 16 5 14 3 14 6 10 5 8
Subtract 9 to numbers over 9: 1 8 9 9 7 6 7 5 5 3 5 6 1 5 8
Add all numbers: 1 8 9 9 7 6 7 5 5 3 5 6 1 5 8 85
Mod 10: 85 modulo 10 = 5 (last digit of card)

List of credit card number formats:

Credit Card Issuer               Starts With ( IIN Range )       Length ( Number of digits )

American Express              34, 37                                                 15


Diners Club                        300, 301, 302, 303, 304,
                                           305                                                     14
Carte Blanche

Diners Club -                     36                                                       14
International

Diners Club -                      54                                                       16
USA & Canada

Discover                            6011, 622126 to 622925,644, 
                                           645, 646, 647, 648, 649, 65              16

InstaPayment                    637, 638, 639                                     16

JCB                                    3528 to 3589                                      16

Laser                                 6304, 6706, 6771, 6709                     16-19

Maestro                             5018, 5020, 5038, 5893, 
                                           6304, 6759, 6761, 6762,
                                           6763                                                   16-19

MasterCard                        51, 52, 53, 54, 55                               16-19

Visa                                     4                                                         13-16

Visa Electron                     4026, 417500, 4508, 
                                           4844, 4913, 4917                               16


Monday, 2 March 2015

Appium Configuration

Appium Configuration

Don't have any text to check? Don’t have any text to check? Click "Select Samples”.
We will use Eclipse and TestNG framework to run Appium automatic take a look at on automaton device/emulator. Let’s consider conditions of this setup method.

Prerequisites:
1.   Android SDK put in in system.
2.      Appium (You will get this from official Appium site)
3.       ..NET Framework 4.5
4.       Eclipse / IntelliJ plan
5.       TestNG and Se a pair of JARs

We will begin set up for Appium Android configuration. Follow below steps for the same.
  1. Install JAVA 1.7 and above in your system.
  2. Set the environmental variable JAVA_HOME to JDK home directory (Ex. C:\Program Files\Java\jdk1.8.0_25)
  1. Append %JAVA_HOME%\bin in PATH variable
  2. Install Android SDK in your system.
  3. Set ANDROID_HOME environment variable which points to your SDK directory’s \sdk folder.
  4. Append %ANDROID_HOME%\tools; %ANDROID_HOME%\platform-tools; %ANDROID_HOME%\platforms; value to your PATH environment variable.
  5. Start your Android emulator or connect your Android device to your system (Make sure you have Android Debugging option enabled in your Android device).
  6. Open Command Prompt and navigate to your Android SDK’s \platform-tools\ directory (Eg. D:\adt-bundle-windows-x86_64-20130514\sdk\platform-tools).
  7. Run ‘adb devices’ command. You should see your connected devices listed in Command Prompt window.
  8. Run ‘adb start-server’ command. It will start ADB server which will be used by Appium to send commands to your Android device.
  9. Now, navigate to Appium directory in your system and begin Appium by clicking Appium.exe file.
  10. Click Launch button. Your Appium console ought to be displayed as below.



Appium Console
Starting Node Server
> Info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
> Info: Appium REST http interface listener started on 127.0.0.1:4723
  1. Create a Java project in your Eclipse and reference Selenium 2 and TestNG JARs.

Create a new Java class in your project and enter below code.

package com.appiumproj.test;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Appium {
                WebDriver driver;
                @BeforeClass
                public void setUp () throws MalformedURLException {
                                DesiredCapabilities capabilities = new DesiredCapabilities ();
                                capabilities.setCapability ("device", "Android");
                                capabilities.setCapability (CapabilityType.BROWSER_NAME, "");
// Name of mobile web browser to automate. Should be an empty string if automating an app instead.
                                capabilities.setCapability (CapabilityType.VERSION, "4.4");
                                capabilities.setCapability (CapabilityType.PLATFORM, "Windows");
                                capabilities.setCapability ("app-package", "APP PACKAGE"); //Replace with your app's package
                                capabilities.setCapability ("app-activity", "APP PACKAGE.ANDROID ACTIVITY"); //Replace with app's Activity
                                driver = new RemoteWebDriver (new URL ("http://127.0.0.1:4723/wd/hub"), capabilities);
                }
                @Test
                public void Cal () {
                                driver.findElement (By.name ("Weather")).click ();
                }
                @AfterClass
                public void tearDown () {
                                driver.quit ();
                }
}
  1. Run your test using TestNG.

Troubleshooting - Common Errors
1.       Error: A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT)
Fix: Remove the spaces between SDK and ADT paths.
Check adt is up and working using command prompt type ‘adb-help’

2.       Error: No app set; either start appium with --app or pass in an 'app' value in desired capabilities, or set androidPackage to launch pre-existing app on device
Fix: The app-Package, platform desired capabilities provided were not recognized by appium.
Check your desired capabilities: [caps]
platformName = "Android"
platformVersion = "4.4"
deviceName = "Galaxy S4"
appPackage = "com.example.android.sample1"
appActivity = "com.example.android.learn.launch.activity.LaunchActivity"
app = "apps/android-learn-debug.apk"

you need at a minimum either the app or the appPackage/appActivity. If you google aapt, you'll figure out how to get those.

3.       Error: Failed to start an Appium session, err was: Error: Bad app: /Users/data/app/ /Facebook.apk.
Fix: App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name.

4.       Error: A session is either terminated or not started (Original error: Could not find adb; do you have the Android SDK installed and the tools + platform-tools folders added to your PATH?
Fix: you need to add the path to sdk folder to the PATH variable and check again that the path to your .apk is the correct one.

5.       If you started the emulator, but the “ ./adb devices “ command returns no result, try running:
Fix: Sometimes there are issues connecting to the emulator, so you would need to restart adb by performing the below instructions
“adb kill-server “
“adb start-server “

6.       IOS/Android Driver casting on a shared test code base
Fix:  You can declare AppiumDriver field in the test code. It will be correct because Android Driver and IOS Driver both extend AppiumDriver which is abstract now.
Sample Example
//it is parameterized test
public class AppiumJUnitTest {
//this is set up by given parameters before test is started
private AppiumDriver driver;
@Test
public void test () throws Exception {
//code which works against Android and iOS
}
}

7.       Prerequisites: Download Links
4.       Appium Server for Windows: https://bitbucket.org/appium/appium.app/downloads/

7.       Android SDK Tools (ADT Bundle for Windows) http://developer.android.com/sdk/installing/index.html?pkg=tools