coding Archives | Online Productivity Solutions Pvt. Ltd. Tue, 22 Oct 2019 08:59:43 +0000 en-US hourly 1 GraphQL vs Rest API https://opspl.com/blog/graphql-vs-rest-api/ https://opspl.com/blog/graphql-vs-rest-api/#respond Fri, 13 Sep 2019 08:58:06 +0000 https://opspl.com/?p=10453 GraphQL is a data query language architectured and developed by Facebook. It was developed for as an alternative to REST API.

The post GraphQL vs Rest API appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
Introduction to GraphQL

GraphQL is a data query language architectured and developed by Facebook. It was developed for as an alternative to REST API. It gives a total and reasonable depiction of the information in your API, enables customers to request precisely what they need and nothing more makes it less demanding to advance APIs after some time and empowers ground-breaking developer tools.

Introduction to REST API

For the past decade or so we have been using REST API. It is the most popular API. Most of the businesses have adopted the trend of REST API. This can be used over nearly any HTTP methods. As it works on HTTP as well as HTTP2 protocol, this enables developers to reduce the dependency over additional software.

Similarities between Rest and GraphQL

We come across a new problem with every evolving technology and hence we come up with a new technology that intends to solve those problems. But there lie some similarities between them and this is also true with these two APIs. So what could these two share for all intents and purpose? Indeed, one clear thing they share for all intents and purpose is that they are the two details for building and expending APIs. Additionally, REST and GraphQL can both be worked over HTTP, however, GraphQL is convention skeptic. GraphQL Endpoint is mostly called using an HTTP post Method.

Differences between Rest and GraphQL

So now we can come to the differences and see exactly what problems these two API’s were intended to resolve.

Data Fetching

GraphQL has a query based data fetching mechanism. In case of REST API, several requests are made to single or multiple endpoints for data retrieval purpose.

Network Requests

It might take REST to make 10 requests to get a particular data but using GrapgQL, a significant advantage is that can now be done in one request itself.

Over/UnderFetching

In GraphQL we can request only for the data we want and ignore fetching of unwanted data.

But the same isn’t true for REST, as it fetches everything, from which unwanted data need to be discarded by the endpoint consumer.

Error Handling

Error handling in REST is pretty clear, we essentially check the HTTP headers to get the status of a response. Depending on the HTTP status code (404, 503, 500, etc.) we get, we can without much of a stretch tell what the Error is and how to approach settling it. GraphQL then again, when worked over HTTP, we will always get a 200 OK reaction status.

Caching

As REST is implemented using Http which already has caching baked in, it avoids refetching of data. However, GraphQL has no caching functionality baked in for caching.

Tools Used for Graphql

• Graphiql

• Apollo Optics

• Graphcool

• GraphCMS

Tools for RestAPI

• Postman

• Insomnia

• Rest Client

Conclusion

Based on my experience, I feel GraphQL reduced my coding time by considerably reducing the code that I had to write as compared to what I had to write for the REST API. There is no perfect fit for all situations and conditions and so first you will need to check your situation and need, then based on that, you will have to make your decision.

 

Snivio Braganza

The post GraphQL vs Rest API appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
https://opspl.com/blog/graphql-vs-rest-api/feed/ 0
Easy Code Sharing And Collaboration With Bitbucket https://opspl.com/blog/easy-code-sharing-and-collaboration-with-bitbucket/ https://opspl.com/blog/easy-code-sharing-and-collaboration-with-bitbucket/#respond Fri, 06 Sep 2019 12:13:14 +0000 https://opspl.com/?p=10442 Bitbucket is one among the code sharing and collaboration tools that lets your team choose how you want to work with your code. You can host it on your own servers or run it from the cloud. You'll always know where to look when you need code as you can organize the work into Teams, Projects, and Repositories.

