Automated Test Cases with Java String Methods

How To

List of test casesWhen you’re writing automated test cases in Java, you’ll often want to use string methods to see if your test results match expectations.

What are string methods? They let you perform various operations on strings, like checking how many characters they have, or whether they contain certain words.

Below, you’ll find a list of some of the most common Java string methods. If you don’t understand how to use them, don’t worry — you can scroll down to see real live examples of code using each string method on the list below.

Common Java String Methods:

  • String length() — returns the length of the string
  • String charAt() — returns a char value at the given index number
  • String concat() — adds a given string at the end of the string
  • String contains() — returns true if chars are found in the string
  • String startsWith() — checks if a string starts with a given prefix
  • String endsWith() — checks if a string ends with a given suffix
  • String equals() — compares the contents of two given strings
  • String indexOf() — returns the index of a given character value or substring
  • String isEmpty() — checks if the string is empty
  • String replace() — returns a string replacing all of the old char with new char
  • String substring() — returns a part of the string
  • String toCharArray() — returns the string converted into character array
  • String toLowerCase — returns the string in lowercase letter(s)
  • String toUpperCase() — returns the string in uppercase letter(s)
  • String trim() — removes leading and trailing spaces

Test Cases Using String Methods:

You can view a suite of TestNG test cases using these string methods here, on my Github profile. This isn’t meant to be a comprehensive or real test plan, but rather a fun way to see what types of things the above list of string methods can do in an automated test.

Note that if it doesn’t make sense to you, that’s okay — everyone has to start from somewhere, and there are a ton of great free and low-cost resources online that can help you learn Java (or whatever language you’d like to write automated test scripts in). Two of the best cheap and/or free resources that I recommend are Codecademy and Udemy. Good luck!

 

 

How to Install Appium in Eclipse

How To

Note: this post only covers adding Appium itself, and not pre-requisites like Android Studio, Dotnet Framework, and Xcode.

Part One: Download the JAR File

To add Appium to Eclipse, first you need to download the JAR file. It’s okay if you don’t know what a JAR file is yet — it’s just like downloading any other file for now.

AppiumTo download the Appium JAR file:

  1. Go here (or you can manually go to the Maven Repository website and search for Appium — the result will be called “Java Client”)
  2. Click the number of the version you want to download — for example 4.0.0
  3. On the resulting page, click “central” in the “Repository” field, which should take you to a list of downloadable files like this
  4. Click the one called “java-client-4.0.0.jar” (or whichever version number you’re downloading). This will start the download

Once the download is complete, open your Downloads folder and move your new file to a permanent location on your computer — anywhere you want is fine, though I recommend putting it in the same Eclipse folder that you use for other related files.

Part Two: Add the JAR File to Eclipse

You’re almost there! All you have to do next:

  1. Open Eclipse
  2. Right-click the name of your project in the left nav (if you don’t have a project yet, you can click “File” in the top bar and select “New” and then “Java Project”)
  3. Select “Build Path” and then “Configure Build Path”
  4. Click “Add External JARs”
  5. Find the JAR file you downloaded and click “Open”
  6. Click “OK”

Congrats! You’ve officially added the Appium JAR file to Eclipse.

Want to double-check that it was installed correctly? Good call. To do so, simply expand the “Referenced Libraries” folder under the project you added the Appium JAR file to. If you see “java-client-4.0.0.jar” on the list of items in Referenced Libraries, then you’re good to go.

Did Your Firefox Driver Suddenly Stop Working in Eclipse?

How To

Firefox

If you do automated QA testing with Selenium WebDriver, you probably use Firefox Driver to run your tests in Firefox. If so, you may have noticed that these tests suddenly stopped working recently, with error messages relating to “firefox-bin.” If you’ve been tearing your hair out in frustration, fret no more! I’m happy to share the solution.

You may be surprised at how simple it is, after extensively searching without any luck. Are you ready? The answer is… Firefox 47! The latest version of Firefox, which most people have set to auto-update, introduced problems when opened with Eclipse/Selenium WebDriver/Firefox Driver.

These problems will likely be fixed soon (I hope!), but in the meantime, here’s what you need to do to get back to testing in Firefox:

First, make sure that your Firefox preferences are not set to auto-update:

  1. Open Firefox, and click the menu button at the top right (represented by three horizontal lines)
  2. Select “Preferences”
  3. In the left-hand menu, click “Advanced”
  4. Click “Updates”
  5. Select “Check for updates, but let me choose whether to install them”
  6. Navigate away and it will auto-save

Next, you need to uninstall Firefox.

If you’re on a Mac, simply open your Applications folder, and drag the “Firefox” app to the trash.

If you’re on Windows, go here and follow the recommended steps.

Once you’ve completely uninstalled it, it’s time to download the previous version of Firefox, which is Firefox 46. You can download it here – simply scroll down and click “Firefox 46.0.1” and download/install it, and you’re good to go.

Now, you should be able to run tests with Firefox Driver with none of the previous problems.

Happy testing!