Categories
Programming

Redirect from one host to another using Apache htaccess

Redirect from one host to another using Apache htaccess

Categories
Programming

Speed up Selenium web-driver tests by disabling images and CSS

Using Selenium Webdriver, we can manipulate and use a web browser programmatically. This is widely used in website testing as once a programmed script is written to run on a website, we can sit back and relax while the script is testing the desired outcomes of the website. Also there are many other use cases.

Now the thing about the driver is that it uses a real web browser to run the scripts. So once a web page is accessed, the browser will perform its normal functionality loading everything in the web page. This can slow down the script. However for your use case you might not need to wait till images are rendered or CSS files being loaded etc.

So I wanted to disable the images, CSS for my use case when I’m running the script on Firefox. So if you are ok with not having load the images, CSS and disable other stuff, you can manipulate Firefox profiler in the test window to achieve that. I think other browser can do similar like this to archive the same thing.  The code segment below works for Firefox.

That’s it. Now images, CSS and other stuff will not be loaded.

Conclusion

If disabling images, and other stuff break your website you will not get any value from this approach however for certain cases this might come handy. And it’s a great option to have if you want to speed up the execution of the scripts.

Categories
Programming

PDF version of Guide to MongoDB Indexes

You can download the PDF version for MongoDB indexes on their official site at:
http://docs.mongodb.org/master/MongoDB-indexes-guide.pdf

Categories
Programming

Fixing No Input File Specified error on Nginx + PHP

Today I wanted to try out Nginx server my windows machine. After setting up the basic server block details for my project, I called the site URL. In the WT-NMP stack to quickly setup the software I needed. In the server block, I needed to specify my root path in a different location other than WWW.

Then when I hit the URL, I was getting “No Input File Specified” for my PHP script.

Now I’m not much of a reader so I just goggled here and there and didn’t found much of a fix. So then I reviewed the php log files. There I got the error message as my project folder path is not within the allowed path(s): (c:/wt-nmp)

So basically I had to edit php.init open_basedir value to include the path I stored my project. However here I could see that even the driver is considered to be as a path. So I ended up placing the driver letter since if I want to store more websites in my ‘d’ drive, I would not encounter this error.  This is the final line. I have bold my text to indicate the change I made.

open_basedir = “c:/wt-nmp.;d:/

“Happy Nginx, is a good Nginx.”

Categories
Programming

Setting up xdebug with phpstorm

This guide provide a step by step details on how to set up phpstorm IDE to work with xdebug.

 

Installing on Ubuntu

In software search for xdebug and install.

 

Add to the following xdebug settings to php.ini file

 

 

 

 

Installing on Windows XAMPP

First download xdebug and copy it into the extension folder. Copy the full path the extension.

 

Add the following xdebug settings to php.ini file.

php.ini file

 

 

 

 

Install easiest xdebug for Firefox and specify the remote IDE key for Firefox

easiest_xdebug_ff

 

Then in the xdebug configuration apply following

phpstorm_xdebug

 

 

Put debug points and run the remote debug setting.

xdebug_option

 

 

enable the easiest debug and navigate the test page through the browser. Your debug point should be hit, the request url is reading the debug file.

 

Notes:

To stop breaking at the first line Untick Run->break and first line…

 

Categories
Programming

Xpath vs CSS Selectors

After researching and reviewing on whether to choose XPATH or CSS selector, the following are the points I came across.

 

Some points to CSS

Generally CSS is easy to use and readable over XPATH.

REF: http://www.seleniumhq.org/docs/appendix_locating_techniques.jsp#starting-to-use-css-instead-of-xpath

 

CSS is native to browsers and XPATH is not

REF: http://old.eurostarconferences.com/blog/2013/1/28/liveblogged!-automated-web-testing-traps-for-the-unwary-with-simon-stewart

CSS is preferred for testing as it is having more advantages over XPATH

REF: http://seleniumeasy.com/selenium-tutorials/css-selectors-tutorial-for-selenium-with-examples

 

Some points to XPATH

XPATH can travese up the document from a child element to parents.

REF: http://www.rapidprogramming.com/questions-answers/difference-between-css-and-xpath-css-vs-xpath-1388

 

Speed wise CSS and XPATH can be equal, or either one would be a bit speedier than other.

Therefore speed comparison can be ignored. However off the record, I have encountered that most mention that CSS is much faster than XPATH.

