Thursday 19 June 2014

Sample Java WebDriver usage

The following test case was discussed at Cigniti company technical interview question:
  1. 1. open flipkart.com 
  2. 2.select electronics in that click on laptops.
  3. 3.In Laptops brands select HP
  4. .4.select checkbox 30000-40000 
  5. 5. list of Laptops copy to excel sheet( without using Data table).
  6. 6.select first Laptop and buy it.
As per my understanding I've prepared Java code to automate with Selenium WebDriver


solution:------------

import java.io.FileOutputStream;
import java.io.WriteAbortedException;
import java.util.ArrayList;

import java.util.List;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import com.thoughtworks.selenium.Selenium;
public class flipkart_lappy {
 public WebDriver driver;
 public Selenium selenium;
 String str1;
 
 @Testpublic 
 void lappy() throws Exception{
  FileOutputStream fo =new FileOutputStream("E:\\Saritha\\output\\result.xls");
  WritableWorkbook wb = Workbook.createWorkbook(fo);
  WritableSheet ws = wb.createSheet("Sheet1", 0);
  driver.findElement(By.xpath(".//*[@id='fk-mainhead-id']/div[2]/div/div[1]/ul/li[1]/a/span")).click();
  Thread.sleep(1000);
  driver.findElement(By.linkText("Laptops")).click();
  Thread.sleep(1000);driver.findElement(By.linkText("HP")).click();
  Thread.sleep(1000);driver.findElement(By.xpath("//*[@id='price_range']/li[4]/a/input")).click();
  Thread.sleep(1000);//adding input from excel sheet.
  String str1= driver.findElement(By.xpath(".//*[@id='browse-results-area']/div[6]")).getText();
  System.out.println("str1");String s[] = str1.split("\n");
  System.out.println(s.length);
  for (int i = 0; i < s.length; i++) 
  {
   if (s[i].contains("HP")) {
    System.out.println(s[i]);
    }
    Label res =new Label(0, i, s[i]);
    
    ws.addCell(res);
   }
   wb.write();
   wb.close();
   driver.findElement(By.xpath("//*[@id='products']/div[1]/div[1]/div/div[1]/a")).click();
   ArrayListwindow =new ArrayList(driver.getWindowHandles());
   driver.switchTo().window(window.get(0));
   Thread.sleep(1000);
   driver.findElement(By.xpath("//*[@id='mprod-buy-btn']/form/input[3]")).click();
  }
  
  @BeforeTest
  public void beforeTest() {
   driver =new FirefoxDriver();
   driver.get("http://www.flipkart.com/");
   driver.manage().window().maximize();}
@AfterTestpublic void afterTest() {

driver.quit();}

}

try to excute it

38 comments:

  1. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
    Hadoop Training Institute In chennai

    ReplyDelete
  2. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.


    rpa training in Chennai | rpa training in velachery

    rpa training in tambaram | rpa training in sholinganallur

    rpa training in Chennai | rpa training in pune

    rpa online training | rpa training in bangalore

    ReplyDelete
  3. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    python training in annanagar
    python training in chennai
    python training in chennai
    python training in Bangalore

    ReplyDelete
  4. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
    Devops training in sholinganallur
    Devops training in velachery

    ReplyDelete
  5. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.

    Best Selenium Training in Chennai | Selenium Training Institute in Chennai | Besant Technologies

    Selenium Training in Bangalore | Best Selenium Training in Bangalore

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    ReplyDelete
  6. I was curious if you ever considered changing the layout of your site? It’s very well written; I love what you’ve got to say. But maybe you could a little more in the way of content so people could connect with it better.
    industrial safety courses in chennai

    ReplyDelete
  7. Nice post. I learned some new information. Thanks for sharing.

    endtoendhrsolutions
    Technology

    ReplyDelete
  8. Informative post,It is useful for me to clear my doubts.I hope others also like the information you gave in your blog.
    german language classes in bangalore
    learn german in bangalore
    German Training in Mogappair
    German Training in Nungambakkam

    ReplyDelete
  9. Hi,
    I must appreciate you for providing such a valuable content for us. This is one amazing piece of article. Helped a lot in increasing my knowledge.
    Android Training Chennai
    Android Courses in Chennai
    Android Mobile apps Development Training in Chennai
    AWS Training in Chennai
    AWS Training
    AWS Course in Chennai

    ReplyDelete
  10. At this time, it seems like Word Press is the preferred blogging platform available right now.
    occupational health and safety course in chennai

    ReplyDelete
  11. Very good brief and this post helped me alot. Say thank you I searching for your facts. Thanks for sharing with us!
    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  12. Amazing! This blog looks just like my old one!
    It’s on a completely different subject but it has pretty much
    the same layout and design. Wonderful choice
    of colors!

    Java Training in Chennai

    Java Course in Chennai


    ReplyDelete
  13. No.1 AWS Training Institute in Chennai | Infycle Technologies

    Description:
    Study Amazon Web Services for making your career as a shining sun with Infycle Technologies. Infycle Technologies is the best AWS training institute in Chennai, providing complete hands-on practical training of professional specialists in the field. In addition to that, it also offers numerous programming language tutors in the software industry such as Oracle, Python, Big Dat, Hadoop, etc. Once after the training, interviews will be arranged for the candidates, so that, they can set their career without any struggle. Of all that, 200% placement assurance will be given here. To have the best career, call 7502633633 to Infycle Technologies and grab a free demo to know more.
    Amazon Web Service

    ReplyDelete
  14. Titlle
    Top AWS Course in Chennai | Infycle Technologies

    Description:


    Wanna have a good carrier in software fields? Come to Infycle Technologies. We provide the Top AWS training in Chennai. Not only that, we also offer more than 20 software training courses with 100% job assurance. Along with that, we prefer a mock interview session for students, so that they can attend the interview without any fear. For more details dial 7502633633


    ReplyDelete

  15. Title:
    Get Big Data Certification in Chennai | Infycle Technologies

    Description:
    Learn Big Data for making your career towards a sky-high with Infycle Technologies. Infycle Technologies is the best Big Data training institute, providing courses for the Big Data certification in Chennai in 200% hands-on practical training with professional trainers in the domain. Apart from the training, the placement interviews will be arranged for the students, so that they can set their career without any struggle. Of all that, 100% placement assurance will be given here. To have the best career, call 7502633633 to Infycle Technologies and grab a free demo to know more.
    Best training in Chennai

    ReplyDelete
  16. Infycle Technologies, the best software training institute in Chennai offers the No.1 Data Science training in Chennai for Students, tech professionals, and freshers. In addition to the Data Science Training Course, Infycle also offers other professional courses such as Cyber Security, Python, Oracle, Java, Power BI, Digital Marketing, Big Data, etc., which will be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7502633633 to get more info and a free demo.

    ReplyDelete
  17. If Database is a job that you're dreaming of, then we, Infycle are with you to make your dream into reality. Infycle Technologies offers the best Oracle DBA Training in Chennai, along with various levels of Oracle courses such as Oracle PLSQL, Oracle Hive, etc., in hands-on practical training with professional tutors in the field. The training will be tested by various levels of preparation strategies for the placement and by that the mock interviews will be given for the candidates, so that, they can face the interviews with full confidence. For your enhanced future, call 7502633633 to know more offers and training.
    Best software training in Chennai

    ReplyDelete