Jenkins Selenium TFS Integration

Hi all, in this article, we will learn how to integrate Selenium C# .NET test automation codes with Jenkins. The conditions are listed below:

Version Control System: TFS

Test Automation Framework: Selenium C# .NET

Continuous Integration Tool: Jenkins

Required Plugins:

First, you need to install Jenkins and required plugins in your CI environment. If everything is OK. Then, you need to create a Jenkins Job.

These are also described in this article step-1 to step-8 extensively.

You should create a “Freestyle project

Then open your project (item/job) and click “Configure” link.

Give a name to a project and keep how many builds do you want in your CI environment as shown below. In below case, I am holding 10 builds.

If your tests are parametric then you should set your parameters as shown below. Passing some parameters like Browsers and URL from Jenkins Job to C# code allows doing a lot of stuff and manipulation to make your Automation more powerful.

 

When you add above parameters, you can get them in your C# code as follows:

//Getting the browser parameter from the Jenkins Job
SelectedBrowser = System.Environment.GetEnvironmentVariable("Browser");

switch (SelectedBrowser)
{
    case "Chrome":
        Browser = new ChromeDriver();
        break;
    
    case "IE":
        var options = new InternetExplorerOptions()
        {
            //InitialBrowserUrl = baseURL,
            IntroduceInstabilityByIgnoringProtectedModeSettings = true,
            IgnoreZoomLevel = true,
            EnableNativeEvents = false
        };
        Browser = new InternetExplorerDriver(options);
        break;

    case "Firefox":
        Browser= new FirefoxDriver();
        break;

    default:
        Browser = new ChromeDriver();
        break;
}

After this settings, you should configure repository (source code management) settings for TFS as shown below.

If you want you can select a Build Trigger. If you don’t select any of them, then you can trigger your Jenkins job manually. I did not select any of these options so I will trigger Jenkins job manually.

Now, we should Build our test automation project as shown below. But before you should to some settings. These are described in this article at step-7.

And now it is time to Run our Test Automation Codes with below NUnit console command.

"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" "C:\Program Files (x86)\Jenkins\jobs\KariyerNet Aday Web Otomasyon\workspace\KariyerNetCandidateTest\bin\Debug\KariyerNetCandidateTest.dll" /result:nunit-result.xml;format=nunit2

If you are using ExtentReports, you should show the results with below Post Build Action.

Note: If you faced with a problem displaying ExtentReports’s report, you do following settings. Jenkins disables CSS and JS scripts. Thus, HTML file functions do not work well. You should run below command in Jenkins Script Console.

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

Also, you should add below lines into jenkins.xml to make these settings permanent.

<executable>java.exe</executable>
<arguments>[arguments are here]</arguments>

Reference: http://stackoverflow.com/questions/35783964/jenkins-html-publisher-plugin-no-css-is-displayed-when-report-is-viewed-in-j#35785788

Finally, Publish NUnit Test Results and send e-mail notifications.

Thats all. :)

Thanks.
-Onur

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.