Sunday, 30 August 2015

DesiredCapability For Cloud Environment SauceLabs Vs BrowserStack

Additional Keys Are Supported For Setting Desired Capabilities W.R.T execution on cloud environment:

1. Account Name: username=<AccountName>
2. AccessKey : accessKey=<AccessKey>

Example:
/*Below snippet does belong to C# conventions*/
private void setRemoteWebDriverForCloudSauceLabs()
        {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability(CapabilityType.BrowserName, this.browser);
            desiredCapabilities.SetCapability(CapabilityType.Version, this.version);
            desiredCapabilities.SetCapability(CapabilityType.Platform, this.platform);
            desiredCapabilities.SetCapability("username", this.userName);
            desiredCapabilities.SetCapability("accessKey", this.accessKey);
            desiredCapabilities.SetCapability("name", this.executedFrom + " - " + this.jobName + " - " + this.buildNumber + " - " + TestContext.CurrentContext.Test.Name);
            Uri commandExecutorUri = new Uri("http://ondemand.saucelabs.com/wd/hub");
            this.driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilities);
        }

The same url for saucelabs connection can also contain username and accesskey. For example:
Uri commandExecutorUri = new Uri("http://<username>:<accessKey>@ondemand.saucelabs.com:80/wd/hub");

/*For BrowserStack*/

private void setRemoteWebDriverForCloudBrowserstack()
        {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability("browser", this.browser);
            desiredCapabilities.SetCapability("browser_version", this.browser_version);
            desiredCapabilities.SetCapability("os", this.os);
            desiredCapabilities.SetCapability("os_version", this.os_version);
            desiredCapabilities.SetCapability("browserstack.user", this.browserstack_user);
            desiredCapabilities.SetCapability("browserstack.key", this.browserstack_key);
            Uri commandExecutorUri = new Uri("http://hub.browserstack.com/wd/hub/");
            this.driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilities);
        }

How to get list of desiredcapabilities:
SauceLabs: Set Environment Using Utility Given At PlatformConfigurator
1. PlatformConfigurator: https://docs.saucelabs.com/reference/platforms-configurator

 

Thursday, 23 April 2015

Unit testing best practices

Unit testing is not about finding bugs
Tips for writing great unit tests
Test only one code unit at a time
Don’t make unnecessary assertions
Make each test independent to all the others
Mock out all external services and state
Don’t unit-test configuration settings
Name your unit tests clearly and consistently
Write tests for methods that have the fewest dependencies first, and work your way up
All methods, regardless of visibility, should have appropriate unit tests
Aim for each unit test method to perform exactly one assertion
Create unit tests that target exceptions
Use the most appropriate assertion methods.
Put assertion parameters in the proper order
Ensure that test code is separated from production code
Do not print anything out in unit tests
Do not use static members in a test class
Do not write your own catch blocks that exist only to fail a test
Do not rely on indirect testing
Integrate Testcases with build script
Do not skip unit tests
Capture results using the XML formatter
Details: http://howtodoinjava.com/2012/11/05/unit-testing-best-practices-junit-reference-guide/

Saturday, 13 December 2014

How to upload a file using selenium webdriver

Scenario:

Using selenium webdriver, one can simulate fileupload easily using sendKeys.

Using firebug, I could see, the button which pops up operating system specific dialog box where file loaction is typed-in has got type=file.

The below is snippet from naukri site, which has got button to upload file.

<input type="file" name="attachCV" id="attachCV" valtype="attachCV" class="">

In case, input type="file", we can pass absolute location of file to be uploaded using sendKeys method exposed by WebElement class.

Ex:
WebDriver wd = new FirefoxDriver();
WebElement we = wd.findElement(By.id = "attachCV");
we.sendKeys(<Absolute FileLocation>);

Internationalization Testing Using WebDriver

Internationalization Testing Using WebDriver
One need to open browser in localized mode, in specific language.

