How can I integrate my TestNG tests with Selenium in TeamCity? - selenium-webdriver

Please guide me through the steps on setting up TeamCity so that it can run my TestNG tests.
My Objective: Whenever I run a new build on TeamCity, it should automatically trigger my testNG suite on the new build.
I am using the following tools:
IDE: Eclipse
Automation Tool: Selenium Webdriver
Language: Java
Test Runner Framework: TestNG
Any reference to link or website would be very helpful.

You should integrate ANT in your selenium+TestNG framework so that you can run the tests from a build script. Plus, TeamCity's docs say that
TeamCity directly supports the following testing frameworks:
JUnit and TestNG for the following runners: Ant (when tests are run by
the junit and testng tasks directly within the script)
Some links:
Apache ANT
ANT Tutorial
TestNG with ANT
So once you create your build script in build.xml file which should lie in your framework's root folder, you should configure your build job and add a build step (with an ANT build runner) in TeamCity to run this build.xml after TeamCity finishes building/deploying the app. You can do that by specifying a step execution policy for the ANT build step.

Related

uploading the test report from jenkins to Alllure TestOps

We are using WebDriverIO and jenkins for managing our tests.
We are trying to integrate the jenkins with allure TestOps and upload the reports to allureTestOps.
Do we need to configure the allure with gherkin or webDriverIo that we are using.

Does Selenium- Jenkins Integration needs TestNG or JUnit Framework

Should we need TestNG or Junit framework to integrate Selenium with Jenkins. I have project which is build without TestNG or JUnit can i integrate it with Jenkins.
You can use both JUnit and TestNG frameworks as Jenkins supports both.
Steps in details for TestNG integration with Jenkins.
Step 1: Create Free Style project in Jenkins and fill the details and Save the project.
Step 2: click on Configure
Step 3: In the Build section of Configure:
java -cp J:\taf\testng\*;J:\taf\workspace\TestNGExamples\bin;J:\automation\* org.testng.TestNG J:\taf\workspace\TestNGExamples\testng1.xml
Note: you have to change the paths as per your system.
In -cp argument, we must provide testng.jar, project location and ``selenium jarslocations/paths.
org.testng.TestNG- TestNG Main Class.
andlocation to the XML of testng configuration`
Download and install the testng-plugin for jenkins from here and restart Jenkins in order to take effect.
Step 4: In the Post-build Actions section,
Select Publish TestNG Results from Add post-build action dropdown.
provide the path where to look for TestNG results (.xml file containing results).
Click Apply and Save buttons.
Screenshot for reference:
TestNG and JUnit on simple terms can be visualised as "java code execution" mechanisms with support to do validations.
So instead of you having only one main() method that would be the single point of entry for execution of your selenium code, TestNG/JUnit takes up that role and lets you run multiple java classes via themselves.
Jenkins is an orchestrator tool that lets you build, test, deploy as per your wish.
The test phase can be skipped by not using TestNG and JUnit, and you resorting to executing your selenium based tests via a main() method which takes care of doing all validations as well (assertions in the JUnit/TestNG world)

TestNG Executable JAR files

Is the TestNG Executable JAR files alone is enough to work with TestNG framework or the TestNG plugin is essential? I have the JAR files, can i add to my library and work with TestNG?
Plugin just simplifies running things. You do not need it so to say. But, if you say want to run a single test or a suite file - a plugin would give you a simple way to right click and trigger it off. But with no plugin you will have to run with the java run command or through maven command if that's what you are running.
So the answer is yes - you can run but the plugin will always help while you are developing your tests.

Manage Protractor tests with a single Gulp task

I'm trying to get e2e testing going with on my angular project using Gulp.
I'm able to get it working, but only if I manually launch a standalone selenium server using webdriver-manager start in a seperate terminal window.
Ideally I would like my gulp task to manage starting and stopping the server so as to not add more overhead for my team to run these tests.
I got set up following the instructions here:
https://github.com/mllrsohn/gulp-protractor
They describe 2 options for starting the selenium server. One is to set up a gulp task which appears to do the same thing as webdriver-manager start:
gulp.task('webdriver_standalone', require("gulp-protractor").webdriver_standalone);
This works, but not when I have my e2eTest task invoke it as a dependency. I have to run gulp webdriver_standalone in a seperate terminal window.
I cannot understand the other suggested option.
point to the selenium jar in the protractor config file
These instructions require a path to the selenium-server-standalone jar, in protractors node_modules (./node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar), but my node_modules/protractor/ directory does not have such a jar (or a selenium sub-directory at all)
The instructions for Running Protractor without a plugin seem to have the same problem of having to run the selenium server in another terminal window.
Is there a way to get this set up so that a single gulp task starts the standalone server, runs the tests, and shuts it down with no other intervention?
When you run Protractor you have several options regarding Selenium WebDriver (remember that WebDriver is web-service written in Java):
Run with Protractor with remote (standalone) service. It can be either local or on different machine. If Selenium is on different machine then your web app should be publicly available, not just localhost. If you choose to use standalone Selenium service then you configure your config file/Gulp task with seleniumAddress option.
"Ask" Protractor to run Selenium for you. In this case Protractor will run Selenium WebDriver with the Jar file you provide in seleniumServerJar configuration.
Do not use Selenium WD. Use direct connect instead, which is compatible with Chrome and (probably) Firefox only.
In your case simply run:
./node_modules/protractor/bin/webdriver-manager update
It will download Selenium. Then point config to the right jar.
The easiest way to get this working locally is using a local Selenium Standalone jar, as Igor suggested in option #2. (It is pretty difficult to get gulp to run webdriver-manager start as a spawned child_process or async task.)
You can get that jar in your node_modules folder easily by using:
npm install selenium-server-standalone-jar --save-dev
Then, in your protractor.conf.js comment out or remove the seleniumAddress line and add a line for seleniumServerJar.
exports.config = {
seleniumServerJar: '../node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.47.1.jar',
//seleniumAddress: 'http://localhost:4444/wd/hub',
/* Lines below for completeness only, leave yours as is. */
framework: 'jasmine2',
specs: ['login-spec.js'],
multiCapabilities: [{
browserName: 'chrome',
browserName: 'firefox'
}]
};

What is the use of node.js in protractor?

I'm very new to AngularJS. I am trying to automate an angularJS app.
installed node.js
installed protractor (npm install -g protractor)
updated webdriver manager tool (webdriver-manager update)
started the driver (webdriver-manager start)
I create a simple conf.js and spec.js files. Everything works fine and set to go.
when we execute spec.js, protractor talk to selenium webdriver which then launches the browser and does the other stuff like interacting with angularJS app. Am I correct?
So, what is the role of node.js here in protractor?
I might be wrong, if so please do correct me and explain how protractor works.
Thanks in advance :)
Node.js is an open source runtime environment to develop applications in JavaScript.
WebDriverJS has been written in Node.js and Protractor has been written on top of WebDriverJS.
Node.js will be executing the javascript code you've written in your spec and po files with its JavaScript Engine (Google V8), or as you've so colourfully described: "does the other stuff like interacting with angularJS app".
Read more here and here
Protractor is a Node.js application... hence the Node requirement. Protractor is written in Javascript, so it requires a Javascript engine, which Node provides (Google V8), thus allowing it to run on a server.
Node.js is package file we are using in protractor automation tool to run the angular.js based application.It contains selenium and other browser drivers to run our applications in different environments.

Resources