The post Easy Code Sharing And Collaboration With Bitbucket appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
Every developer has experienced moments in their career when they need to share code or gain some backing when something is just not going their way. Right from College projects to working in projects in an Organisation, getting workflow just right isn’t an easy task. Writing code with another developer while working on a project as a team is a great way to absorb knowledge, challenging yourself with new perspective and ultimately delivering a better software. Unfortunately, this can be such a hassle at times and people don’t bother. It can be challenging and undesirable for remote or development teammates to share the same physical machine or move the entire workflow into a hosted environment.

Times have changed, incorporating this kind of sharing and collaboration into the workflow has been improving at a fast pace impacting how the developers work with teams touching the same code base. Bitbucket is one among the code sharing and collaboration tools that lets your team choose how you want to work with your code. You can host it on your own servers or run it from the cloud. You’ll always know where to look when you need code as you can organize the work into Teams, Projects, and Repositories.

To collaborate on code, Teams let you add multiple people to your account so you can be part of multiple teams working for different projects at once. Projects, then, come under teams, which break the work up into sections. Repositories are where you store the actual code and files you’re working on. Projects can be made private, so that they can be visible to people only in that project team.

Bitbucket includes the tools you need for working with the code. Once you’re ready with a code base, you can create a new repository or import one from GitHub. When you want to work on the project in the repository, all you have to do is clone the main repository, make your changes, commit your changes and then push them back to the main repo.

As the team makes changes to the clone ad pushes the final result, every commit has comments which help the other teammates to figure out what are the changes made, which changes to add, and what still needs to be worked on. You can view code online or download it directly, see commits, branches, pull requests, and compare the changes between each version of the commit. Bitbucket also includes snippets for smaller bits of code which can be reused later.

After logging in to your BitBucket account, Go to Project and click on “Create Repository” option to open up a repository creation form (see Fig. 1).

Create-Options

Once a repository is created it will take you to Repository homepage. (see Fig. 2).

Repository-homepage

Until the next set of instructions are followed, there won’t be any content in repository. Following are some instructions to push your project code to your repository:

To get started, you need to run the following commands in your terminal/command window:

cd <Project Directory>

git init

git add –all

git commit -m “Initial Commit”

git remote add origin <Repository Link>

git push origin -u master To collaborate and share the project code with team members, find your clone URL in the left hand sidebar of the repository homepage and share it (see Fig. 3).

NOTE : In order to grant access to users of this repository, you have to set up permissions at the parent project level.

Completing a project and turning your code into a product for the client isn’t simple, but integrating and collaborating your code with the suitable dev tools can help you work as a  team more efficiently

 

Ashmitha Lopes

The post Easy Code Sharing And Collaboration With Bitbucket appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
https://opspl.com/blog/easy-code-sharing-and-collaboration-with-bitbucket/feed/ 0
Mistakes a Programmer Can Avoid in a Tech Company https://opspl.com/blog/mistakes-a-programmer-can-avoid-in-a-tech-company/ https://opspl.com/blog/mistakes-a-programmer-can-avoid-in-a-tech-company/#respond Fri, 09 Nov 2018 04:50:23 +0000 https://opspl.com/?p=7754 Most of the people reading this blog will mostly be programmers or developers or someone who shows interest towards IT. Those of you who have worked on an IT related project, or even students for this matter, will understand that the life cycle of a project has to be done in stages, and a lot...

The post Mistakes a Programmer Can Avoid in a Tech Company appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
Most of the people reading this blog will mostly be programmers or developers or someone who shows interest towards IT. Those of you who have worked on an IT related project, or even students for this matter, will understand that the life cycle of a project has to be done in stages, and a lot can go wrong during this life cycle.

So if a software life cycle is done in stages, then nothing can go side ways, right? WRONG, there are chances that something can go side ways! And one of the major contributing factors to this is simple, deadlines. With clients having their needs and demands, we need to meet the deadline in order to keep them happy (Unless you do things at your own pace, which in my opinion usually takes more time and is a waste). Happy clients equal more projects or opportunities. But what we fail to ignore is the consequences of doing things rapidly and ignoring the simple things that can cause an unpleasant user experience. For example, during API Testing, if the response is a 200 that is returned, we assume that it is working and sometimes tend to overlook the actual output returned (I’m sure some of you’ll have experienced this ‘cause I did when I started programming).