REF: http://elementalselenium.com/tips/33-xpath-vs-css-revisited

 

Conclusion

If we are down to select either CSS or XPATH reference, as I see we should compare the generated CSS and XPATH and select the better readable and short path locating string. Others comments are highly appropriated.

 

Additional Notes

Converting XPATH to CSS seletors: Following article layout on how to change XPATH element reference to CSS.

https://saucelabs.com/resources/selenium/css-selectors

 

Differences between CSS and XPATH

Ref: http://www.rapidprogramming.com/questions-answers/difference-between-css-and-xpath-css-vs-xpath-1388

 

A general guideline on how to select elements in a preferred order (where ID is the king)

https://blog.mozilla.org/webqa/2013/09/26/writing-reliable-locators-for-selenium-and-webdriver-tests/

https://thenewcircle.com/static/bookshelf/selenium_tutorial/locators.html

A video presentation on how why CSS is preferred on many occations and comprehensive presentation on CSS vs XPATH for Selenium.

https://www.youtube.com/watch?v=6vPu3TO6XZ4

 

Categories
Programming

NUC machines might be the next desktop killer

While it seems like to CPU processing power is coming to a limitation, Intel is focusing on small form factor machines.

Categories
Programming

Installing Unlimited Strength Jurisdiction Policy Files for your JRE

Today in work, I had to use AES encryption to basically encrypt and secret text and store it somewhere. This is with Ruby language so I ended up using ‘aes’ gem as it is build on top of OpenSSL and provides simple set of methods that can be used to encrypt and decrypt strings.

Following is the Git repository location which also has some guidelines on using the gem.

https://github.com/chicks/aes

Client wanted to use something similar to AES and we researched a bit and found it is easy to use for the situation. Basically in AES the key that is used for to encrypt is used to decrypt and get the original text.

secret-key

However during execution when encryption and decryption methods are called, the following Java encryption key size limitation policy issue was occurred:

 

As it turns out that the Cipher class will generally not allow encryption with a key size of more than 128 bits. The apparent reason behind this is that some countries (although increasingly fewer) have restrictions on the permitted key strength of imported encryption software.

Ref: http://www.javamex.com/tutorials/cryptography/unrestricted_policy_files.shtml

 

Basically this is a forced restriction set by Java and can easily be fixed and there are two different solutions for this issue as mentioned in https://github.com/jruby/jruby/wiki/UnlimitedStrengthCrypto.

 

Method 1 – Install the “Unlimited Strength” policy files from Oracle

In this approach it is required to install unlimited strength cryptography in the JVM, corresponding to Jenkins machine running java version:

http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html

http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

After downloading the relevant zip file, the JAR files located in that should be replaced with the same JAR files found in “<java-home>/lib/security” . A detailed installation instruction should be also included in the zip file.

 

Method 2 – Disable the crypto restriction programmatically

There’s also a gem called ‘unlimited-strength-crypto’ that programmatically disables this limitation.

Ref: https://rubygems.org/gems/unlimited-strength-crypto

However as specified in the document (https://github.com/jruby/jruby/wiki/UnlimitedStrengthCrypto), this approach may apply to Java 7+ only.

 

As I see method 2 appears to be better as the situation is handled by a gem and easy to use. However as mentioned above, it is necessary to update the Java 7 or upper version. 

Categories
Programming

Setting up xdebug with phpstorm

This guide provide a step by step details on how to set up phpstorm IDE to work with xdebug.

 

First download xdebug and copy it into the extension folder. Copy the full path the extension.

 

Add the following xdebug settings to php.ini file.

 

php.ini file

[XDebug]
zend_extension = “C:xamppphpextphp_xdebug-2.2.5-5.5-vc11.dll”
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_log=”c:tmpxdebugxdebug.log”
xdebug.show_exception_trace=0
xdebug.show_local_vars=9
xdebug.show_mem_delta=0
xdebug.trace_format=0
xdebug.profiler_enable = 1
xdebug.profiler_output_dir =”c:tmpxdebug”

 

 

Install easiest xdebug for Firefox and specify the remote IDE key for Firefox

Untitled picture

Then in the xdebug configuration apply following

Untitled picture

Put debug points and run the remote debug setting.

Untitled picture

 

enable the easiest debug and navigate the test page through the browser. Your debug should be hit, the request url is reading the debug file.

 

Notes:

To stop breaking at the first line Untick Run->break and first line…