Powered By Blogger

Search Here!

Tuesday, June 15, 2021

Setup Automated Mobile Test Build Parameters in Jenkins !

Jenkins File -

properties([ 
disableConcurrentBuilds(),
buildDiscarder(logRotator(numToKeepStr: '25')),
parameters([
string(defaultValue: "localhost", description: 'Server Login IP address', name: 'LOGIN-IP-VALUE'),
choice(choices: ['All','Smoke','Regression'], description: 'Test Suite Name', name: 'Test_Suite_Name'),
choice(choices: ['emulator','device'], description: 'Device Type', name: 'DEVICE_TYPE'),
extendedChoice(name: 'Slave', value: 'Manish,Evan,Max', defaultValue: 'Manish', description: 'Slave Machine Name', type: 'PT_MULTI_SELECT', visibleItemCount: 2)
])
])

node("${env.Slave}") {
stage('Checkout') {
timestamps {
checkout scm
}
}

stage('Test') {
timestamps {
try {
bat 'python.exe -m robot --variable LOGIN-IP-VALUE:%LOGIN-IP-VALUE% --variable DEVICE_TYPE:%DEVICE_TYPE% -d Output -i %Test_Suite_Name% --loglevel TRACE Tests/'
} catch (Exception e) {
emailSubject = "Jenkins build Failure: ${JOB_NAME} #${BUILD_NUMBER}"
emailRecipients = [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']]
emailBody = """
<style>
table {border:1px solid #ccc}
th {border:1px solid #ccc}
td {border:1px solid #ccc}
</style>
<table>
<tr><th>Result</th><td>${e}</td></tr>
<tr><th>Name</th><td>${currentBuild.fullDisplayName}</td></tr>
<tr><th>Job URL</th><td><a href="${JOB_URL}">${JOB_URL}</a></td></tr>
<tr><th>Build URL</th><td><a href="${BUILD_URL}">${BUILD_URL}</a></td></tr>
</table>
""".stripIndent()
emailext attachLog: true, mimeType: 'text/html', subject: emailSubject, body: emailBody, recipientProviders: emailRecipients
throw e
} finally {
stage('Generate report') {
publishHTML([allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir:'Output',
reportFiles:'report.html',
reportName:'Mobile Integration Test Report'
])
}
                        }
                }
        }
}

Preview in Jenkins -

As per my assumption out tests should be enough capable to run on the given environment -

LOGIN-IP-VALUE - Execute test's on given IP address.
Test_Suite_Name - Execute tests based on selected types of scenarios.
DEVICE_TYPE - Using emulator or on the real device connected via USB.
Slave - Execute test on different machines based on user identity.


Setup Mobile Automation With Robot Framework And Appium !

 Robot Framework  [only for android]

 Is an open-source test automation framework for acceptance testing and acceptance test-driven development. It follows different test case styles − keyword-driven, behavior-driven, and data-driven for writing test cases.

Appium is an open-source tool to automate native, web and hybrid mobile application.

Setup needed in Windows?

  1. Java 
  2. Android Studio
  3. Android Emulator 
  4. Node.js 
  5. Appium
  6. Robot Framework 
  7. Python - IDE PyCharm
Java Setup -




Android Studio Setup -




Android Emulator Setup -




Node JS Setup -




Appium Setup -


Robot Framework Setup – Install Python -




Robot Framework Setup – Install Robot -


Robot Framework Setup – Install Pycharm - 



Execute Test - 

robot -d Output --loglevel TRACE Tests/Essential/Login.robot
robot -d Output --loglevel TRACE -i Regression Tests/*
robot -d Output --loglevel TRACE -i All Tests/*

Monday, June 14, 2021

Mobile Device Testing using AWS Device Farm !

Device Farm is an app testing service that you can use to test and interact with your Android, iOS, and web apps on real, physical phones and tablets that are hosted by Amazon Web Services (AWS) since 2015.

  There are two main ways to use Device Farm:

  • Automated testing of apps using a variety of testing frameworks.

  • Remote access of devices onto which you can load, run, and interact with apps in real time.


Ways to use Device Farm


Automated Testing Vs. Remote Access

Automated Testing Vs. Remote Access


Problems will solve?
  • The cost and complexity of effective testing is growing
  • Maintain device on lab
  • Manual testing on each device is not practical
  • Record to trace the testing issue

Free Edition Limits in AWS Device Farm?
  • Mobile App package size < 4 GB .
  • Remote Access/ Automated testing only allow 1 hour at most each Session.
Pricing?

Pricing


Sunday, June 13, 2021

Webdriver Wait for window loads !

Wait for window loads and then select the window.

/// Wait for window till it gets load on the page.
///
/// The name of the window.
/// This is time to wait.
/// if the window not loads in the specified interval of time.
/// If the window not exists on the page.
        protected void WaitUntilWindowLoads(string windowName, int timeOut = -1)
        {
            // Intialization of bool 'isWindowPresent' for checking window present
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            if (timeOut == -1)
            {
                timeOut = this.waitTimeOut;
            }
            while (stopWatch.Elapsed.TotalSeconds < timeOut)
            {
                try
                {
                    //Wait for window
                    if (WaitUntilWindow(windowName) == true) break;
                }
                catch (Exception)
                {
                    // For Any exceptions catch value is assinged false
                }
            }
        }
  
///
/// Is Window Opened In the Specified Interval of Time or not.
///
/// This is the name of the window.
/// This is the time to wait for window get open.
/// True if the window is opened otherwise false.
/// If the window not able to find in the specified time.
/// If the window not exists on the page.
        protected bool WaitUntilWindow(string windowName, int timeOut = -1)
        {
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            if (timeOut == -1)
            {
                timeOut = this.waitTimeOut;
            }
            while (stopWatch.Elapsed.TotalSeconds < timeOut)
            {
                if (WebDriver.WindowHandles.Any(item =>                       WebDriver.SwitchTo().Window(item).Title == windowName))
                {
                    return true;
                }
            }
            stopWatch.Stop();
            return false;
        }