So let’s get down to putting a few mistakes a programmer can avoid while working in a tech company.

Firstly, Caching. Those of you who have developed websites, will understand this point more clearly. What is Caching? For those who aren’t familiar, in simple English, it stores information somewhere on your computer for future use. So why is caching important for websites, and APIs? It basically helps the server to reduce the load on itself and allows for more users to access the same service without it’s performance getting affected. “So if I have a cached copy stored on my system, I’m good to go?” Well, not really, this cache needs to be updated after set intervals. An expired cached copy can cause a user problems at high traffic time and probably not even return a proper response to the user. It is the developer’s job to not overlook this aspect and ensure that the user isn’t negatively affected by it. After all, if a website is poorly created and can’t display things that the user expects, why would anyone even visit the site?

Secondly, Lack of communication. I noticed this issue when I started working, but thankfully, this isn’t an issue for me any more. Communication is very important when it comes to working in a team. In an IT team, we create new software and programs where everyone’s contribution can lead it to be a successful one. But what happens when there is no proper communication between team members? Each member does the work the way they want to do it and when it comes down to merging all of it together, BOOM, Failed software. All this trouble for the simple fact that the members were not communicating properly. To be honest, when I started working on my first project, it was a handover from a senior, as the senior had resigned for whatever reason, it felt like the project was just dumped on me, and the handover wasn’t even properly done. Nonetheless, even though the other seniors were busy in their own projects, they lent a helping hand whenever they could. But for the rest of it, I was on my own, until we had newer members joining the team, and one of them on the project I was handling. Life got a lot easier working as a team and we started to show results at a much better progressive rate. So remember, communication is one of the keys to opening a door to a successful step ahead to something better, and of course, building a terrific software.

Thirdly, Compatibility. While some software are targeted for a specific version, sooner or later, perhaps never, some modifications or updates need to be made to the existing software. This not only applies to software developed, but also to software that are under development. Let’s take this example for instance. If a member of your team were to develop a piece of code that is not compatible with your code due to a version mismatch or outdated/deprecated method, then both of you’ll need to sit down and discuss which is the best approach to move forward and ultimately, one of you’ll will have to rework the code, which is a waste of time. So remember to communicate with your team member(s) and be sure that you’ll are looking towards the same thing.

Lastly, Localization. While some clients have a fixed audience, we need to consider that the client can change their mind and want to reach a wider audience, and this includes people from different countries with different dialects. There are so many dialects in this world, is it necessary to incorporate all of these languages for localization? No, ideally, the best approach would be to use common languages such as English, Hindi, Portuguese and French. Unless specified otherwise by the client.

To summarize, by the quote of G.I. Joe, Knowing is half the battle. And what this means is, the sooner you recognize these mistakes or any other mistake which you feel that can be avoided, the better it is for everyone on the team. It saves time and effort, and you don’t have to break your head as to why the system isn’t working the way it should. These were a few common mistakes a programmer can avoid when working in a tech company. Hope all if not, some of these points have enlightened you to work better and take you to greater heights with your team.

 

Ian Coutinho

The post Mistakes a Programmer Can Avoid in a Tech Company appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
https://opspl.com/blog/mistakes-a-programmer-can-avoid-in-a-tech-company/feed/ 0
WebAssembly https://opspl.com/blog/webassembly/ https://opspl.com/blog/webassembly/#respond Fri, 19 Oct 2018 12:00:14 +0000 https://opspl.com/?p=7566 Since the dawn of time, native applications have always delivered a larger-than-life performance compared to web applications. Any web application could never enable or scale to the full functionality of the device expected from apps like games, multi-media intensive apps, high data processing apps, etc. JavaScript wasn’t designed to be fast for very large applications....

