TESTEVERYTHING

Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Thursday, 5 March 2015

Scrolling web page with Webdriver using java

We can scroll the web page using javaScript Executor or You can use the "org.openqa.selenium.interactions.Actions" class to move to an element:


Following classes you required in you java code
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement;
import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor;

1. We may require to scroll to bottom of the page and then perform operations. For this scenario we can use following code
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");

2. Some times, we may require to scroll to particular element and peform operations on that particular element. For this we need to pass the element on which we need to perform operation. For this scenario we ca use following code
WebElement element = driver.findElement(By.linkText("googleMap")); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);
OR
WebElement element = driver.findElement(By.id("my-id"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();

3. We can also use the coordinates to scroll to particular position by passing the coordinates. For this scenario we use following code
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");

Monday, 22 September 2014

MOBILE WEB/APPLICATION AUTOMATION INSTALLATION GUIDE FOR IOS

1      Software Requirement

1.       Xcode 5.0 + (Mandatory for iOS 7)
2.       rvm
3.       Ruby 2.0.0
4.       Homebrew
5.       Java
6.       Maven
7.       Ant
8.       Cocoapods
Note: In mac machine, you must have admin rights.

1.1            Install Xcode

Download the latest Xcode from apple developer site

1.2            Install RVM

                           1. Open the terminal window on mac

                          $ \curl -sSL https://get.rvm.io | bash -s stable
                         
                           refer the below url for more info
                                http://rvm.io/rvm/install

1.3            Install RUBY

1.   Ruby is installed by default on Mac, just make sure it is using the version 2.0.0, ruby version can be checked using command;
                                          $ ruby -v
2.   To install ruby version 1.9.2 type below command in terminal
                                          $ rvm install 1.9.2

3.   Once the installation has completed, we need to tell RVM which version of Ruby we currently want to use:
       $ rvm use 1.9.2


                         4.    Make 1.9.2 the Default If you restart Terminal, and type ruby -v again, you'll likely find that it has defaulted back to the system version of Ruby: 1.8.7. That's no good! Let's be sure to make 1.9.2 the default.

rvm --default use 1.9.2

1.4            Install HomeBrew

1.        Homebrew, “the missing package manager for OS X,” allows you to easily install hundreds of open-source tools. The full instructions are available on the Homebrew Wiki, but you should only need to run the command that’s listed at the bottom of the Homebrew site:




                              2.       Once the installation is successful, run the following command:

$ brew doctor

1.5            Install Java, Maven & Ant

1.    Download java .dmg file from http://www.java.com/en/download/
2.    Double click .dmg file and install java
3.    Now download maven from http://www.interior-dsgn.com/apache/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz
4.    Extract maven to any directory
5.    Now to set the environment variables, in the terminal type
$ nano ~/.bash_profile
For Java enter;
      export JAVA_HOME= <path to your java directory >
For Maven enter;
      export M2_HOME= <path to your extracted maven directory>
      export M2=$M2_HOME/bin



Once done press ctrl+O and press enter, now press ctrl+x
6.    In the same terminal enter command
$ source ~/.bash_profile
7.    To install Ant use command
 $ brew install ant
8.    To verify the Maven installation, in terminal, issue the command mvn -version.

$ mvn -version

Apache Maven 3.0.3 (r1075438; 2011-03-01 01:31:09+0800)
Maven home: /usr/share/maven
Java version: 1.6.0_33, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.4", arch: "x86_64", family: "mac"
9.    To verify java installation, in terminal, issue the command mvn -version.


$ java -version

Monday, 20 May 2013

Create issue in JIRA using Http Client via REST API services/ from JAVA



JIRA is a well known Software-suite. In short, JIRA is a proprietary issue tracking product, maintained and developed by Atlassian. It is commonly used for bug tracking, issue tracking, and project management



The JIRA Remote API Calls


I was surprised how easy it was to get the Remote API up and running. Basically you just enable the ‘Accept remote API calls’ option in your General Configuration settings under the Administration tab. The moment you turn it on, the following URL should give you a nice response


Note: It supports only in JIRA >5.0.

Here in am using http client 4.1.2

Here is  the code:

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;

public class CreateIssue {

 public static void main(String[] args) throws Exception {
  CreateIssue.CreateIssueJira();
 }
public static void CreateIssueJira() throws ClientProtocolException,
   IOException {
  String host = "https://rajivkumarnandvani.atlassian.net/";
  // int port = 8080;
  String userName = "EnterUserName";
  String password = "EnterPassword";
  String ResponseData;
  DefaultHttpClient httpClient = new DefaultHttpClient();
  String jsonObj = "{"
    + "\"fields\": {"
    + "\"project\":"
    + "{"
    + "\"key\": \"DEMO\""
    + "},"
    + "\"summary\": \"REST ye merry gentlemen.\","
    + "\"description\": \"Creating of an issue using project keys and issue type names using the REST API\","
    + "\"issuetype\": {" + "\"name\": \"Bug\"" + "}" + "}" + "}";

  HttpHost targetHost = new HttpHost("rajivkumarnandvani.atlassian.net",
    -1, "https");

  httpClient.getCredentialsProvider().setCredentials(
    new AuthScope(targetHost.getHostName(), targetHost.getPort(),
      targetHost.getSchemeName()),
    new UsernamePasswordCredentials(userName, password));

  HttpPost httpPost = new HttpPost(
    "https://rajivkumarnandvani.atlassian.net/rest/api/2/issue/");
  StringEntity entity = new StringEntity(jsonObj);
  entity.setContentType("application/json");
  httpPost.setEntity(entity);

  // Create AuthCache instance
  AuthCache authCache = new BasicAuthCache();
  // Generate BASIC scheme object and add it to the local auth cache
  BasicScheme basicAuth = new BasicScheme();

  authCache.put(targetHost, basicAuth);

  // Add AuthCache to the execution context
  BasicHttpContext localcontext = new BasicHttpContext();
  localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

  try {

   HttpResponse httpResponse = httpClient.execute(httpPost,
     localcontext);
   HttpEntity entitydata = httpResponse.getEntity();
   ResponseData = new String(EntityUtils.toByteArray(entitydata));
   System.out.println(ResponseData);
  } catch (ClientProtocolException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
  httpClient.getConnectionManager().shutdown();
 }
}




Which one is right ?

Translate







Tweet