Wednesday 26 June 2013

what is a JSON file

JSON (JavaScript Object Notation) is an independent data exchange format. JSON  supports text and numeric values. Binary values are not supported.

 Data structures in JSON are based on key / value pairs. The key is a string, the value can be a numerical value, a boolean value (true or false) or an object.

An JSON object is a set of key / value pairs which starts with "{" and ends with "}".

Example: file name declares as chromesettings.json

{
  "capabilities":
      [
     
        {
       "platform": "WINDOWS",
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 5556,
    "host": 192.18.0.5,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": 192.18.0.5
  }
}

Lists are one or more values surrounded by [] and separated by ",".

How to identify dynamic elements or Xpaths in Selenium

Many web sites create dynamic element on their web pages where Ids of the elements gets generated dynamically. Each time id gets generated differently. So to handle this situation we use some JavaScript functions.
starts-with
if your dynamic element's ids have the format  where button id="continue-12345"  where 12345 is a dynamic number you could use the following
XPath: //button[starts-with(@id, 'continue-')]
contains
Sometimes an element gets identfied by a value that could be surrounded by other text, then contains function can be used.
To demonstrate, the element  can be located based on the ‘suggest’ class without having to couple it with the ‘top’ and ‘business’ classes using the following
XPath: //input[contains(@class, 'suggest')].

Wednesday 19 June 2013

org.openqa.selenium.NoSuchElementException: Unable to locate element:

This type of error will come whenever Xpaths changes


So going to particular xpath... try to update the latest xpath.. Consequently you can solve this problem.



org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id='header']/div[4]/div[1]/ul/li[4]/a[1]"}
Command duration or timeout: 30.09 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_21'
Session ID: 2aa03a64-ac7f-4a31-9d3f-f55f9fd3ca97
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=21.0}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:404)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:344)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:101)
    at com.sun.proxy.$Proxy10.findElement(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:180)
    at testsuites.CheckoutTest.Testsalescycle(CheckoutTest.java:96)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.rules.Verifier$1.evaluate(Verifier.java:34)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session.

 This type of error will come just in case

1) if you script unable to find xpath which  you have specified.

To trobleshoot this error .. run your script on Debug mode. So that you will come to know.. where it is failing.
2) just in case if you are driver is close before performing your operations in that case also this error will come.




org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_21'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:161)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
    at com.mns.international.framework.WebDriverLoader.initializeWebDriver(WebDriverLoader.java:61)
    at testsuites.MyFirstTest.beforetest(MyFirstTest.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.rules.Verifier$1.evaluate(Verifier.java:34)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner

Monday 17 June 2013

Proxy settings for Remote Webdriver Remotewebdriver

if (browser1.equalsIgnoreCase("firefox")) {

capability = new DesiredCapabilities().firefox();
capability.setBrowserName(browser1);
capability.setJavascriptEnabled(true);

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();

String hostname = "proxybc.youcompany.net:8080";
String username = "changeUserid";
String password = "Password1";


proxy.setProxyType(ProxyType.MANUAL);
proxy.setHttpProxy(hostname);
proxy.setSslProxy(hostname);
proxy.setFtpProxy(hostname);
proxy.setSocksUsername(username);
proxy.setSocksPassword(password);




FirefoxProfile fp = new FirefoxProfile();
fp.setProxyPreferences(proxy);
capability.setCapability(FirefoxDriver.PROFILE, fp);
driver = new RemoteWebDriver(new URL("http://"
+ ConfigReader.SELENIUM_SERVER_URL
+ ":".concat(port).concat("/wd/hub")), capability);
browser = new WebDriverBackedSelenium(driver,
ConfigReader.ENVIRONMENT_URL);

jse = (JavascriptExecutor) driver;

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 }

Saturday 15 June 2013

How to find or search file name in Eclipse or short cut to find file name in eclipse

Please use below keyboard keys to find any character or string in eclipse .


Ctrl +Shift + R

After pressing this command ... Open Source popup window will come.

Monday 10 June 2013

Java was started but returned exit code=1

For this we have to go to Command line

type

c:\> java -version
then you can find some error like
Error occurred during initialization of VM. I could not find agent library jvmhook on the library path, with error: %1 is not a valid Win32 application.

So now you have go to Control panel-> System -> Environment variables

Under "System Variable" tab you can find
JAVA_TOOL_OPTIONS

Delete that one and click on ok

Now again go to c:\> java -version

Now it will work fine.

Your eclipse problem also will resolve.






Eclipse.ini
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120522-1813
-product
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256M
-showsplash
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms512m
-Xmx1024m
-Xss1024k
-Declipse.buildId=v21.0.0-519525

Saturday 8 June 2013

How to switch IE versions in browsers

To change IE Internet Explorer versions in browser. We have to press F12 on keyboard .

And after that change your IE version from IE 8 to IE 9 ... As per your requirement.