Tuesday, October 16, 2018

Selenium Firefox - Test using FindByElement( By.ClassName() )

This is very similar to the Test using FindByElement( By.XPath() ).

The change in this article is replacing the use of "xpath" obviously.

[Test Utility Class]
public static Boolean isDisclaimerDisplayed(WebDriver webDriver) {
    String modalTitle = webDriver.findByElement(By.className("modal-title").getText();
    return modalTitle.equalsIgnoreCase("Notice to All Users");
}

That's it. Cheers!

References
https://www.softwaretestingmaterial.com/how-to-locate-element-by-class-name-locator/
https://saucelabs.com/resources/articles/selenium-tips-css-selectors

Selenium Firefox - Test using FindByElement( By.XPath() )

Today, the goal is to verify the home page for a user after login. Actually, a disclaimer is displayed to the user before the user can access the home page. A modal is displayed with the disclaimer agreement and waits for the user to accept the disclaimer before the application redirects the user to their homepage.

So, the title of the modal include this text: "Notice to All Users".

I want my test to find this modal title and verify that the text is "Notice to All Users". This will also confirm that my login test passes because when I enter an unrecognized username the login dialog continues to display as opposed to showing an error message or error page. (In my opinion, this is poor design of the application and I will fix this if I ever get the time.)

My Code:

[Test Script Class]
@Test
public void testLogin() {
    Application.login(webDriver, url, username, password);
    boolean isDisplayed = Application.isDisclaimerDisplayed(webDriver);
    Assert.assertTrue("User successfully logged into Application.", isDisplayed);
}

[Test Utility Class]
public static Boolean isDisclaimerDisplayed(WebDriver webDriver) {
    String xpathRegEx = "//h3[@class='modal-title']";
    String modalTitle = webDriver.findByElement(By.xpath(xpathRegEx).getText();
    return modalTitle.equalsIgnoreCase("Notice to All Users");
}

One side of Caution here: This is slower than other methods of finding elements like by ID or by Class Name because this method looks through the entire XML formatted HTML document to find the element expected.


References
https://www.softwaretestingmaterial.com/how-to-locate-element-by-xpath-locator/
https://saucelabs.com/resources/articles/selenium-tips-css-selectors


Journey into SET: Part 1

So, I'm getting back into the game of software testing and especially with the new test automation tools and techniques. I'm going to log my journey of catching back up in this field after being in software development (away from testing to purely coding without testing - and I know this is bad). So, let's just add that I'm restoring the best practices of a software engineer.

Nowadays, it seems the new title for software testers is either Software Development/Design Engineer in Test (SDET) or Software Engineer in Test (SET) or similar. The emphasis is on the evolving skills of a tester having the capabilities to develop (or code) meanwhile advancing their techniques of applying best practices in test automation. This makes sense when we consider how the multitude of frameworks for development web application and software tools has also evolved.

Here are some articles to read.

Evolution of the Software Testing role:


One can also gain an understanding of what a test engineer (or SDET or SET) does today by looking up the job qualifications on major tech company career websites including Google (specifically "Test Engineer"), Amazon (spec. "Software Development Engineer in Test"), Microsoft (spec. "Software Design Engineer in Test").

A Quick Recap from Microsoft's Personal Experience
Here's a nice recap from Microsoft on the transition of eliminating the Software Test Engineer (STEs) and creating a "combined engineering" team.


Software Test Design
Similarly to developing any software, developing scripts to test software also should go through the design phase in order to create test structure. This helps with organizing tests to correspond to the software design, finding bugs early in the design process of software development, creating a testing framework for easier ramp-up of new Test Engineers and for easier review of the software development team, and more.

Software Test Design - Problems
First problem I'm interested in is what to name the appendages of the class files especially for the automated test scripts via the browser.
Unit Tests use the appendage "Test" like "HelloWorldTest".
Integration Tests use the appendage "IT" like "HelloWorldIT".

I've seen throughout the Selenium docs the term "AUT" (or application under test) and wonder if I should use this as the appendage for my test scripts via browser like "HelloWorldAUT". But is this sufficient?

Software Test Design - Research
https://dzone.com/articles/design-patterns-in-automation-testing

What is SOLID (Principles)?

  • Single responsibility
  • Open-Closed priniciple: open for extension and closed for modification
  • Liskov substitution
  • Interface segregation
  • Dependency injection

https://msdn.microsoft.com/en-us/magazine/dn683797.aspx (dated: May 2014)
*There are a number of terms explained in this article that I really like. For instance, the author says "when I say principle, I'm referring to a feature of the computer code that helps maintain the value of that code."


Software Testing Conferences
Here are some conferences to be aware of with respect to software test automation and the future of testing software.



Software Test Tools
There are a lot of tools from the many articles online that I've read. Not to overwhelm one with reading through all the articles and also knowing that the software tool depends on the software developed, here's a short list of tools that I'm learning and applying.

Leading the list is Selenium as the best, open source tool for testing web applications.


I should really keep track of my progress here. This is getting way too long. So I need to split this step into smaller steps and start publishing.

Monday, October 15, 2018

Loading Properties file for Test Automation

I am trying to load a simple.properties file into my test suite as soon as I run my test automation.

I tried following tutorial on Apache Commons, but I am missing the configuration2 package. I don't have time to download this and install since I'm working on a secure network.
https://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html

To be exact, I need the configuration2 package for the Parameters class.
https://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration2/builder/fluent/Parameters.html

Okay, now what?

Well, let's first use basic Java to load a Properties file and test it.

I can't remember the website where I got this code from, but it is similar to the basic Java tutorial with the exception of using a BufferedReader instead of the InputStreamReader or the like. I added this into my init() method.

private Properties properties;

@Before
public void init() {
    Log.Info("Starting my test automation...");

    BufferedReader reader;
    try {
        reader = new BufferedReader( new FileReader( "src/test/resources/simple.properties"));
        properties = new Properties();
        try {
            properties.load(reader);
            reader.close();
        } catch (IOException ioEx) {
            ioEx.printStackTrace();
        }
    } catch (FileNotFoundException fileEx) {
        fileEx.printStackTrace();
        throw new RuntimeException("simple.properties file not found!");
    }
}

// Note, inside of my simple.properties file is: 
// testword = hello
@Test
public void testPropertiesFilesLoaded() {
    Assert.assertEquals(properties.get("testword"), "hello");
}

I ran this from the command line using Maven.
$ mvn -Dtest=SimpleTestAUT test -pl :app-ui

And the test passed! Yay!

Now, I need to know how to really use this properties file across my test suite. I have a Sample1AUT.java and Sample2AUT.java. In Sample1AUT.java, I have the following.

@BeforeClass
public static void setup() {
    MyProperties.loadProperties("myPropertiesFileName");
}

@Test
public void testPropertiesLoaded() {
    Assert.assertEquals("user", MyProperties.getProperty("biz.username"));
}

This is what my MyProperties class looks like.

public class MyProperties {

  static Properties properties;

  public static void loadProperties(String fileName) {

    BufferedReader reader;

    try {
        reader = new BufferedReader( new FileReader( "src/test/resources/"+fileName+".properties"));
        properties = new Properties();
        try {
            properties.load(reader);
            reader.close();
        } catch (IOException ioEx) {
            ioEx.printStackTrace();
        }
    } catch (FileNotFoundException fileEx) {
        fileEx.printStackTrace();
        throw new RuntimeException(fileName+".properties file not found!");
    }
  }

  public static String getProperty(String key) {
    return (String) properties.get(key);
  }
}

It worked, yay!

What I need to try next is loading Properties file via Krausening in case my "test/resources" folder is not deployed with the WAR including the Test Suite.

References


Monday, September 10, 2018

Not actually a minifesto

Devs,

Here's another interesting article that I just read.
http://minifesto.org/

Not sure I would agree with everything especially with calling this a "mini"festo, but I get this author's point. I also would use better terms instead of "killing the baby". Anyhow, just something to read and think about. In essence, fail fast, work fast, better is good (thanks President Obama), and keep your eyes on the win.

Discovering Datasets with Google

Devs,

If you haven't already been keeping abreast of all the data science hype, then I would suggest that you get with it. Although I haven't been able to keep up with the "hype" (and I call it "hype" because everything with computers has been on processing 'data'), this doesn't mean you have to wait for me. I'll catch up eventually. I have just have other priorities right now in this season of my life (aka two toddlers).

Here's an article I enjoyed reading. Cheers!

https://www.blog.google/products/search/making-it-easier-discover-datasets/




Tuesday, September 4, 2018

True "Agile Development"

Devs,

I'm not going to say much since some developers have the tendency to talk in circles on certain topics like "what is Agile". Instead, I am posting an article that I just read and totally agree with (who is actually one of the founders of the Agile Manifesto). I actually took part in this "experimental" phase when it came out with my first corporate job in Minnesota. From there, I've been on teams in Boston and in DC. There has only been one other team which was a Boston, small business that worked close to the principles of Agile. This is perhaps because the CTO was co-founder of the business.

Therefore, I'm realizing that for an organization to truly be Agile, one of the co-founders must be extremely technical if not a co-founder/CTO.

https://martinfowler.com/articles/agile-aus-2018.html
  1. Get rid of the Agile Industrial Complex and the idea of imposing stuff on teams. Let teams work out the way they should work themselves.
  2. Raise the importance of technical excellence, and never forget that when writing software, the technology side is really vital, and
  3. organize around products.
One area I wish Martin would have highlighted is the importance of "smart users". That is, users are who are aware of how to develop their product to make life easier. I don't mean easier like "make a better car" but visionary like "make a self-driving car". That kind of vision (which requires an imagination - thanks GE) is the kind of easier I'm referring to. Somehow, I thought with more people using all of these gadgets that people would become more creative. I'm still waiting to witness, hahaha.

Enjoy the ride!