there could be 2 approaches:
i. create profile and load it during launching browser.
    --ProfileIni pf = new ProfileIni();
    --FirefoxProfile fireFoxProfile = pf.getProfile(<profileName>);//<profileName is created using profile manager, "type firefox.exe -p on Windows+R "
 
    --WebDriver wd = new FireFoxDriver(fireFoxProfile);
ii. Create object of FirefoxProfile. Set the preference of FirefoxProfile to open in particular langauage.
--FireFoxProfile fireFoxProfile = new FireFoxProfile();
--fireFoxProfile.setPreference("intl.accept_languages","sl");
--WebDriver wd = new FireFoxDriver(fireFoxProfile);

package learn.I18n;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
/*
Internationalization Testing Using WebDriver
One need to open browser in localized mode, in specific language.

there could be 2 approaches:
i. create profile and load it during launching browser.
    --ProfileIni pf = new ProfileIni();
    --FirefoxProfile fireFoxProfile = pf.getProfile(<profileName>);//<profileName is created using profile manager, "type firefox.exe -p on Windows+R "
 
    --WebDriver wd = new FireFoxDriver(fireFoxProfile);
ii. Create object of FirefoxProfile. Set the preference of FirefoxProfile to open in particular langauage.
--FireFoxProfile fireFoxProfile = new FireFoxProfile();
--fireFoxProfile.setPreference("intl.accept_languages","sl");
--WebDriver wd = new FireFoxDriver(fireFoxProfile);



Profile setting can be done using ProfileIni Class in WebDriver
*/
public class Localization implements Constants
{

WebDriver wd = null;

@BeforeTest(enabled = true)
public void setup()
{
/*
ProfilesIni pf = new ProfilesIni();
FirefoxProfile fireFoxProfile = pf.getProfile(profileName);
wd = new FirefoxDriver(fireFoxProfile);
*/
FirefoxProfile fireFoxProfile = new FirefoxProfile();
fireFoxProfile.setPreference("intl.accept_languages","sl");
wd = new FirefoxDriver(fireFoxProfile);
}

@Test
public void testLoadApplication()
{
wd.get("http://www.gmail.com");

}


}

Sunday, 7 December 2014

Good site For Agile Software Development



http://scrummethodology.com/
http://www.agilebuddha.com/agile/how-to-do-effective-capacity-planning-on-the-scrum-team/

Saturday, 6 December 2014

Sprint Cycle


Traversing Linked List In Reverse Order

Traversing Linked List In Reverse Order:

package linkedList;

import java.util.List;

public interface LinkedListInterface<T>
{
void add(T t);
List<T> readNodeValues();
List<T> readNodeValuesInReverseOrder();
}


/********************************************/

package linkedList;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractLinkedListImpl<T> implements LinkedListInterface<T>
{
protected Node start = null;
static class Node
{
private Node next = null;
private Object value;

}

@Override
public void add(T t) {
Node n = new Node();
n.value = t;
if(this.start == null)
{
this.start = n;
}
else
{
//create temp node to point to start
Node temp = this.start;
//traverse to end of linked list whre next = null
while(temp.next !=  null)
{
temp = temp.next;
}
temp.next = n;
}
}

@Override
public List<T> readNodeValues() {
List<T> list = null;
while(this.start!=null)
{
list = new ArrayList<T>();
list.add((T)start.value);
this.start=this.start.next;
}

return list;
}

@Override
public List<T> readNodeValuesInReverseOrder() {

List<T> list = null;
traverse(this.start);
return list;
}

private void traverse(Node start)
{

if(start == null)
{
return;
}
traverse(start.next);
System.out.println(start.value);


}

}

/********************************/
package linkedList;

public class MyLinkedList<T> extends AbstractLinkedListImpl<T>
{

public MyLinkedList()
{
this.start = null;
}

public static void main(String [] str)
{
MyLinkedList<String> linkedList = new MyLinkedList<String>();
linkedList.add(new String("Debasish"));
linkedList.add(new String ("Subhasish"));
linkedList.add(new String ("Krishna"));
linkedList.add(new String ("Kanha"));
linkedList.readNodeValuesInReverseOrder();
}
}