Logging with Logback in Scala

Posted in Scala | Tagged , , ,

Introduction to CSS3

Posted in CSS | Leave a comment

Generate the Advance level of Test Report of Selenium with Image using Scala

Generating the test report of test cases is the important part of selenium tool. When we write the test cases in selenium and execute the these test cases we always find the pass/fail result. so if we want to generate the report of these test cases in html format ,we can use the Extent Report .we will do just add the jar file of extent report in our project and call in our packages.

Add the jar files- extentreports-java-141.jar

package SeleniumTest
import java.io.BufferedInputStream
import java.io.File
import java.net.URL
import java.util.concurrent.TimeUnit
import org.apache.pdfbox.pdfparser.PDFParser
import org.apache.pdfbox.util.PDFTextStripper
import org.openqa.selenium.firefox.FirefoxDriver
import org.scalatest.FlatSpec
import play.api.test.FakeApplication
import play.api.test.Helpers.HTMLUNIT
import play.api.test.Helpers.inMemoryDatabase
import play.api.test.Helpers.running
import play.api.test.TestServer
import setup.Testsetup
import com.relevantcodes.extentreports.ExtentReports
import com.relevantcodes.extentreports.LogStatus
import org.fest.assertions.Assert

class GenerateReport extends FlatSpec with Testsetup {

