How long does it take to learn Selenium and Python

This is another post that grew out of a question asked by someone else online.

Here is the original question (and my answer) on Quora:

https://www.quora.com/How-long-does-it-take-to-learn-selenium-Webdriver-with-Python

There are several different things here, and they affect how long it will take you to learn Selenium with Python.

Let’s break it down:

  1. Learning Selenium
  2. Learning Python
  3. Learning programming
  4. Learning test automation

Your existing knowledge in each of these topics will affect how easy it is.

For example, if you’ve already used Selenium with another programming language, that means that (to some degree) you also know programming and test automation principles. So all you need to learn is Python.

But if you have some programming experience in JavaScript but have never done test automation (with or without Selenium) or used Python, you come with general programming knowledge (but using a different paradigm) there are more obstacles.

Alternately, you may have experience with test automation so you understand the goals, but have used a commercial low-code record and playback automation tool. This may actually be harder than starting from a programming background because it requires a paradigm shift in your strategy to test automation.

However, probably most people asking this question have some experience manually testing software, a basic knowledge of programming (either in Python, or some other language — but would not consider themselves expert), and want to know how long it would take them to become competent enough with Selenium and Python to either:

A. Get a job doing test automation with Selenium and Python or
B. Apply test automation with Selenium and Python in their current job
(which may be manual testing, or some other role).

So, I’ll try to answer this question.

Give yourself a few weeks to learn the basics of Python, general programming principles, and the “Pythonic” idioms. A good course on Udemy or book about Python is about what you need. Subtract if you already understand some of this, if you’re a fast learner, or have guidance (such as a mentor.)

But it’s not really about how quickly you can absorb knowledge, it’s practice to retain it, and having the time to make mistakes and experiment.

And then it will only take a week or two to pick up Selenium. It has a fairly straightforward API, and the concepts of automating finding buttons and clicking on them is fairly simple to understand. There are some obstacles that can trip you up though — things like provisioning and configuring a WebDriver, managing sessions, “getting” locators like XPath and CSS, data driven, using Pytest and fixtures, etc can trip you up and lead to hours (or days) of frustration — or you can establish bad habits that will bite you in the future.

But applying Selenium in a meaningful way to write useful test automation may take additional weeks, or months (or years) of practice. Again, this depends on your personal curiosity, cleverness, mentoring opportunities, and above all, practice and ability to apply it in the real world.

These challenges fall under writing good maintainable test automation, knowing what to test and how to approach it, and even little things like picking good locators, or naming functions and variables well.

If you were smart, and scrolled to the bottom, short answer is:

It should only take you a few weeks to pick up Python and Selenium, depending on where you are coming from experience-wise and how fast you learn. Having mentors and or guided learning can help you focus on what’s important and get past silly obstacles. But like anything, it will take a much longer time to master, and depend on real world experience applying the principles, making mistakes, and learning from them.

A reasonable time to go from basic programming knowledge and no test automation experience to competent enough to make an impact at a job (e.g. get hired as a junior test automation engineer) is a few months of steady learning and practice.

Updating test results in QC using the QC OTA API explained

Yesterday I cleaned up and posted my example QCIntegration utility on GitHub.

While it works as a standalone tool, some people might not want to wade through the code to understand or modify it. So today, I’m going to try to explain how the OTA API works by recreating the steps as a blog post with explanation in a simple script.

I’ll start with an example using C# and then give an equivalent Python example. I’ll use the same scenario, updating test case results in QC, but if requested, I can also show how to get test steps from a test plan, or read & update defects in QC using the OTA library.

First, create a new project in Visual Studio (or SharpDevelop). You’ll need to add the OTAClient.dll as a reference. It is a COM library and contains the single interface TDConnection.

When searching for the library name it is called the “OTA COM Type Library”. The package is “TDApiOle80.” Since it is a COM library, it needs to use an interop for C#, but this is handled automatically by the IDE.

using TDAPIOLELib;
TDConnection conn = new TDConnection();

Now, let’s create a connection to your Quality Center server. You’ll need to know the URL of your QC Server and have valid login credentials with access to an existing Domain and Project.

Assuming you have quality center installed on your local machine (not a typical setup) you might have the following setup:

string qcUrl = "http://localhost:8080/qcbin";
string qcDomain = "oneshore";
string qcProject = "qa-site";
string qcLoginName = "aaron";
string qcPassword = "secret";

Note: I do not use this same password for my bank account

There are several ways to log in, but I’ll use the simplest here:

tdConn.InitConnectionEx(qcUrl);
tdConn.ConnectProjectEx(qcDomain, qcProject, qcLoginName, qcPassword);

Now you need to find your test sets that need updated. I typically use folder structure that goes something like:

Project – Iteration – Component – Feature

It’s a bit convoluted but here’s the code to get a testSet:

