Hey ,
Firstly thanks thanks thanks for taking your valuable time to read about me and ofcourse my blog :)
This is Vamshi Kurra.This blog is about my thoughts on life and my little little little knowledge on testing , test automation tools & other technical topics.
Personal :
Colors : Black and Blue
Hobbies : Blogging and Reading Books
Have a great great day .. !! :)
Firstly thanks thanks thanks for taking your valuable time to read about me and ofcourse my blog :)
This is Vamshi Kurra.This blog is about my thoughts on life and my little little little knowledge on testing , test automation tools & other technical topics.
Personal :
Colors : Black and Blue
Hobbies : Blogging and Reading Books
Have a great great day .. !! :)
Very good blog for automation...please some more information about webdriver...
ReplyDeleteThanks,
Sravan
Thanks Vamshi.Your blog is really packed with useful information.Thanks for sharing such great information with us all.
Delete-Vishal Aggarwal
http://testocean.blogspot.in
Thanks Vishal..!!
DeleteBetween your blog is awesome :)
Hey guys i am stuck with the problem here in reading the program from excel file and putting the values in web page. I have done the 2 ways first is through jexcel api and the program is below
ReplyDeleteimport java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;
import jxl.DateCell;
public class operationclass {
public void init(String filePath) {
FileInputStream fs = null;
try {
fs = new FileInputStream(new File(filePath));
contentReading(fs);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//Returns the Headings used inside the excel sheet
public void getHeadingFromXlsFile(Sheet sheet) {
int columnCount = sheet.getColumns();
for (int i = 0; i < columnCount; i++) {
System.out.println(sheet.getCell(i, 0).getContents());
}
}
public void contentReading(InputStream fileInputStream) {
WorkbookSettings ws = null;
Workbook workbook = null;
Sheet s = null;
Cell rowData[] = null;
int rowCount = '0';
int columnCount = '0';
DateCell dc = null;
int totalSheet = 0;
try {
ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));
workbook = Workbook.getWorkbook(fileInputStream, ws);
totalSheet = workbook.getNumberOfSheets();
if(totalSheet > 0) {
System.out.println("Total Sheet Found:" + totalSheet);
for(int j=0;j(CompoundFile.java:116)
at jxl.read.biff.File.(File.java:127)
at jxl.Workbook.getWorkbook(Workbook.java:268)
at operationclass.contentReading(operationclass.java:54)
at operationclass.init(operationclass.java:19)
at operationclass.main(operationclass.java:108). i dont know how to get rid of this error.can u guys help me please?
You can use regular FileReader class of java to read excel file.
ReplyDeleteHere is the sample code .
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
public class Excel{
public static void main(String [] args) throws IOException{
String sCurrentLine;
BufferedReader CSVFile = new BufferedReader(new FileReader("FILEPATH"));
String rows = CSVFile.readLine();
while ((sCurrentLine = CSVFile.readLine()) != null) {
System.out.println(sCurrentLine);
}
}
Does this help ?
Oh boss you are trying too much just use the below
ReplyDeleteWorkbook wb=Workbook.getWorkbook(new File(uri));
Sheet s=wb.getSheet(sheet_name);
for(i=0;i<s.getRows();i++)
{
for(j=0;j<s.getColumns();j++)
syso(s.getCell(i, j).getContents());
Nice blog vamsi i will share u r few posts in my blog.....
ReplyDeletehey sanjay i have something similar in ruby u can try this
ReplyDeletehope u will get some idea
#-------------------------------------------------1. Login and Logout Test Case (Using values from xls file)---------------------------------------------
require 'selenium-webdriver'
require 'test/unit'
require 'roo'
require 'rubygems'
class TC_Login < Test::Unit::TestCase #------------ define a class----------------
@@driver = Selenium::WebDriver.for :firefox #-------- Define driver element---------
@@driver.navigate.to "URL" #---- call url----
@@wait = Selenium::WebDriver::Wait.new(:timeout => 60) # seconds #----define wait------
@@data = Roo::Excel.new("E:\\test1updated.xls") #------ define excel
@@xls = Roo::Spreadsheet.open('E:\\test1updated.xls')
def test_Login
login_page()
rows = @@xls.sheet(0).count
2.upto(rows) do |i|
login()
end
end
def login_page
sleep(5)
@@wait.until do @@driver.find_element(:class, " navbar-inner")
@@driver.find_element(:link, "Login").click
end
@@driver.find_element(:id, "txtUserName")
@@driver.find_element(:id, "txtPassword")
if @@driver.find_element(:id, "txtUserName").displayed?
username = @@driver.find_element(:id, "txtUserName")
password = @@driver.find_element(:id, "txtPassword")
end
end
def login
2.upto(@@data.last_row) do |row| #------- to read fron second row in excel sheet---------
username_value = @@data.cell(row, 'A')
puts username_value
sleep(5)
password_value = @@data.cell(row, 'B')
puts password_value
puts password_value.to_i
puts password_value.to_i.to_s
puts username_value
puts password_value
puts "Hi-------------------@@@@@@@@@@@@@@@@@@@@"
username = @@driver.find_element(:id, "txtUserName")
password = @@driver.find_element(:id, "txtPassword")
username.send_keys username_value
sleep(10)
password.send_keys password_value.to_i.to_s
puts "Hi1-------!!!!!!!!!!!!!!!!!!!!!!"
#------ parse into integer and then into string-----------
@@driver.find_element(:id, "btnLogin").click
logout()
end
end
def logout
@@wait.until { @@driver.find_element(:class, "container")}
@@driver.find_element(:class, "dropdown-toggle")
@@driver.find_element(:class, "dropdown-toggle")
@@driver.find_element(:class, "caret").click
@@wait.until { @@driver.find_element(:class, "dropdown-menu")}
@@wait.until { @@driver.find_element(:xpath, ".//*[@id='patient_banner_linkLogout']").click}
alert = @@driver.switch_to.alert
alert.accept()
login_page()
end
end
HI Vamshi,
ReplyDeleteYour Blogs helps alot in learning selenium..
I have interview by Tomorrow on 26th sep..
i need answers for this.
what are the challenges faced during automation using selenium2? and solution to over come from it?
what are the bugs one can find the automation?
what are cross browsers issues? please give me example for each issue?
Thanks,
Taj
hi khurra how are u
Deletei very happy to read ur selenium example .
pls help me in how to read excel file using selenium webdriver
my email id is bbitharen@gmail.com
sumit choudhary
HI Vamshi,
ReplyDeleteFirst of all i want to thanks for your blogs.Your each post has helped me alot.
i need answers for some question,
what are the challenges you faced during automation using selenium2? ant? jenkins? and how to overcome from each challenge?
what are the cross browser issues? give examples on this topic?
how to handle multiple browsers in webdriver? if i want to run my testng.xml on more than two browsers,where actually we have to setting to run parallel on different browsers?
Challenges faced during automation always depend on the project you are working on . Most of the time issues come with captcha , flash , script executon etc.
DeleteFor captcha , we have our development team to disable captcha for specific IP address so we were able to overcome it.
I couldn't answer most of your questions now.
Wish you luck for your Interview..!! Give your best :)
Hi Vamshi Kurra,
ReplyDeleteThanks for such a nice content for selenium :) , It really helps a lot
Actually i m fresher in Testing world n having lot of interest in Selenium
So, Now a days i m struggling with below mention topic , pls help me in this :
How to Upload File/Photo using “Upload Image Button” in Selenium Webdriver
WebElement UploadImg = driver.findElement(By.xpath("//*[@id='file_upload_button']"));
UploadImg.click();
WebElement frame =driver.switchTo().activeElement();
frame.sendKeys("d:\5.jpg");
This code just open system window but it doesn't select any Photo/File
Hi Niya,
DeleteI am not sure on which site you are testing it.Can you share the site url on which you tried?
Here is the sample script:
driver.get("http://www.freeonlinephotoeditor.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("file")).sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg");
driver.findElement(By.name("upload")).submit();
Thank You So much For Reply
ReplyDeleteRefer a Link for a above problem :
http://classifieds.sandhira.com/toronto/pet/birds
For this button , our website use ajax
hence above written code is not working over.
Niya,
DeleteI couldn't find a solution for this till now . I will give it a try and update you If I happen to get a solution :)
meanwhile , if you happen to get the solution then please do share :)
Thanks for reply & help :)
ReplyDeleteAnd i will surly tell you if i get a solution....!
Hi Vamshi , I have query that how to set specif value in slider , i am able to move the slider but not able to set slider on specif value..Hope u can help me in this .. :)
ReplyDeleteHi Niya,
DeleteSpecifying value in slider can be done by using javascript.
I am not sure which site you are referring but the below code works fine for http://jqueryui.com/slider/ .
driver.get("http://jqueryui.com/slider/");
driver.switchTo().frame(0);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementsByClassName('ui-slider-handle ui-state-default ui-corner-all')[0].setAttribute('style', 'left: 18%;')");
Actually i knew the code u have given , however i wanna set specific value in slider , for ex. go to www.myntra.com and set exact 3000 value in slider , According to my knowledge : onces u move and set the slider on 3000 value than it display 3000 in hidden textbox and changing value in that doesn't affect on slider hence, Now we have to achieve this through URL as u can see ...slider value effect in URL . Hope u can help me in this :)
ReplyDeleteHi Vamshi , i solved program :D that i asked yesterday.
ReplyDeleteCool :)
DeleteDid you use javascript executor or any other thing to solve it ?
No i just rearrange the URL. and set a slider based on that :)
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi Vamshi,
ReplyDeleteI have one very small doubt. If I want to Click on LOGIN button after entering Username and Password in Facebook login page:
Does really the below code, clicks on LOGIN button
driver.findelement(By.Id("loginbutton")).sendkeys(keys.Enter);
If not, what does actually the above code does?
This comment has been removed by the author.
ReplyDeleteHi Vamshi,
ReplyDeleteI have one very small doubt. If I want to Click on LOGIN button after entering Username and Password in Facebook login page:
Does really the below code, clicks on LOGIN button
driver.findelement(By.Id("loginbutton")).sendkeys(keys.Enter);
If not, what does actually the above code does?
Hi,
DeleteUse the below code for clicking on LOGIN button.
driver.findElement(By.cssSelector("input[value='Log In']")).submit();
OR
driver.findElement(By.cssSelector("input[value='Log In']")).sendKeys(Keys.ENTER);
In your code , you have not used the correct locator for login button.So it does nothing .
driver.findelement(By.Id("loginbutton")).sendkeys(keys.Enter);
Hi Vamshi,
DeleteThank you for addressing my Question. When I tried both the code line you have given, I see only 1st submit() code is working whereas 2nd code is functioning same as my code "driver.findelement(By.Id("loginbutton")).sendkeys(keys.Enter);".
No actions performed on the button. I am very much curious to witness what actually Special Characters do when we pass it via sendKeys().
Hi,
DeleteSecond code worked for me on ff 26.0 . somehow it is not working on ff 27.0
Regarding your second question special characters functionality is as same as what they do when you manually send it .
Ex :
Below code can refresh a webpage by sending F5 key .
driver.findElement(By.name("email")).sendKeys(Keys.F5);
Hi All,
ReplyDeleteCan anybody please help me solve the following issue.
I have an element on webpage which carry text like this Questions›Create questions where Questions is link type and its very easy to find its locator but the second one 'Create question' is static i.e. its not link type and fixed.
I'm unable to find the locator for 'Create question' text as it combines with Questions and create a xpath like this .//*[@id='main']/h2"
I really need to find the locator OR is there any technique which can help me get the partial text of any locator?
You can check whether text is present on the webpage ro not by checking sourcecode page .
Deleteex:
driver.getPageSource().contains("Create question");
Hope it helps..!!
html code
ReplyDelete/h2
a href="https://abcd.com/test2/test/public/admin/question/index/index/project_id/1"
span style="font-size:9pt;">Question/span
/a
span style="margin:0px 10px;">›/span
Create question
h2/
I was doing one thing and stucked somewhere, Kindly help some one by giving the code details,
ReplyDeleteWhen we are using test ng to fail any test case we are ususally writing assertion method to fail the test case. But after that it's coming out and not executing rest of the test case.
So I caught that error in try catch block.
And now all test cases passed,the failed one also.
But i want to fail the test case and pass all other.So some how i have to tell the reporter to fail the test case with error messege.
Ho to do that.I know through test ng listener we can do it,but plz tell me details with code(Any example u can give)
I was doing one thing and stucked somewhere, Kindly help some one by giving the code details,
ReplyDeleteWhen we are using test ng to fail any test case we are ususally writing assertion method to fail the test case. But after that it's coming out and not executing rest of the test case.
So I caught that error in try catch block.
And now all test cases passed,the failed one also.
But i want to fail the test case and pass all other.So some how i have to tell the reporter to fail the test case with error messege.
Ho to do that.I know through test ng listener we can do it,but plz tell me details with code(Any example u can give)
Hi Gourab ,
ReplyDeleteIf you create every testcase as individual class testNG will run all testcases irrespective of the run-state of previous testcase.
Also you can use Reporter.log("") to log details of tests in the output file.