Friday, August 17, 2018

getElements method in nightwatch js


Nightwatch js does not have getElements methods to locate multiple elements but it has provided with WebDriver methods specified in the WebDriver Specification. These methods can be used to create your own getElements method. Below is one such implementation

To achieve this, we have to set selector strategy which can be done by examining locator string. Below is my implementation

    /**
     * It will return the slector strategy for the given selector string
     */
    getSelectorStrategy: function (locator) {
        if (locator.startsWith("//")) {
            return "xpath";
        } else {
            return "css selector";
        }
    } 

Using above method, elements method can be implemented as below
const {client} = require('nightwatch-cucumber');

 /**
   * This will retrun array of elements for the given selectors
   */
   getElements: function (locator, callback) {
       var selectorStrategy = this.getSelectorStrategy(locator);
       return client.elements(selectorStrategy, locator, function (result) {
           callback(result.value)
       });
    }

Tuesday, July 24, 2018

Simple HTTP server on Node JS

Ever needed an HTTP server just to test out something. If you are working on Node platform then you can do so very easily by following the mentioned steps.


1. Simply paste below mentioned code in a file server.js
var connect = require('connect');
var serveStatic = require('serve-static');
connect().use(serveStatic(__dirname)).listen(8080, function(){
    console.log('Server running on 8080...');
}); 

2. Run this server.js via command prompt
node server.js

3. This will start a HTTP server on port 8080 and pickup the content from current directory

 This is quite useful when you want to see some static content using a server

Thursday, June 28, 2018

JSE Coin - Web minable coin

JSE Coin is the latest entrant in the cryptocurrency market and it has focus on  only one thing - to make web based payments simple and easy.

Can this be mined - yes it can be, but it not actually work in the way traditional mining works. The miner will solve a mathematical problem which will give you a ticket to lottery. Each lottery will give you chabce to win some JSE coins. So in a way you are mining the coin but in reality you are not.

I am still not sure how this mining will work when they will run out of the coins to distribute as it only seems like a marketing scheme.

One thing which is great about this coin is  that it is minable using web browsers like monero on coinhive. However tbe scripts that are doing moning does not got blocked by most of the major firewall and antivirus programs. So, you can monetize your web traffic using this coin.

For now it seems promising but can really say how it will perform in future. As still going through ICO process.

In case you are interested, you can avail a free account using below link. Once you have signed up, you can start mining using their web miner program.

Link to sign up - https://platform.jsecoin.com/?lander=3&utm_source=referral&utm_campaign=aff62467&utm_content=

Sunday, May 27, 2018

Electroneum (ETN) referral code - 24D744

While most of you were mining Electroneum (ETN) on mobile app, you can boost up your earnings by using referral code. You can not use your code (obviously) or you need another account from which you can use referral code. Either ways, your first account will be left without referral code.

You can use below referral code for your first account. It should give your mining account a little boost.

Referral code is - 24D744

Alternatively, you can scan the QR code from below image.

Friday, April 20, 2018

Sending pfx or p12 certificate using javascript


Recently I was stuck with a task where I needed to send .p12 file along with the request and since this certificate is different from the regular one, it will have to be sent in a different way.

The testing framework was in Javascript and we used chakram as the module to send the request which is using requests module underneath. It took some time to find out a working solution which I am sharing here. Hope this will help you.

Code
 var fs = require('fs');  
 var options = {  
   headers: { 'authrization':'' },  
   agentOptions: {  
     pfx: fs.readFileSync('certfile.p12'),  
     passphrase: 'passphrase',  
     securityOptions: 'SSL_OP_NO_SSLv3'  
   }  
 };