The post WebAssembly appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
Since the dawn of time, native applications have always delivered a larger-than-life performance compared to web applications. Any web application could never enable or scale to the full functionality of the device expected from apps like games, multi-media intensive apps, high data processing apps, etc. JavaScript wasn’t designed to be fast for very large applications.

“WebAssembly (or Wasm) is a binary instruction format for a stack-based virtual machine.” Wasm is a portable platform to compile high-level languages like C & C++ to be deployed on the web. The code will execute at speeds previously achieved by assembly programs. Web assembly doesn’t replace the way the web works; JavaScript will not be replaced, but rather an improvement to it.

Wasm is aimed to be efficient & fast. Web assembly includes a stack machine that encodes the code in load-time efficient binary format. This allows it to achieve native speeds. Web assembly is a sandboxed environment that guarantees safety of your device. It also will not allow cross-origin that makes the device vulnerable.

Wasm is built as a binary format. It’s very compact to download and also very efficient to compile & execute. Wasm enables speed in 2 areas; first in app start-up speed (2x or more) and secondly in throughput (compiled code runs faster). With Web assembly, we can now have real 64-bit integer data type, more control over memory management & smooth performance throughout the application.

With Wasm, developers across spectrums can bring their native C or C++ applications to the web & reach efficient performance capabilities of the device. This in-turn means no downloads, malwares, etc. as there is no need for installation on the device.

Implementing Wasm in our web project is a sequence of simple tasks:

  • Write source code in your preferred high-level language (C, C++, Rust)
  • Compile it into WebAssembly (will output a .wasm file)
  • Include this .wasm in your web project
  • Write Async JavaScript code in your web project to compile & execute the .wasm

Wasm is a revolutionary technology. It’s community keeps improving and adding new features at alarming speeds. Wasm is not the only technology of such nature; but it is the one backed by W3C and major company like Microsoft, Google, Apple, etc. Only time will tell what is in store for the future.

Sonal Naik

The post WebAssembly appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
https://opspl.com/blog/webassembly/feed/ 0
What Does it Mean to be a Good Programmer? https://opspl.com/blog/be-a-good-programmer/ https://opspl.com/blog/be-a-good-programmer/#respond Fri, 31 Aug 2018 11:30:33 +0000 https://opspl.com/?p=7319 By the term programmer, a lot of things come to our mind, like smart, intelligent and the most important of all, logical. But, these are not the only skills needed to be a good programmer. Below are the basic skills needed to be a good programmer : Willingness to learn A good programmer should be...

The post What Does it Mean to be a Good Programmer? appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
By the term programmer, a lot of things come to our mind, like smart, intelligent and the most important of all, logical. But, these are not the only skills needed to be a good programmer.

Below are the basic skills needed to be a good programmer :

  • Willingness to learn
    A good programmer should be ready to learn anything thrown at them. They shouldn’t limit themselves to just one technology, but should have some basic knowledge about other technologies. Because the technology is always advancing, the skills of a programmer should also be continuously updated
  • Impressive technical skills
    This is the most obvious of all, a person working on one language should not only know how to do it but, also know how it actually works. If you know the functioning of the language, then you can solve any problem that you encounter later on.
  • Debugging skills
    Creating a code from start is completely different from investigating someone’s completed code. Getting to understand such code and researching the possible issues that may or may not come in the future is a very important skill to have.
  • Problem-solving skills
    A programmer should always find different ways to solve a problem. Avoid saying “It cannot be done” since this kind of attitude stops you from moving forward and getting innovative ideas.
  • Passion for the work
    You should love what you do. If you love coding, then there is nothing that you can’t do. Coding is fun when you enjoy it. The challenges, the unexpected errors, and deadlines – all this means nothing if you love your work. You can overcome any challenges or obstacles to get to the end.
  • People skills
    It’s very important to work with your co-workers since the development of the project is done by a team. The ability to work well with others is a must since it helps you to convey your ideas properly. At the same time, you should listen to the ideas of the others. Good co-ordination helps to get the work done faster and efficiently.

 

