Select Page

Category Selected: Automation Testing

193 results Found


People also read

Accessibility Testing

Section 508 Compliance Explained

Blog

Types of Hybrid Automation Frameworks

Blog

AI for QA: Challenges and Insights

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility
TestNG Tutorial : An Introduction to its Attributes and Features

TestNG Tutorial : An Introduction to its Attributes and Features

TestNG is not the only option available in the market. But most of the automation testers prefer TestNG over other options like JUnit because TestNG allows parallel execution of test cases that saves loads of time possible with the help of the ‘parallel’ keyword in the XML file, TestNG’s seamless integration with tools like Jenkins, Maven, etc., and grouping of test cases also becomes easy with the use TestNG. These features have been instrumental in us providing the best software testing services to our clients. So in this TestNG tutorial, we will be focusing on how to make use of all these advantages and also explore all the advantages that TestNG brings to the table.

TestNG is an open-source testing framework where NG stands for Next Generation. It provides many features to execute the test methods by using various annotations like @Test @BeforeTest, @BeforeClass, etc. TestNG allows its users to generate robust test results that include the number of test cases that have Run, Passed, Failed, and Skipped. It can also be used to implement the logging feature using TestNG Listeners. On the whole, TestNG can also be used across various testing types like Unit, Regression, Functional, and API Testing. But before we get started with the TestNG Tutorial, let’s see how to set it up.

Installation and Setup of TestNG in IntelliJ:

IntelliJ requires a JAR file to add dependencies for TestNG script development and for running the test suites. So if it is a Maven Project, we would have to download the TestNG Jar File. Since we will be running tests on Java, we need to download an external TestNG Jar File onto our system by using the provided link.

Direct download link: TestNG/7.4.0/testng-7.4.0.jar

Reference: org.testng/TestNG

Please refer to the below image and instructions for a step-by-step guide,

Step by Step Guide

i. Open IntelliJ,

ii. Create a new JAVA Project,

iii. Navigate to ‘File’ >> ‘Project Structure’ in IntelliJ,

iv. Click on ‘Libraries’ from Project Setting,

v. Add it to your ‘TestNG’ jar file, and then click on the ‘Apply and OK’ button.

Selecting Library Files

If we want to work on a maven project, we have to mention the dependency in the POM.xml file

Maven Repository

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.4.0</version>
    <scope>test</scope>
</dependency>

TestNG Annotations:

TestNG annotations that are used to execute the test scripts can be defined by ‘@Test’ annotations. Before we head over to other aspects of the TestNG Tutorial, let’s take a look at the various annotations that are available in TestNG along with a short description of them.

Types of TestNG Annotations:

TestNG Annotation Order

@Test Annotations:

We use this annotation to mark a method as a test method. The methods marked with @Test annotation are automatically invoked by the TestNG engine in default order (i.e.) alphabetically.

Syntax:

@Test
public void TestMethod1() {
System.out.println("\n Test-Method-001");
}

So in this part of the TestNG Tutorial, we will be focusing on the most important attributes of @Test annotations, starting with the description

1. ‘Description’ attribute of @Test Annotation:

The ‘Description’ keyword is used to provide a description of the test case. It can also be termed as a one-line summary, and it has been illustrated in the below example that describes the action of the user in a single line.

@Test(description = "User visits Codoid Home page")
public void launchCodoidURL(){
System.out.println("\n >>> User visits Codoid Home page...");
}
2. Test Methods with Priority:

As mentioned earlier, we are aware that the methods will execute multiple test annotations alphabetically by default. But what if there is a need to run the methods or the test annotations based on defined priorities? Here is where the ‘Priority’ attribute comes into play, as it can be used to assign priorities to each test method. The highest priority would be given when a test method is marked with 1 and the priority decreases inversely as the number increases.

We have mentioned syntax below to denote how the priority attribute would function.

Syntax:

@Test(priority = 1)
public void Test1() {
System.out.println("\n Test-1");
}

@Test(priority = 2)
public void Test2() {
System.out.println("\n Test-2");
}
3. Test Methods with Priority & without priority:

So in the above-mentioned syntax code, we saw 2 sets of programs that had defined priorities. But what if there is a need to define priorities only for a certain number of methods? It is very easy to accomplish as you can simply leave the methods that don’t need defined priorities and mark the other methods alone in the order that you wish. It is worth noting that the methods that had no defined priority will be run first on an alphabetical basis and then followed by the defined order.

Syntax:

@Test(priority = 1)		//with Priority
public void Test1() {
System.out.println("\n Test-1");
}

@Test		//without priority
public void TestMethod1() {
System.out.println("\n Test-Method-001");
}

@Test		//without priority
public void TestMethod2() {
System.out.println("\n Test-Method-001");
}

@Test(priority = 2)		//with Priority
public void Test2() {
System.out.println("\n Test-2");
}

Code Explanation:

– Non-Prioritized methods ‘TestMethod1() and TestMethod2()’ have been executed in alphabetical order. (Line No: 60 and 65)

– Prioritized methods ‘Test1() and Test2()’ have been executed based on the priority level. (Line No: 55 and 69)

4. Depends On Methods in TestNG:

In our test scripts, we might have some methods that depend on the execution of another method before it is executed. For example, if a user wishes to send an email using the email application, then the user has to be logged in to the application first. So there will be no point in trying to send the mail if the sign-in is incomplete. So we can make use of this attribute that will help methods from getting executed if their dependent method doesn’t get a ‘Pass’. The same scenario is shown below as an example.

Syntax:

@Test
public void UserLoginIntoEmailApplication(){
    System.out.println("\n >> User Login :: ");
}
@Test(dependsOnMethods = "UserLoginIntoEmailApplication")
public void UserSendAnNewEmail(){
    System.out.println(">> User send an eMail");
}

Depends on Methods

Sometimes, there might be scenarios where a test case depends on more than one test method. So we can pass the parameters in annotations as shown below.

Syntax for dependsOnMethods: (Multiple Dependent Test methods)

@Test(dependsOnMethods = { "UserLoginIntoEmailApplication", "UserSendAnNewEmail" })
public void SignOut() {
System.out.println(">>> Sign Out");
}

Syntax for depends on Methods in TestNG

5. TestNG Groups:

The grouping concept is one of the best features of TestNG and one of the important parts of this TestNG Tutorial. So using this concept we can create a group of test methods based on modules/test cases. For example, the client requirement might demand you to execute a large number of smoke or regression tests. So you can simply pass the parameter in group attributes as shown below.

Syntax:

@Test(groups = { "Regression" })
public void userLogin() {
....
}
@Test(groups = { "Regression" })
public void userSendEmail() {
....
}

So the groups are specified in the ‘.xml’ file and can either be used with the “groups” tag name or under the ‘test’ tag.

Syntax:

<groups>
<run>
<include name = "Regression"></include>
</run>
</groups>

TestNG Groups

DataProvider in TestNG:

In this method, a user will be able to pass the test data in test methods and also iterate the test methods using different data from the @DataProvider annotation, and it will return the 2D array objects.
Let’s see a simple example for this annotation,

Code:

@DataProvider(name = "data-provider")
public Object[][] dataProviderMethod() {
return new Object[][]{{"Codoid-001"}, {"Codoid-002"}};
}
@Test(dataProvider = "data-provider")
public void testDataProviderConcept(String strData) {
System.out.println("\n >> Data: " + strData);
}

Code Explanation:

We have maintained the array object and Test methods in the same class. In this method, the “testDataProviderConcept(String strData)” will iterate based on the array size. It will also retrieve the values “Codoid-001 and Codoid-002” from the ‘dataProviderMethod()’ with the help of the @DataProvider annotation.

Data Provider in TestNG

Multiple Parameters in TestNG DataProvider:

It is even possible to pass multiple data through a single parameter. In this test method, we will be able to retrieve the data using multiple arguments as shown in the example,

For example,

@DataProvider(name = "data-provider")
public Object[][] dataProviderMethod(){
return new Object[][] {{123,456 ,789}, {001, 002, 003}};
}
@Test(dataProvider = "data-provider")
public void testMethod(int value1, int value2, int value3) {
System.out.println("\n >> value1: "+value1+"; Value2: "+value2+"; Value3: "+value3);
} 

Multiple Parameters in TestNG provider

DataProvider In TestNG Using Inheritance concept:

If you are looking for a way to maintain the code based on the project structure, then the DataProvider methods can maintain one class and the test methods can maintain another class. Let’s take a look at the example to find out how.

For example, we can access the dataprovider class using another attribute like “dataProviderClass”

Syntax :

@Test(dataProvider = “data-provider”, dataProviderClass = DP.class)

Note:

i. dataProviderClass // attribute Name

ii. DP.class // class Name; To inherit the other class.

Code:

//Class-1
@Test(dataProvider = "data-provider", dataProviderClass = DataProviderUtil.class)
public void testDataProviderConcept(String strData) {
System.out.println("\n >> Data: " + strData);
}
//Class-2  "Class Name: DataProviderUtil"
@DataProvider(name = "data-provider")
public Object[][] dataProviderMethod() {
return new Object[][]{{"Codoid-001"}, {"Codoid-002"}};

TestNG Tutorial for using Excel Workbook as a Data Provider:

Now that we have seen how to pass the parameter with single or multiple data through an array object, but what if there is a need that demands a large number of data be used? Adding everything to the code will not be an optimal choice at all. We have a solution to overcome this in our TestNG Tutorial and so let’s focus on how we can retrieve data from an Excel workbook. Knowing this will come in very handy while executing Functional tests, and when there is a need to create a large amount of test data for performing Load tests.

We are going to implement the Excel workbook in the TestNG-DataProvider annotation to fetch the data from the excel sheet and search the products in Amazon. In the example, we have listed a few mobile phones like iPhone 12, Pixel 4a, and so on in the excel sheet.

The below-mentioned Excel util class is used to retrieve the data from the Excel sheet.

ExcelUtil.JAVA

Code:


/*Description: We can retrieve the data from the Excel workbook
    * parameter-1: Excel workbook directory path,
    * parameter-2: Sheet name*/
    public static Iterator<Object[]> getTestData(String strWorkbookPath, String strWorksheetName) {
        List<Object[]> data = new ArrayList<Object[]>();
        int inRowCounter = 0;
        try {
            FileInputStream file = new FileInputStream(new File(strWorkbookPath));
            //Get the workbook instance for the xlsx file.
            HSSFWorkbook workbook = new HSSFWorkbook(file);
            //Get the first sheet from the workbook
            HSSFSheet sheet = workbook.getSheet(strWorksheetName);
            //Get an iterator to all the rows in the current sheet
            Iterator<Row> rowIterator = sheet.rowIterator();
            Row firstRow = rowIterator.next();
            Map<String, String> columnNamesMap = getColumnNames(firstRow);
            while (rowIterator.hasNext()) {
                Iterator<Cell> cellIterator = rowIterator.next().cellIterator();
                Map<String, String> rowMap = new LinkedHashMap();
                for (Entry entry : columnNamesMap.entrySet()) {
                    String strColumnName = entry.getKey().toString();
                    String strValue = cellIterator.next().toString();
                    rowMap.put(strColumnName, strValue);
                }
            }
            file.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data.iterator();
    }

    private static Map<String, String> getColumnNames(Row row) {
        Map<String, String> columnNamesMap = new LinkedHashMap();
        Iterator<Cell> cells = row.cellIterator();
        while (cells.hasNext()) {
            String strColumnName = cells.next().toString();
            columnNamesMap.put(strColumnName, strColumnName);
        }
        return columnNamesMap;
    }
DataProvider.Class
@DataProvider(name = "AmazonProduct", parallel = false)
        public static Iterator<Object[]> getDeviceName() {
            String strWorkBookPath = new StringBuilder().append(System.getProperty("user.dir")).append(File.separator)
                    .append("resources\\testdata").append(File.separator).append("testdata").append(".xlsx").toString();

            Iterator<Object[]> testData = ExcelUtil.getTestData(strWorkBookPath, "Mobiles");
            return testData;
        }
TestScripts.java
@Test(dataProvider = "AmazonProduct", dataProviderClass = DataProviderUtil.staticProviderClass.class)
public void searchAmazonProducts(Map<String, String> dataMap) {
        System.setProperty("webdriver.chrome.driver", "./resources/drivers/chromedriver.exe");
        driver = new ChromeDriver();
        driver.get("https://www.amazon.in/");
        wait = new WebDriverWait(driver, 25);
        WebElement txtSearchEngine = wait.until(ExpectedConditions.visibilityOfElementLocated(
                By.cssSelector("#twotabsearchtextbox")));
        System.out.println("\n Devices : " + dataMap.get("Devices"));

        txtSearchEngine.sendKeys(dataMap.get("Devices"));
        txtSearchEngine.submit();
        driver.quit();
    }

Please refer to the below image,

Data provider in Excel Workbook

Parameterization in TestNG:

When there is a need to perform tests by using different test data, or when you are looking to test by logging in with a different user that has distinct usernames and passwords then Parameterization will come in handy as the “@Parameters” annotation in TestNG allows argument values to pass to Test methods via the testng.xml file. (Parameter values are declared in testng.xml) We have explained the different user scenarios using an example.

Syntax:

@Parameters({ “param-name” })

Let’s write a simple program for the @Parameters annotation,

Code:

@Test
@Parameters({"Username"})		
public void TestMethod1(String strUsername) {	
//We can retrieve the data using this argument. (It’ll retrieve from testng.xml file)
System.out.println("\n Username : " + strUsername);
}

Parameterization in TestNG

TestNG Tutorial for Parallel Execution:

Saving time during the testing process is always a priority, and one of the best possible ways to do it would be by executing tests in parallel rather than sequential execution. So as promised at the beginning of this TestNG Tutorial, let’s see how we can have test suites executed in parallel on different browsers, and how it can be even defined in the Testing.xml file.

TestNG provides different levels of execution that we can achieve by using the Testing.xml file. The attributes that we can use to achieve them are,

i. Methods,

ii. Classes, and

iii. Tests.

i. parallel=”methods”:

We had already seen about methods that are dependent on other methods for their execution, so accordingly if you are looking to execute many independent methods in parallel, then this attribute can be used. Using this attribute, all test methods will run on a separate thread. In the below example, we have executed two test methods in two threads.

Note: Thread count is the specified number of browser instances that should be assigned for this test execution.

Syntax:

<suite name="Test-method Suite" parallel="methods" thread-count="2" >

Parallel Methods

Code :

TestParallelForMethodsExecution.java
public class TestParallelForMethodsExecution {

    @Test
    public void visitCodoidPage() {
        String baseUrl = "https://codoid.com/";
        System.setProperty("webdriver.chrome.driver", "./resources/drivers/chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get(baseUrl);
        driver.manage().window().maximize();
        WebDriverWait wait = new WebDriverWait(driver, 25);
        String testTitle = "QA Testing Company - Software Testing Services";
        boolean isVerified = wait.until(ExpectedConditions.titleContains(testTitle));
        Assert.assertTrue(isVerified);
        WebElement elmntAboutUsTab = driver.findElement(By.xpath("//ul[@id='top-menu']/li/a[text()='About Us']"));
        elmntAboutUsTab.click();
        driver.close();
    }

    @Test
    public void visitAmazonPage() {
        String baseUrl = "https://www.amazon.in/";
        System.setProperty("webdriver.chrome.driver", "./resources/drivers/chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get(baseUrl);
        driver.manage().window().maximize();
        WebDriverWait wait = new WebDriverWait(driver, 25);
        String testTitle = "Online Shopping site in India";
        boolean isVerified;
        isVerified = wait.until(ExpectedConditions.titleContains(testTitle));
        Assert.assertTrue(isVerified);
        driver.close();
    }
}
TestNG.xml
<suite thread-count="2" name="Parallel-Test-Suite" parallel="methods">
    <test name="To Run TestNG :: Parallel methods concept">
        <classes>
            <class name="scripts.TestParallelForMethodsExecution"/>
        </classes>
    </test>
</suite>
ii. parallel=”tests”:

But the problem is that the above type will not work if we have a lot of test methods that are dependent on each other like how we saw earlier with the email example. So this attribute can be used to overcome this issue by adding all the dependent tests to a suite file (Testing.xml) and executing it separately in a thread as each tag will be considered a test suite and it’ll be executed in a separate thread.

Syntax:

<suite name="Test-Suite" parallel="tests" thread-count="2">

Parallel Test

Code

MultipleSession1.java
public class MultipleSession1 {

    public static WebDriver driver = null;
    public static WebDriverWait wait = null;

    @Test
    public void visitAmazonPage() {
        String baseUrl = "https://www.amazon.in/";
        System.setProperty("webdriver.chrome.driver", "./resources/drivers/chromedriver.exe");
        driver = new ChromeDriver();
        driver.get(baseUrl);
        driver.manage().window().maximize();
        wait = new WebDriverWait(driver, 25);
        String testTitle = "Online Shopping site in India";
        boolean isVerified;
        isVerified = wait.until(ExpectedConditions.titleContains(testTitle));
        Assert.assertTrue(isVerified);
    }

    @BeforeMethod
    public void beforeMethod() {
        System.out.println("\n Starting Test On Chrome Browser");
    }

    @AfterTest
    public void terminateBrowser() {
        driver.close();
    }
}
MultipleSession2.java
public class MultipleSession2 {

    public static WebDriver driver = null;
    public static WebDriverWait wait = null;


    @Test
    public void visitCodoidAboutUsPage() {
        String baseUrl = "https://codoid.com/";
        System.setProperty("webdriver.chrome.driver", "./resources/drivers/chromedriver.exe");
        driver = new ChromeDriver();
        driver.get(baseUrl);
        driver.manage().window().maximize();
        wait = new WebDriverWait(driver, 25);
        String testTitle = "QA Testing Company - Software Testing Services";
        boolean isVerified = wait.until(ExpectedConditions.titleContains(testTitle));
        Assert.assertTrue(isVerified);
        WebElement elmntAboutUsTab = driver.findElement(By.xpath("//ul[@id='top-menu']/li/a[text()='About Us']"));
        elmntAboutUsTab.click();
    }


    @BeforeMethod
    public void beforeMethod() {
        System.out.println("\n Starting Test On Chrome Browser");
    }

    @AfterTest
    public void terminateBrowser() {
        driver.close();
    }
}
TestNG.xml
<suite thread-count="2" name="Parallel-Test-Suite" parallel="tests">
    <test name="To Run TestNG :: Parallel Tests concept - 1">
        <classes>
            <class name="scripts.MultipleSession1"/>
        </classes>
    </test>
    <test name="To Run TestNG :: Parallel Tests concept - 2">
        <classes>
            <class name="scripts.MultipleSession2"/>
        </classes>
    </test>
</suite>
iii. parallel=”classes”:

This type has similar usage scope as the previous one with one major difference. Using this attribute, we can execute tests under each class in an individual thread, and the same has been explained in the below example.

Syntax:

<suite thread-count=”2” name =”Parallel-Test-Suite” parallel=”classes”>

Parallel Classes

Code:

Test1.java
public class Test1 {

    public static WebDriver driver = null;
    public static WebDriverWait wait = null;

    @Test
    public void Test1() {
        String baseUrl = "https://codoid.com/";
        System.setProperty("webdriver.chrome.driver", "./resources/drivers/chromedriver.exe");
        driver = new ChromeDriver();
        driver.get(baseUrl);
        driver.manage().window().maximize();
        wait = new WebDriverWait(driver, 25);
    }

    @Test
    public void Test2() {
        String testTitle = "QA Testing Company - Software Testing Services";
        boolean isVerified;
        isVerified = wait.until(ExpectedConditions.titleContains(testTitle));
        Assert.assertTrue(isVerified);
    }
    @Test
    public void Test3() throws InterruptedException {
        WebElement elmntAboutUsTab = driver.findElement(By.xpath("//ul[@id='top-menu']/li/a[text()='About Us']"));
        elmntAboutUsTab.click();
    }
    @AfterTest
    public void terminateBrowser() {
        driver.close();
    }
 }
Test2.java
public class Test2 {

    public static WebDriver driver = null;
    public static WebDriverWait wait = null;


    @Test(priority = 1)
    public void launchAmazonURL() {
        String baseUrl = "https://www.amazon.in/";
        System.setProperty("webdriver.chrome.driver", "./resources/drivers/chromedriver.exe");

        driver = new ChromeDriver();
        driver.get(baseUrl);
        driver.manage().window().maximize();
        wait = new WebDriverWait(driver, 25);

    }

    @Test(priority = 2)
    public void verifyAmazonTitle() {
        String testTitle = "Online Shopping site in India";
        boolean isVerified;
        isVerified = wait.until(ExpectedConditions.titleContains(testTitle));
        Assert.assertTrue(isVerified);
    }

    @Test(priority = 3)
    public void navigatesToAboutUsPage() throws InterruptedException {
        WebElement elmntAmazonPayTab = driver.findElement(By.xpath("//a[text()='Amazon Pay']"));
        elmntAmazonPayTab.click();
    }

    @BeforeMethod
    public void beforeMethod() {
        System.out.println("\n Starting Test On Chrome Browser");
    }

    @AfterTest
    public void terminateBrowser() {
        driver.close();
    }
}
TestNG.xml
<suite thread-count="2" name="Parallel-Test-Suite" parallel="classes">
    <test name="Using Classes attributes for parallel execution.">
        <classes>
            <class name="scripts.Test1"/>
            <class name="scripts.Test2"/>
        </classes>
    </test>
</suite>

In the above 3 points, it can be seen that we have defined the keywords for parallel (classes, tests, and methods) attributes on the Testing.xml file. Now, we’re going to explain the sample scripts for classes and methods.

Conclusion:

As promised at the beginning of this TestNG tutorial, we have explored all the plus points of TestNG. So we hope this information would be useful and that you have enjoyed reading this blog. As one of the leading automation testing companies, we have always found TestNG beneficial in crucial circumstances, and hope it will come in handy for you as well.

4 Test Automation Mistakes the Every QA Team Should Avoid

4 Test Automation Mistakes the Every QA Team Should Avoid

In the world of software development, no product could ever face success without undergoing thorough and rigorous testing. Test automation is essential as it ensures that the end product delivered is stable and works according to the required specifications. However, QA teams and automation testing companies are not immune to making mistakes. In fact, any mistakes they made could potentially cost time, money, and trust that could easily derail the product’s success. Here are four common test automation mistakes your team should avoid at all times.

Not Identifying What Should and Shouldn’t Be Automated

For a tester, understanding what areas to automate and how it will help the organization is the basic rule of thumb for test automation success. It’s why you do the things you do. 

However, there are times when you might be tempted to jump in and start hunting for tools to do the job. Don’t be too hasty about it, and make sure to clearly identify first which tasks to automate and which ones to execute manually. This will effectively be your guiding principle throughout the testing process. Failure to do so is a recipe for disaster.

Automating the Wrong Things

In a way, this is the result of mistake number one. Because you failed to identify what areas to automate, you risk making mistakes and automating the wrong things. Many teams try to automate tasks that aren’t actually good candidates for automation. One big miscalculation in this area is trying to translate your existing testing activities one-to-one into automation. Doing this is a huge waste of time and effort, leaving you to focus on things that don’t need to be automated at all. Keep your priorities straight, and don’t forget why you’re doing the testing in the first place.

Picking the Wrong Tools

There are many different problems you want to solve with automation, and one tool can’t solve all of them. That’s why picking the right tools is essential. The thing is, a lot of QA managers and automation testing companies are always looking for that one tool that could solve everything for them. The truth is, it just doesn’t exist.

The key is finding out what problem you want to solve with a tool, rather than buying a tool and then finding a problem for it. It’s best to design specific problems you need to solve before shopping around for a tool.

Failure to Coordinate with Fellow Testers

There are many people involved in a testing team. All these people are equipped with a different skill set that can prove invaluable to you. While they have their own specializations, that doesn’t mean you don’t discuss the progress of your tasks with them. Coordination is key to accelerating product delivery. Without coordination, you risk committing more mistakes and taking more time to fix those mistakes. If everyone is on the same page, they can respond better if something doesn’t go according to plan.

Conclusion

When handling an automation testing project, you need to be mindful of every little detail, including avoiding any pitfalls such as the ones mentioned above. While it is good to learn from your mistakes, it is always better to be preventive, especially if we’re talking about developing software.

If you’re in need of a QA company with a seamless track record, Codoid is your best choice. Every new software product deserves high-quality automation testing, and our team happens to be fully equipped to do just that. When it comes to QA automation services, there’s no better choice than Codoid. Partner with us today!

5 Mobile App Testing Mistakes to Avoid When Creating Your App

5 Mobile App Testing Mistakes to Avoid When Creating Your App

Mobile apps have taken the world by storm over the last decade. These powerful programs have allowed users to perform various tasks on their smartphones, such as paying their bills, guiding them through traffic, and even purchasing groceries. However, with so many apps on various marketplaces, it’s become even more difficult to design and launch an app successfully. 

Even though you may have a unique, potentially groundbreaking idea for an app, you’ll need to subject it to rigorous mobile app testing services to make sure it works properly in all intended scenarios before rolling it out. Otherwise, any issue that pops up can cause your intended users to drop the app altogether.

Here are five mobile app testing mistakes to avoid:

1. Failing to Test on Actual Devices

Many companies prefer to use cloud-based tools when testing the application in the interest of time and resources. While these tools are efficient in supporting the actual device, they cannot replace them entirely. It is crucial to test your mobile app on a real device as some features and functionalities present differently on the cloud than on the device itself. Be sure to test in at least two real devices, like Android and iOS, along with the last two versions of the operating systems.

2. Not Doing Proper Responsive Testing

Responsive testing is another critical aspect that many companies tend to skip. However, it is essential to check the applications and render them in multiple devices of various screen sizes and operating systems. It’s best to entrust this to mobile testing service providers, as they have all the tools and equipment necessary to test an application’s render throughout various devices.

3. Forgetting to Consider Device Configuration and Network

Suppose your app needs a precise amount of storage space or Internet connection to work properly. In that case, you’ll need to consider the device configuration and network when testing, another part that companies forget to do. Test your app with different RAM sizes and evaluate the application’s speed, which will help you determine the optimal conditions for your app to function. You’ll also need to conduct network virtualization testing to check your app’s performance with various internet speeds, data, and others.

4. Testing Only at the End

Testing your mobile app must be done right from the beginning, not at the end. That way, you can guarantee that your mobile app is stable and performs as such, and the team has enough time to resolve the issues instead of rushing the solution to meet deadlines. Rushed work often means cutting corners in the process, which you definitely don’t want in your app.

5. Being Unable to Recreate User Usage

Users have very high expectations of mobile apps and expect them to look attractive, perform well, and have an intuitive interface. User experience (UX) ultimately makes or breaks an app, so it’s crucial to test your app from their perspective and recreate how they use your app. It must perform according to your user’s expectations and not simply what you expect it to do. 

Conclusion

Apps have come a long way since their early days, and they continue to grow more advanced and sophisticated. As such, for your app to succeed, you must subject it to thorough testing before rolling it out. Providing a seamless experience for your users is the key to getting them to use it frequently, which will earn you a rapidly expanding user base.

If you’re looking for mobile app testing services to ensure your app is fit to launch, let us know at Codoid! As part of the leading test automation companies, our grade-A testing will give your growing product all the care and attention it needs to fulfill its potential. Contact us today to get started on testing your app!

The Best JavaScript Testing Frameworks you should be using in 2021

The Best JavaScript Testing Frameworks you should be using in 2021

Automation testing using JavaScript has been gaining popularity in recent days making a blog about the best JavaScript Testing Frameworks available the need of the hour. A conversation between business analysts, developers, and testers about a feature will become specifications. After that, the developers & testers convert the specs into automated acceptance tests. Automated tests help the team to drive the feature development as passing acceptance tests prove the fact that the agreed feature has been developed as expected.

To convert specifications into automated acceptance tests, devs & QAs should use the same programming language. Let’s say your team is using JavaScript for development and Java for automation testing. In this case, you won’t be able to enable effective collaboration between the developers & testers which is a big concern. Analysts & developers can capture acceptance criteria effectively. However, testers are good at adding edge cases making them invaluable as well. That is why everyone’s involvement right from the beginning is vital with common tools, frameworks, and language.

In this blog article, we have listed the best JavaScript Testing Frameworks which are widely used for writing unit tests and acceptance tests.

Jasmine

When developers focus more on components than features, they don’t add value to the business. Writing tests in plain English helps your team focus on the business goals and Jasmine is one of the best testing frameworks to make it possible. Using Jasmine you can write meaningful tests which can be understood by everyone in the team and help the developers to write higher quality code more efficiently.

Jasmine has support for Node.JS, RUBY, and Python. If you want to run the tests on a Web Browser instead of running them in interpreter/programming engine, then you can go for Jasmine Standalone. Now let’s find out how to use Jasmine in Node.JS beginning right from its installation.

Installation:

To install Jasmine, run the below npm command.

npm install jasmine —save-dev
Initialization

To set up Jasmine in a Node.JS project, you need spec files and jasmine.json (Configuration file). You can add these files manually. However, we have an npx command to initialize Jasmine in your project and it has been listed below

npx jasmine init

After running the above command, you can find the ‘spec’ folder and ‘jasmine.json’ file under the spec->support folder.

Add Jasmine in package.json

Now, you need to inform your node project that you are using Jasmine for testing. Open package.json and update the ‘test’ value as ‘jasmine’ as shown below.

{
  "name": "jasmine-sample",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jasmine"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "jasmine": "^3.7.0"
  }
}
Describe

In order to group related test cases like how we group scenarios in a feature file in Cucumber, you need to create a JavaScript file and write a ‘describe’ function as shown below.

describe("User Management", ()=>{

})

In the above function, it is a placeholder to add ‘User Management’ related test cases.

Specs

Specs are your test cases. You need to write specs inside the ‘describe’ function as shown below.

describe("User Management", ()=>{

    it("should signup",()=>{

    })

    it("should login", ()=>{

    })
})

As we mentioned earlier, everyone in the team should understand what is the purpose of each test. When naming a test case for unit & acceptance tests, you need to describe what you are expecting. However, it is a cumbersome task for a developer to focus on names. If there are a rule and a standard which come from the testing framework, then the team members will be able to stick to the business goals and focus on achieving them instead of concentrating only on the code components.

That is why the Jasmine framework has the ‘it’ function and the first argument starts with ‘should’. When a test case says ‘It should do something’, the developer will focus on that something throughout the development which is exactly what we want.

How is a spec pass or fail determined? You can have multiple assertion lines inside a spec and even if one of those assertions fails, the spec will be marked as ‘Fail’.

Assertions

Jasmine has an in-built assertion function which is called ‘expect’. Expect function has one argument which takes the actual value. You can also chain the assertion using Matcher functions.

expect(“my string”).toMatch(/string$/) – Expect the actual value to match a regular expression.

expect(bigObject).toEqual( “foo”: ‘bar’, ‘baz’ ) – Expect the actual value to be equal to the expected value using deep equality comparison.

expect(thing).toBe(realThing) – Expect the actual value to be === to the expected value.

Configurations

Jasmine has a total of five configurations in the jasmine.json file. Let’s take a look at the purpose of each of these configurations one by one.

“specdir” – A directory path where you have the specs in the current project directory.

“specfiles” – You can include & exclude spec file paths with regular expression.

“helpers” – Before the test execution commences, you may need some supporting files that should be executed. The helpers config is the placeholder to mention the supporting JS files.

“stopSpecOnExpectationFailure” – This is a boolean config. If the value is true, then the spec execution will be stopped when the first assertion is failed.

“random” – Run the specs in random order.

Advantages of Jasmine
  • You can customize the Jasmine report.
  • It has a very strong community that supports the users.
  • You can even create your own Matchers.
  • It is extremely simple and easy to use making it the choice of many developers and testers mainly for its simplicity.

Jest

Jest is also a popular JavaScript Testing framework that works with Node.JS, React, Angular, Vue, Babel, TypeScript, and more. Jest was developed by Facebook and so it runs thousands of tests for Facebook on a daily basis. Apart from Facebook, there are many other prominent companies that also use Jest. So let’s see what makes Jest one of the best JavaScript Testing Frameworks and how you can implement it in your project. Let’s begin with its installation process.

Installation

You can easily install Jest by making use of the below code,

npm install --save-dev jest
Add Jasmine in package.json

Update scripts>test node as ‘jest’ in Package.json as shown below.

{
  "name": "jest-sample",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "jest": "^26.6.3"
  }
}
Configuration

No configuration is required to write or run Jest tests. However, every testing framework has its own configuration file. To create a config file, you can run the below command.

npx jest —init

Once you run the above command, Jest will ask you a few questions to create the config file.

Migrating from Jasmine to Jest

If you are planning to migrate from Jasmine to Jest, then we’ve got some good news for you as Jest is compatible with Jasmine tests. This makes the migration far less complicated. However, if you want to do a code-level migration, you can use third-party jest-codemods for the best results.

Assertions

In order to write assertions elegantly in a test, you would definitely need sophisticated Matchers. Jest has a lot of compressive matchers that you could use. However, we have listed some of the commonly used Matchers below.

test('two plus two is four', () => {
  expect(2 + 2).toBe(4);
});
test('object assignment', () => {
  const data = {one: 1};
  data['two'] = 2;
  expect(data).toEqual({one: 1, two: 2});
});
test('null', () => {
  const n = null;
  expect(n).toBeNull();
  expect(n).toBeDefined();
  expect(n).not.toBeUndefined();
  expect(n).not.toBeTruthy();
  expect(n).toBeFalsy();
});
Snapshot Testing

Your Acceptance Tests test the application under test by performing actions on the UI. However, it never validates whether the UI is rendered as same as before and if the CSS styles are applied correctly or not. Jest has a feature to address this issue (i.e. Visual Regression Testing). Using Jest, you can capture snapshots and compare them with the expected snapshot thereby creating a huge advantage if that is your primary need.

Advantages

If you want to run your tests in parallel, then Jest is your go-to testing framework. Jest has numerous assertion functions. In terms of ease of adoption, simplicity, support, and documentation, Jest is hands down the clear winner.

Mocha

Mocha is a JavaScript Testing framework only for Nod.JS. Mocha doesn’t have an in-built assertion library. However, it allows you to use the following libraries such as should.js, chai, expect.js, better-assert, and unexpected for assertions. You can execute tests in two modes (Serial & Parallel).

Conclusion

Jest and Jasmine are the best JavaScript Testing frameworks. However, most of the engineers are comfortable with Jasmine over Jest. As an automation testing company, we use Jasmine for Protractor automation testing. Jasmine is the default testing framework for Protractor. Our suggestion is not final and it shouldn’t influence your framework decision.

Jest has many sophisticated features such as Configuring Visual Testing (i.e. Snapshot Testing) which is not as easy to do in Jasmine. However, in Jest, it is pretty straightforward. Apart from that, test creation and assertions are similar in both these frameworks. If you feel Jest is suitable for your project, please go ahead.

Basic npm Commands

Basic npm Commands

Even the smallest hiccups like package installation errors can be a bane to your productivity. In this blog article, we have listed some of the basic npm commands which are used by developers and software testers regularly to resolve package installation errors and to even upgrade existing npm packages. As a software testing company, we are experts in automation testing services using Protractor & Jasmine frameworks.

For one to manage npm packages effectively, one should be aware of the most common npm commands. So let’s get the ball rolling with a few basic commands that have been categorized by their purpose.

Package Installation

To install a package in your current project using npm commands, you can make use of either of the codes given below:

npm install package-name -s

or

npm install package-name

Use the code given below to install a package under Development dependencies in your current project by using npm commands:

npm install package-name —save-dev

You can install a package globally using npm commands if a package dependency is not for the project by using the below code:

npm install package-name -g

Install a specific package version

Sometimes you might find yourself to be in a situation where you need to install a specific package version rather than the most latest version. But when you run the npm install command, it will only install the latest version of a package. The solution is easy, as you can install a specific package version by simply using the version number in the installation command as shown below.

npm install package-name@version-number

Finding Outdated Packages

When the dependency list grows, it is a cumbersome job to find the outdated packages in a project. However, npm can make your job easy as it has a command to find the packages which can be upgraded.

npm outdated

When you run the above command, it will list the outdated packages from which you can find the version that you are looking for.

Clear npm Cache using npm commands

When a package installation doesn’t go as expected, it may be because of an npm cache issue. One best option would be to clear the cache and then execute the installation command again.

Before clearing the npm cache, make sure to check how many cache entries are available by using the below code.

npm cache verify

Now you can clear the npm cache by using the below command.

npm cache clean —force

Audit Packages

Using vulnerable npm packages can make your project less secure. So it is crucial to perform a security check for all the available project packages. You can do so by running the below command.

npm audit

Once the audit has run, it will list the vulnerable packages which are supposed to be removed to make your packages more secure.

Installing Minor & Patch Releases

When you run the npm install command, it will install the packages which are mentioned in the package.json file. The npm install command can be used to install only the missing packages. But if you are looking to install recent minor versions using the npm install command, you have to prefix the caret (^) symbol before the package version in package.json. To install patch releases, you have to prefix the Tilde (~) symbol.

Conclusion

Auditing packages & removing unused packages periodically will help avoid catastrophic failures when deploying code in a production environment. Node.js is a memory-efficient environment. When an automation test suite runs for a longer duration, you should optimize it by improving the script and using good packages.

QA automation testers who are starting automation test scripting using JavaScript & Node.js will find these basic npm commands very helpful. Being an automation testing company, we use Protractor, Selenium WebDriver, and Jasmine frameworks for web apps automation testing, and therefore in the subsequent blog articles, we will be publishing more on Protractor and automation test scripting using JavaScript & Node.js. So make sure to keep an eye on our website so that you don’t miss out on the upcoming blogs.

3 Signs You Need Commercial Tools for Your Test Automation Project

3 Signs You Need Commercial Tools for Your Test Automation Project

As a test engineer, you’ve probably faced numerous challenges when beginning a new test automation project. One of your biggest concerns was probably if the right tools were being used to ensure you get accurate results. Although many people automatically prefer using open-source tools, they often aren’t enough to fulfill testing needs.  

Open-source testing tools have proven reliable, although commercial tools are quickly outshining them in their capabilities. If you’ve been considering making the switch, here are three signs your test automation project needs commercial tools instead of open-source ones:

You’re Testing More Than One Type of Technology

 

Before diving right into a testing project, you’ll have to identify your testing needs first. Although open source might be a good fit, you may benefit more from commercial tools. Ensure that you study your needs carefully before finalizing your decision.

If you’re testing more than one type of technology, write down all the technologies your organization must automate against, which will help you save more money in the long run. Having just one test tool that is compatible across all your teams will make the project run faster and more efficiently. If you decide to use an open-source solution, you may not have the test coverage you need. However, vendor-based tools automate a wide range of technologies like mobile applications, Oracle Forms, and SAP, giving you everything you need in one go. 

Ease of Use Is the Priority

 

When you think about it, most open-source tools are really just API. If you are testing products with these tools, you’ll need to have a team of engineers who can create a custom framework to meet all the project’s requirements, which can be incredibly difficult. Not many testers have this technical mastery, making open-source tools even less favorable.

However, with vendor-based tools, you’ll have efficient products that make the test-creation process intuitive and straightforward. They offer features like monitoring, defect integration, and built-in object spies, which perform crucial tasks for you. You can also have a complete application lifecycle solution in place thanks to these features. 

You Need Testing Platforms That Are Certified-as-Compliant

Many companies require engineers to seek approval for the testing tools they want to use in a project, which can be time-consuming. In these scenarios, commercial tools are the more advantageous option, as they’ve gone through rigorous testing and evaluation to make sure they abide by common compliance standards. If you work in a highly regulated industry like healthcare, you’ll have to ensure that the tools you choose are evaluated to be safe and secure.

Most commercial tools have been in the business for years, which means they’ve been regularly updated to fix bugs, making them an ideal fit for testing technology. They also come with many years of domain knowledge, providing you with reliable and robust tools to start your test automation project.

Conclusion

Rigorous testing is necessary to squash any bugs and resolve errors before launching the product. With vendor-based tools, you’ll have all the extra features to make sure that your software works across all devices, giving you a product that is sure to succeed.

If you’re looking for the best app testing services, you’ve come to the right place. Codoid is one of the best QA and software testing companies offering mobile app testing, QA automation services, and many more. Contact us today to find out what we can do for you!