Wednesday, 4 November 2015
Wednesday, 7 October 2015
Integrating Autoit and Selenium: Uploading a file using autoit
While automating a web application I faced a challenge. The challenge is integrate autoit and selenium. So I am going to share the problem domain and the coded solution below so that others can find it out helpful
Problem domain: I have a file located in my own machine which I need to upload in one of my web application project
Used tool:
1. Selenium for automating web application
2. Autoit for interacting with windows/ uploading a file from own local machine
Step 1: Autoit code
Write the Autoit code:
ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload","","Edit1","D:\Test\Shp\Vegetation.zip")
ControlClick("File Upload", "", "Button1")
First write this autoit code and then save it using the extension, Example: fileupload.au3
Step 2: Compile script(Convert into .exe format)
Right click on the fileupload.au3 file and hit compile script, If you are using a 32 bit OS then choose x86 option and if you are using a 64 bit os then choose x64 option
Step 3: Integrating with selenium
Write only the following line in your selenium code where you need to upload you file
Runtime.getRuntime().exec("C:\\Users\\example\\Desktop\\fileupload.exe")
(It is the file path of the .exe file)
Then run your selenium code and observe the expected result
This code works fine for me hope you will find this helpfull
Problem domain: I have a file located in my own machine which I need to upload in one of my web application project
Used tool:
1. Selenium for automating web application
2. Autoit for interacting with windows/ uploading a file from own local machine
Step 1: Autoit code
Write the Autoit code:
ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload","","Edit1","D:\Test\Shp\Vegetation.zip")
ControlClick("File Upload", "", "Button1")
First write this autoit code and then save it using the extension, Example: fileupload.au3
Step 2: Compile script(Convert into .exe format)
Right click on the fileupload.au3 file and hit compile script, If you are using a 32 bit OS then choose x86 option and if you are using a 64 bit os then choose x64 option
Step 3: Integrating with selenium
Write only the following line in your selenium code where you need to upload you file
Runtime.getRuntime().exec("C:\\Users\\example\\Desktop\\fileupload.exe")
(It is the file path of the .exe file)
Then run your selenium code and observe the expected result
This code works fine for me hope you will find this helpfull
Thursday, 1 October 2015
Draw in canvas using selenium web driver and java
Drawing 3 points which will create a polygon
WebElement element = driver.findElement(By.xpath("html/body/div[3]/div[2]/div[2]/div[2]/div/canvas"));
Actions builder = new Actions(driver);
Action drawAction = builder.moveToElement(element,135,15) // start point in the canvas
//signatureWebElement is the element that holds the signature element you have in the DOM
.click()
.moveByOffset(200, 60) // second point
.click()
.moveByOffset(100, 70) // third point
.doubleClick()
.build();
drawAction.perform();
WebElement element = driver.findElement(By.xpath("html/body/div[3]/div[2]/div[2]/div[2]/div/canvas"));
Actions builder = new Actions(driver);
Action drawAction = builder.moveToElement(element,135,15) // start point in the canvas
//signatureWebElement is the element that holds the signature element you have in the DOM
.click()
.moveByOffset(200, 60) // second point
.click()
.moveByOffset(100, 70) // third point
.doubleClick()
.build();
drawAction.perform();
Wednesday, 10 June 2015
Code academy: Function: 3/19: Calling a function with parameter
We've set up a function,
Solution:
def square(n):
"""Returns the square of a number."""
squared = n**2
print "%d squared is %d." % (n, squared)
return squared
# Call the square function on line 9! Make sure to
# include the number 10 between the parentheses.
square(10)
square
. Call it on the number 10
(by putting 10
between the parentheses of square()
) on line 9!Solution:
def square(n):
"""Returns the square of a number."""
squared = n**2
print "%d squared is %d." % (n, squared)
return squared
# Call the square function on line 9! Make sure to
# include the number 10 between the parentheses.
square(10)
Sunday, 31 May 2015
== Search Text for Your Name ==
We'll want to place the
var myArray = ['a', 'b', 'c'];
myArray[0]; // equals a.
Instructions:
Add your
There's no need to put anything between the
Solutions:
var text = "Hello world Keya how you doing Keya";
var myName ="Keya";
var hits = [];
for(var i=0; i<text.length; i++ )
{
if (text[i]=== 'K')
{
}
}
We'll want to place the
if
statement inside our for
loop to make sure the program checks the if
statement each time it moves forward through the loop. Essentially, the for
loop is saying: "Hey program! Go through every letter in 'text'." The if
statement will say: if
you see something interesting, push that text into an array!"var myArray = ['a', 'b', 'c'];
myArray[0]; // equals a.
Instructions:
Add your
if
statement in the body of your for
loop. It should check to see whether the current letter is equal to the first letter of your name. (Capitalization counts!)There's no need to put anything between the
{}
s of your if
just yet.Solutions:
var text = "Hello world Keya how you doing Keya";
var myName ="Keya";
var hits = [];
for(var i=0; i<text.length; i++ )
{
if (text[i]=== 'K')
{
}
}
While loop: Tutorial 5/11
== Practice makes perfect ==
Problem: Write a
Solve:
var count= 0;
var loop = function(){
while(count < 3){
console.log("I'm looping!");
count++;
}
};
loop();
== Practice makes perfect ==
Problem: Write a
while
loop that logs "I'm looping!" to the console three times. You can do this however you like, but NOT with three console.log
calls. Check the Hint if you need help!Solve:
var count= 0;
var loop = function(){
while(count < 3){
console.log("I'm looping!");
count++;
}
};
loop();
Python-Conditionals-and-Control-Flow 15/15
If...elif...else
Code:
def the_flying_circus():
if 12 and 1 + 1 == 2: # Start coding here!
print "Yes, I'm greater than 11!"
# Don't forget to indent
# the code inside this block!
return True
elif 11 < 12:
print "We are a circus of less than 12 men!"
# Keep going here.
return True
else:
print "We don't know how many people we are!"
# You'll want to add the else statement, too!
Code:
def the_flying_circus():
if 12 and 1 + 1 == 2: # Start coding here!
print "Yes, I'm greater than 11!"
# Don't forget to indent
# the code inside this block!
return True
elif 11 < 12:
print "We are a circus of less than 12 men!"
# Keep going here.
return True
else:
print "We don't know how many people we are!"
# You'll want to add the else statement, too!
Thursday, 28 May 2015
Python datetime format
Problem domain:
Format 1:
from datetime import datetime
now = datetime.now()
print now
print now.year
print now.month
print now.day
Format 2:
from datetime import datetime
now = datetime.now()
print '%s/%s/%s' % (now.month, now.day, now.year, )
Format 3: from datetime import datetime
now = datetime.now()
print '%s:%s:%s' % (now.hour, now.minute, now.second )
Format 4: from datetime import datetime
now = datetime.now()
print '%s/%s/%s %s:%s:%s' % (now.month,now.day,now.year, now.hour, now.minute, now.second )
- Create a variable called
now
and store the result ofdatetime.now()
in it. - Then,
print
the value ofnow
.
Solve:
from datetime import datetime
now = datetime.now()
print now
Output:
current date
Printing current date year and month code
Format 1:
now = datetime.now()
print now
print now.year
print now.month
print now.day
now = datetime.now()
print '%s/%s/%s' % (now.month, now.day, now.year, )
Format 3: from datetime import datetime
now = datetime.now()
print '%s:%s:%s' % (now.hour, now.minute, now.second )
Format 4: from datetime import datetime
now = datetime.now()
print '%s/%s/%s %s:%s:%s' % (now.month,now.day,now.year, now.hour, now.minute, now.second )
Saturday, 16 May 2015
Faced the following problem for send keys in selenium webDriver in Java
Java is throwing the following error while working with selenium
the method sendkeys(charsequence ) in the type webelement is not applicable for the arguments
the method sendkeys(charsequence ) in the type webelement is not applicable for the arguments
It has a simple solution. Change your compiler compliance level from 1.4 to 1.7.
Follow these steps in your eclipse:
- Right click on your java project and select Build Path -> Click on
Configure Build Path... - In project properties window, Click/select Java Compiler at the left
panel - At the right panel, change the Compiler compliance level from 1.4 to 1.7
(Select which is higher version in your eclipse) - Lastly Click on Apply and OK
Now check your code. it will never show the same error.
Wednesday, 13 May 2015
TestNG file execution Along with jar file.
TestNG file execution Along with jar file.
1. Create a main class 1st
package Testcase;
import com.beust.testng.TestNG;
@SuppressWarnings("deprecation")
public class MainOne {
public static void main(String[] args) {
TestNG testng = new TestNG();
Class[] classes = new Class[]{houpad.class}; //houpad is the class where i included all the //testNG executable testcases.
testng.setTestClasses(classes);
testng.run();
}
}
To export a jar file
1. Run the main class then
2. Right click on the package name> Export> Java> rurnnable JAR file> from the launch configuration select the main class created above.> Hit finish.
3. Now double click on the jar file
4. It will show the execution
http://testng.org/doc/documentation-main.html#running-testng-programmatically
1. Create a main class 1st
package Testcase;
import com.beust.testng.TestNG;
@SuppressWarnings("deprecation")
public class MainOne {
public static void main(String[] args) {
TestNG testng = new TestNG();
Class[] classes = new Class[]{houpad.class}; //houpad is the class where i included all the //testNG executable testcases.
testng.setTestClasses(classes);
testng.run();
}
}
To export a jar file
1. Run the main class then
2. Right click on the package name> Export> Java> rurnnable JAR file> from the launch configuration select the main class created above.> Hit finish.
3. Now double click on the jar file
4. It will show the execution
http://testng.org/doc/documentation-main.html#running-testng-programmatically
Subscribe to:
Posts (Atom)