Stevan Fernandes

The post What Does it Mean to be a Good Programmer? appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
https://opspl.com/blog/be-a-good-programmer/feed/ 0
Earn Money through Bug Bounty https://opspl.com/blog/earn-money-through-bug-bounty/ https://opspl.com/blog/earn-money-through-bug-bounty/#respond Fri, 10 Aug 2018 11:37:50 +0000 https://opspl.com/?p=7265 It is said that hacking is an art, and the hacker is an artist. If you are that hacker looking for fame and some cash, then bug bounty is the correct choice for you. In this blog, I will give you some more information on bug bounty. To start with, let us understand the term...

The post Earn Money through Bug Bounty appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
It is said that hacking is an art, and the hacker is an artist. If you are that hacker looking for fame and some cash, then bug bounty is the correct choice for you. In this blog, I will give you some more information on bug bounty.

To start with, let us understand the term ‘bug bounty’. A Bug bounty program is nothing but a deal offered by companies to find vulnerabilities in their software, websites, or other web applications. It is also called as Vulnerability Rewards Program (VRP). The individuals who report bugs get recognition and compensation, especially if the bugs reported are more likely to exploit the vulnerabilities of their software. The individuals who report such bugs are known as bug bounty hunters and the process of finding such bugs is called bug bounty hunting.

The advantages for companies that run a Bug Bounty Program are very clear: their main aim is to get all the flaws/vulnerabilities (like CSRF, XSS, Subdomain etc) get discovered and resolved before the application is released to the public. This improves their services and helps to carry out security updates to their application/platform, hence ensuring that their data is safe.

For the bug hunters, it’s the money and hall of fame for their work. This is a very good opportunity for developers or white-hat hackers to make some money, as they are the ones who have the required computer knowledge and they can make or break the site.

If you plan to become a bug bounty hunter, you’ll need to know some basic coding and computer skills. Fortunately, there are many resources to help you get started, and coding is pretty easy to teach yourself. Also, you can use some tools available online to break things or write up a vulnerability report to the company which has issued the bounty, then get paid. Some hackers make lots of money in a year just hunting bugs. It is just a matter of skill and luck.