string testFolder = "Root\QASite\Sprint5\Dashboard\Recent Updates";
string testSet = "Recent Updates - New Defects Logged";

TestSetFactory tsFactory = (TestSetFactory)tdConn.TestSetFactory;
TestSetTreeManager tsTreeMgr = (TestSetTreeManager)tdConn.TestSetTreeManager;
TestSetFolder tsFolder = (TestSetFolder)tsTreeMgr.get_NodeByPath(testFolder);
List tsList = tsFolder.FindTestSets(testSetName, false, null);

The parameters for FindTestSets are a pattern to match, whether to match case, and a filter. Since I’m looking for a specific test set, I don’t bother with the other two parameters.
You could easily get a list of all test sets that haven’t been executed involving the recent updates feature by substituting this line:

List tsList = tsFolder.FindTestSets("recent updates", true, "status=No Run");

Now we want to loop through the test set and build a collection of tests to update. Note that we might have more than one test set in the folder and one or more subfolders as well:

foreach (TestSet testSet in tsList)
{
	TestSetFolder tsFolder = (TestSetFolder)testSet.TestSetFolder;
	TSTestFactory tsTestFactory = (TSTestFactory)testSet.TSTestFactory;
	List tsTestList = tsTestFactory.NewList("");

And finally, update each test case status:

    foreach (TSTest tsTest in tsTestList)
    {
        Run lastRun = (Run)tsTest.LastRun;

        // don't update test if it may have been modified by someone else
        if (lastRun == null)
        {
            RunFactory runFactory = (RunFactory)test.RunFactory;
            String date = DateTime.Now.ToString("yyyyMMddhhmmss");
            Run run = (Run)runFactory.AddItem("Run" + date);
            run.Status = "Pass";
            run.Post();
        }
    } // end loop of test cases

} // end outer loop of test sets

Of course you might want to add your actual test results. If you have a dictionary of test names and statuses, you can simply do this:

Dictionary testResults = new Dictionary();
testResults.Add("New defects in Recent Updates are red", "Pass");
testResults.Add("Resolved defects in Recent Updates are green", "Pass");
testResults.Add("Reopened defects in Recent Updates are bold", "Fail");

if (testResults.ContainsKey(tsTest.TestName))
{
    string status = testResults[tsTest.TestName];
    recordTestResult(tsTest, status);
}

That’s all for now. I’ll translate the example into Python tomorrow, but you’ll see it’s really quite straightforward.

Links: Unit Testing and Continous Integration with Flex and AsUnit

Just a bunch of links to tutorials on using AsUnit and continuous integration with Flex Projects:

A post on AsUnit by one of it’s creators,  Luke Baye’s:
http://asserttrue.com/articles/2006/03/10/AsUnit25

An example of a simple TestRunner mxml (AS2):
http://asserttrue.com/articles/2006/10/05/flex2-mxml-project-support-in-asunit

Luke’s post on continous integration:
http://lukebayes.blogspot.com/2005/11/continuous-integration-with-asunit.html

A good tutorial about using AsUnit (but with only a Flash testRunner):
http://www.insideria.com/2008/09/unit-testing-with-asunit.html

Another good tutorial about using AsUnit:
http://www.insideria.com/2008/05/anatomy-of-an-enterprise-flex-10.html

Discussion of one team’s unit test framework requirements:
http://www.eyefodder.com/blog/2006/06/unit_test_frameworks_for_as3_a.shtml

Weaknesses and strengths of FlexUnit and AsUnit:
http://www.eyefodder.com/blog/2006/07/flexunit_asunit_deathmatch_res.shtml

Story of their use of Continuous Integration:
http://www.eyefodder.com/blog/continuous_integration/
http://www.eyefodder.com/blog/2006/05/continuous_integration_with_fl.shtml
http://www.eyefodder.com/blog/2006/05/continuous_integration_with_fl_1.shtml
http://www.eyefodder.com/blog/2006/05/continuous_integration_with_fl_2.shtml
http://www.eyefodder.com/blog/2006/05/continuous_integration_with_fl_3.shtml
http://www.eyefodder.com/blog/2006/05/continuous_integration_with_fl_4.shtml
http://www.eyefodder.com/blog/2006/05/continuous_integration_with_fl_5.shtml
http://www.eyefodder.com/blog/2006/05/continuous_integration_with_fl_6.shtml

A flash-oriented tutorial, but with good AsUnit explanations:
http://marstonstudio.com/2007/07/28/asunit-testing-with-flash-cs3-and-actionscript-3/

Testing tutorials to write

Here are the testing tutorials I’m going to work on:

Selenium
Fit & Fitnesse
Watir
Customizing Bugzilla
Bugzilla features: web services and email_in
TestNG vs. Junit
PHP SimpleTest
Perl Test::Class & WWW::Mechanize
Test Planning, Test Cases & Defects