  running(TestServer(port, FakeApplication(additionalConfiguration = inMemoryDatabase())), HTMLUNIT) { browser =>

    "Application" should "Generate report" in {

       val knol = ExtentReports.get(classOf[GenerateReport])
       knol.init("/home/neeraj/Pictures/report.html", true)
       knol.startTest("Verify Page Title");
       val driver = new FirefoxDriver()
       knol.log(LogStatus.INFO, "Browser started")
       knol.log(LogStatus.INFO, "information with www.knoldus.com");
       val title=driver.getTitle();
       knol.log(LogStatus.INFO, "Get the current title");
       knol.log(LogStatus.INFO, "Browser closed");

generate report

when all the test case are successfully completed, a html report file is automatically will generate in giving folder whose screen shot we can seen in below image which is completely shown the pass fail status according to colour as well as if you want to  seen any image in your report so we can also attach these image in this report.

Screen shot of report.html-


Posted in Scala

Introduction to AngularJS


Below is the CRUD Application i made using AngularJS, NodeJS, and MongoDB


Posted in Scala

Extract Text from PDF file using Selenium Webdriver in Scala

If we want to verify PDF content during the testing  or you want to test the PDF file in scala then you have to follow these code because selenium webdriver does not provide the direct method to extract the text from PDF.

First of all we have to add dependency for pdfbox in build.sbt

libraryDependencies ++=  Seq(
"org.apache.pdfbox" % "pdfbox" % "1.8.2"

Code for Extract text from pdf file-

package SeleniumTest

import java.io.File
import org.apache.commons.io.FileUtils
import org.openqa.selenium.OutputType
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.remote.Augmenter
import org.scalatest.FlatSpec
import play.api.test.FakeApplication
import play.api.test.Helpers.HTMLUNIT
import play.api.test.Helpers.inMemoryDatabase
import play.api.test.Helpers.running
import play.api.test.TestServer
import setup.Testsetup
import java.io.BufferedInputStream
import java.util.concurrent.TimeUnit
import java.net.URL
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.util.PDFTextStripper;

class Pdfformat extends FlatSpec with Testsetup {

running(TestServer(port, FakeApplication(additionalConfiguration = inMemoryDatabase())), HTMLUNIT) { browser =>
"Application" should "Extract Text from pdf file" in {

val driver = new FirefoxDriver()
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
val url = new URL(driver.getCurrentUrl());
val fileToParse=new BufferedInputStream(url.openStream());
val parser = new PDFParser(fileToParse);
val output=new PDFTextStripper().getText(parser.getPDDocument());
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);


Posted in Scala | Tagged , ,

Couchbase : Making views via script file automatially without using GUI.

The problem that we faced is that we have to make views manually from the GUI of the couchbase, but it was quite a cumbersome task, so this blog is about how to make views automatically.

In this blog we’ll learn how to create a script of curl commands and just run that script for making views and the  views  will automatically get created on the couchbase server.

You do not have to make views manually now, just run a script file and it automatically gets created , so that you don’t have to make views manually on staging server and it can easily be made just by running a simple script file.

For creating a design document and views from a script file :

Firstly , you have to make a .ddoc file, the name of file should be same as that of the design document that you want to create.

Screenshot from 2015-07-23 12:25:35

Then inside that .ddoc file you have to write the json for creating view

Its format would be like :

{“views”:{“email”:{“map”:”function (doc, meta) {\n  emit(doc.email,meta.id);\n}”}}}

Where email is the view name and map has the function that we write in the views.

If you are using Javascript functions inside your view then you can change the value of the function accordingly.

{"views":{"name":{"map":"function (doc, meta) {\n  if(doc.email!=null){\n  emit(doc.email,doc.name);\n}\n}"}}}

If you are using reduce function then also you can give it in the same json using reduce element.

For Example:

{"views":{"name":{"map":"function (doc, meta) {\n  if(doc.email!=null){\n  emit(doc.email,doc.name);\n}\n}","reduce":"_stats"}}}

If you want to make more than one view inside a design document then you can change the json accordingly

(doc, meta) {\n  if(doc.email!=null){\n  emit(doc.email,doc.name);\n}\n}","reduce":"_stats"},"code":{\n emit(doc.name,null);\n}}}

Then save this file with name emailDocument.ddoc

So for example now you have

Design document: emailDocument

View Name : email

Now for making this view make a script file for example :curl.sh

And inside script file ,write this command :

curl -X PUT -H ‘Content-Type: application/json’ http://Administrator:<password>@localhost:8092/user-account/_design/dev_email -d @email.ddoc

And then save this file.

And now when you execute this script using ./curl.sh command

It will automatically make the view in the Couchbase.

And It will give you a response json, if it gets made up successfully. The json would be like

Posted in Scala | Tagged ,

Introduction to Google Guice

Posted in Scala | Tagged , ,

Couchbase : How to access and change the document of size more than 2.5Kb.

We faced a situation were we have to firstly see the data and then change it accordingly in couchbase, but the GUI of couchbase doesn’t allows us to see the data of size more than 2.5kb and forget about changing,

Screenshot from 2015-08-07 12:36:16

So there is a quick hack of how you can actually change the data without using the GUI and just by making a curl request:

If you want to see the data :

Just make this CURL request

curl -X GET -H "Content-Type: application/text" "http://Administrator:&lt;password&gt;@&lt;server address&gt;:&lt;port number&gt;/pools/default/buckets/&lt;bucket-name&gt;/docs/&lt;doc-id&gt;"


curl -X GET -H "Content-Type: application/text" "http://Administrator:123456@localhost:8091/pools/default/buckets/user/docs/shivansh"

And you’ll get a response like this :

{"meta":{"id":"shivansh","rev":"4-13f81d12a58600000000000000000000","expiration":0,"flags":0},"json"</code><code class="wrappedText focusRow">:{"click":"Shivansh","new in 2.0":"there are no reserved field names"}}

And inside the field json you’ get your required Json,

You can easily do this just by seeing developer console.. ;)

Now the big task i.e. If you want to change the data

So for that firstly retrieve the data from above request make changes, and then make a POST request to the same url with the new Json. It will get updated.


curl -X POST -H "Content-Type: application/text"
"http://Administrator:12345@localhost:8091/pools/default/buckets/user/docs/shivansh" -d'{"name": "Shivansh", "last name": "Srivastava"}

And it will automatically update the required document.

Posted in Scala | Tagged , , ,

Introduction to OAuth2

Posted in Scala | 2 Comments

Scala Days 2015 Pulse – Sentiment Analysis of the Sessions

As you might have read that the Pulse Application from Knoldus created a flutter at Scala Days 2015. In this post let us dig deeper into some findings. We are already getting some cool requests to open source the code which we would do soon. We would just like to strip out the dictionaries that we have used.
Screenshot from 2015-07-17 19:05:01We collected 5K+ tweets over the period of 2.5 days. These were tweets which were either done with the speaker handle or with the ScalaDays hashtags. Overall the conference was very positive sentiment wise. There were around 37% positive tweets detected and less than 4% negative sentiments detected.
Screenshot from 2015-07-17 19:08:39

Martin Odersky and Jonas Boner were had the largest number of tweets followed closely by Helena Edelson.

Screenshot from 2015-07-17 19:30:30

Roland Kuhn‘s excellent session on Actors vs Types got an undue amount of negative tweets just because people were not able attend his session. The room was packed to capacity and still many people wanted to get in. The conference organizers got into action quickly and announced another session for the wonderful speaker for all the people who could not attend.

Dean Wampler‘s Spark session was famous as expected. So were the sessions from Adam Gibson and Amanda Laucher.


You can get a complete view of the sessions with the tweets on scaladays.knoldus.com The product would be up for another few weeks. If it is not available then the PDF snapshot of the analysis is attached at the bottom of the post. We would be making the tweet data available for further analysis and playing as a part of Zepplin board soon. Stay tuned.

PDF version of ScalaDays 2015 Analysis

Posted in apache spark, Scala, Spark | Tagged , , | 2 Comments