To keep yourself updated about this, join the bug bounty community (https://hackerone.com/leaderboard/all-time).

You can also join the Bug Bounty World on slack and keep reading their blogs, tools, testing ideas etc. (https://bugbountyworld.com/)

Learn scripting languages, which will help in automation, like JS, PYTHON, RUBY etc. This will for sure improve your skills.

Companies will often have a link or a page somewhere on their website offering bug bounties.  Typically, the payment amount depends on how much the bug will impact the users and the difficulty in the hacking. They have their rewards set for the types of bugs. The most critical bug gets the highest amount and then after that, it’s just the priority of the bugs. The final decision is made by the company and their security researchers. The bug report document must have sufficient information for the organization offering the bounty to be able to understand and reproduce the vulnerability.

A large number of organizations, including giants like Mozilla, Facebook, Yahoo!, Google etc. have implemented bug bounty programs.

Here are some links where you can always try to get some fame and money 🙂

https://bughunter.withgoogle.com/

https://www.facebook.com/whitehat

https://www.tripwire.com/state-of-security/security-data-protection/cyber-security/10-essential-bug-bounty-programs-2017/

https://www.guru99.com/bug-bounty-programs.html

Happy Hunting!!

Sabina Colaco

The post Earn Money through Bug Bounty appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
https://opspl.com/blog/earn-money-through-bug-bounty/feed/ 0
Crawling And Scraping With Python https://opspl.com/blog/crawling-scraping-python/ https://opspl.com/blog/crawling-scraping-python/#respond Fri, 29 Jun 2018 12:01:21 +0000 https://opspl.com/?p=7071 Whenever you have something important that intrigues you, Google is the first place you will go to. And voila, it will show you everything related to what you are searching. Have you ever wondered how Google provides all the search results matching what you are searching for? This algorithm is fully dependent on the concept...

The post Crawling And Scraping With Python appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
Whenever you have something important that intrigues you, Google is the first place you will go to. And voila, it will show you everything related to what you are searching.

Have you ever wondered how Google provides all the search results matching what you are searching for?
This algorithm is fully dependent on the concept of Crawling and Scraping the web and you will be able to develop your very own crawler and scraper.

What do you mean by Crawling the web?
Crawling is fetching of information from web pages that match the search query provided by the user of the search engine. The collection of web pages is handled by special software bots called crawlers or spiders.

And what about Scraping?
Using the list of webpages that the spider collected, we extract large amounts of data from these pages and store them in a local file or database.

Now let’s get started with developing your very first crawler and scraper.

Requirements:

– Python 3.x (link: https://www.python.org/downloads/) and that’s it, no other software except for a working internet connection.The reason why I am using Python is, this language is easy to learn; even people with no knowledge of programming can dive right into this language. Well this is from my perspective and I have not been paid to advertise on it. For me personally, I love to code in Python, with it’s vast amount of libraries which can even help with machine learning apart from many other things.

Once you have Python properly installed, all you need is a few libraries and you are good to go. (Make sure that ‘python’ and ‘pip’ is added to you system path variables)

To install these libraries, you will have to and type in at the command prompt:
– pip install mechanicalsoup

This will install all the required libraries needed to build your crawler and scraper.
Now at the command prompt, type in python and hit enter.
This opens the python interpreter, which looks something like this:

 

Python Interpreter

 

Next, to import the library required for this project, type in

import mechanicalsoup

Note: The libraries are case sensitive so make sure you type it exactly as above.

Let’s create a browser object, we will call this our spider (as it will crawl the web and fetch the webpages):

browser = mechanicalsoup.StatefulBrowser()

Now, we open a webpage. In this guide we will be using the search engine http://duckduckgo.com, as it is simpler to understand how the pages are crawled and scraped.

browser.open(“http://duckduckgo.com”)

 

Python Browser

 

The return value of the method open() is an object of type requests.Response. The output is a HTTP response status, 200, which means “OK”, and the object also contains the contents of the downloaded page which resides within the browser object.
To see the content that exists in the browser object, type in this snippet:
browser.get_current_page()

For the next step, we have to know the attribute that exist for the form tag in the search engine. In our case, we are using the ‘id’ attribute which has the value “#search_form_homepage”. This can be known by using the browser’s Developer tools as shown below:

 

Developer Tools

 

To select this form, type in:

browser.select_form(‘#search_form_homepage’)

To print the summary of the currently selected form, type in:

browser.get_current_form().print_summary()

 

Summary Of Selected Form

 

As you can see, there are 3 input tags. From these tags, we will fill the text field which has id “#search_form_input_homepage” with a search query and then submit the selected form.

 

Add Form

 

On submitting, you will get status code 200 which states that the request was successful.

Now we need to populate or so to say ‘scrape’ the page for the search results. For now, we only display the results with the title and the link to that search result

Here is the code snippet to display the same:

for link in browser.get_current_page().select(‘a.result__a’):

print(link.text, ‘\n\t’, link.attrs[‘href’])

 

Search Results

 

And here comes to an end my guide to creating your own crawler and scraper. You can experiment and explore the documentation of mechanicalsoup (https://mechanicalsoup.readthedocs.io) and beautifulsoup (https://www.crummy.com/software/BeautifulSoup/bs4/doc/) to go even more in-depth into crawling and scraping the web.

 

Shyan De Abreu

The post Crawling And Scraping With Python appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
https://opspl.com/blog/crawling-scraping-python/feed/ 0
Guidelines for writing Selenium automation https://opspl.com/blog/guidelines-writing-selenium-automation/ https://opspl.com/blog/guidelines-writing-selenium-automation/#respond Fri, 23 Feb 2018 12:28:40 +0000 https://opspl.com/?p=6702 Automated testing is the best way to increase the effectiveness, efficiency, and coverage of your web application. Automation can be helpful not only to debug the code but also to find the root cause of the defect by identifying the code section that is error-prone. This can be carried out through tests with Selenium WebDriver...

The post Guidelines for writing Selenium automation appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
Automated testing is the best way to increase the effectiveness, efficiency, and coverage of your web application. Automation can be helpful not only to debug the code but also to find the root cause of the defect by identifying the code section that is error-prone. This can be carried out through tests with Selenium WebDriver for web applications and Appium for native and mobile web applications.

Selenium is a testing framework to perform web application testing across various platforms like Windows, Mac, and Linux. Selenium supports only web-based applications that need a browser open. To execute the script on different browsers, we need the driver of that browser.

It supports various programming languages such as Java, PHP, C#, Python, Groovy, Ruby, and Perl for writing the test automation scripts. It offers recording and playback action features to write tests.

Below are the basic requirements for running a Selenium Java script.

Importing Packages

Two important packages that a tester needs to import when starting to code a script are:

  • openqa.selenium.*- This package includes the WebDriver class needed to instantiate a new browser loaded with a specific driver.
  • openqa.selenium.firefox.FirefoxDriver – FirefoxDriver class instantiates a Firefox-specific driver.

As the project would grow, it is evident and logical that we may need to introduce several other packages for more complex and distinct functionalities like database connectivity, manipulating external files, logging, assertions, accessing another class, taking browser screenshots etc.

Instantiating objects and variables

For Selenium automation, the very first line of code comes as:

WebDriver driver = new FirefoxDriver();

To initiate a driver, we create a reference variable for the WebDriver interface and instantiate it using FirefoxDriver class. It means that we are defining a reference variable (driver) whose type is an interface. Any object we assign to it must be an instance of class FireFoxDriver or any other drivers that implement that interface.

A default Firefox profile will be launched which means that no extensions and plugins would be loaded with the Firefox instance and that it runs in the safe mode.

Selenium WebDriver makes direct calls to the browser using each browser’s native support. How these direct calls are made, and the features they support depends on the browser you are using. Selenium standalone server uses this driver to start the browser of your choice. Normally to run webdriver, we just need a browser and a selenium server jar file. Selenium supports to run webdriver on the browsers by adding a .exe path of the driver server for the individual browsers.

Here are the code snippets for Firefox, Chrome and IE:

Firefox

System.setProperty(“webdriver.firefox.bin”,”F:\\Program Files(x86)\\Firefox\\Firefox.exe”);

WebDriver driver = new FirefoxDriver();

driver.navigate().to(“https://www.google.com”);

Chrome

System.setProperty(“webdriver.chrome.driver”,”G:\\Lib\\chromedriver.exe”);

WebDriver driver = new ChromeDriver();

driver.navigate().to(“https://www.google.com”);

Internet Explorer

System.setProperty(“webdriver.ie.driver”,”G:\\Lib\\internetexplorerdriver.exe”);

WebDriver driver = new InternetExplorerDriver();

driver.navigate().to(“https://www.google.com”);

Launching the Web browser

driver.get (baseURL);

To launch a fresh web browser instance the get() method is called on the WebDriver instance. The string character sequence passed as a parameter into the get() method redirects the launched web browser instance to the URL that you specify as its parameter.

Comparison between Expected and Actual Values:

Comparison code simply uses a basic if-else structure to compare the actual condition with the expected one.

if (actualCondition.contentEquals (expectedCondition)) {

System.out.printIn(“Success”);

} else {

System.out.printIn(“Fail”);

}

Terminating a Browser Session:

The “close()” method is used to close the browser window.

driver.close();

The scripts can be saved and re-run at any time. Hope this blog helps you in writing your first of many selenium test scripts.

Muriel Fernandes

Muriel Fernandes

The post Guidelines for writing Selenium automation appeared first on Online Productivity Solutions Pvt. Ltd..

]]>
https://opspl.com/blog/guidelines-writing-selenium-automation/feed/ 0