# Ruby Version 1.9.2-p180
def reverseTest(inputtext)
@a=""
regextext = /[!,.;"()<>\[\]{}]/
arr = inputtext.split(/\s/)
arr.reverse_each { |item|
len = @a.length
# Dealing with a word surrounding by one or multiple punctuation
if item.partition(regextext).at(1)!=''
# Partition the word by particular punctuation, until partition by the last punctuation
begin
@a .insert(len,item.partition(regextext).at(0))
@a .insert(len,item.partition(regextext).at(1))
item = item.partition(regextext).at(2)
end while item.partition(regextext).at(1)!='' && item.partition(regextext).at(2)!=''
# When punctuation is at the end coming after a word
@a .insert(len,item.partition(regextext).at(0))
@a .insert(len,item.partition(regextext).at(1))
@a << ' '
# Dealing with a word without surrounding any punctuation
else
@a << item
@a << ' '
end
}
#Remove space at the end of the string and swap symmetry punctuation
@a.strip!
@a.gsub!(/[()<>\[\]{}]/, '('=>')', ')'=>'(', '<'=>'>', '>'=>'<', '['=>']',']'=>'[', '{'=>'}', '}'=>'{')
print @a
end
Sunday, March 13, 2011
Reverse*a*Sentence*With*Ruby code
For example , if you want "One, Two, Three, Four." to be converted into “.Four ,Three ,Two ,One”, take a look at my ruby version for your reference, hope it helps in some degree :) I know you may never need this function, but some people may let you write such kind of things...
Thursday, March 03, 2011
Using JNative to load AutoITX.dll
I am working on JNative to load AutoITX.dll, and get my complex UI methods work for WebDriver.
First download JNative.jar from website then add JNative.jar to your build path.
Download your AutoITX from http://www.autoitscript.com/site/autoit/downloads/
2 useful docs which you can refer to:
Function reference
http://www.autoitscript.com/autoit3/docs/functions.htm
and AutoITX Help doc -> DLL interface introduction(Find it after installing AutoITV3)
Then start to create your own method based on AutoITX great Functions which in AutoITX.dll
Here is a sample code to create mouse move methods in Java
I will work on more functions and hope they may help my WebDriver automation tests soon :) Enjoy!
Update: The source code has been uploaded to my github, check it out if you like : https://github.com/joychester/AutoIT-in-Java
First download JNative.jar from website then add JNative.jar to your build path.
Download your AutoITX from http://www.autoitscript.com/site/autoit/downloads/
2 useful docs which you can refer to:
Function reference
http://www.autoitscript.com/autoit3/docs/functions.htm
and AutoITX Help doc -> DLL interface introduction(Find it after installing AutoITV3)
Then start to create your own method based on AutoITX great Functions which in AutoITX.dll
Here is a sample code to create mouse move methods in Java
package org;
import org.xvolks.jnative.JNative;
import org.xvolks.jnative.exceptions.NativeException;
public class LoadDllSample {
public static void main(String[] args) throws IllegalAccessException {
// TODO Auto-generated method stub
try {
GetMyMouseMove(100, 100 ,40);
} catch (NativeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
* AutoItX Interface For AU3_MouseMove() Function
AU3_API long WINAPI AU3_MouseMove(long nX, long nY, long nSpeed);
*/
public static void GetMyMouseMove(int x, int y, int s) throws NativeException, IllegalAccessException{
JNative nGetMyMouseMove = new JNative("C:\\Program Files\\AutoIt3\\AutoItX\\AutoItX3.dll", "AU3_MouseMove"); //load .dll file and specific func
nGetMyMouseMove.setParameter(0,x);//The screen x coordinate to move the mouse to.
nGetMyMouseMove.setParameter(1,y);//The screen y coordinate to move the mouse to.
nGetMyMouseMove.setParameter(2,s);//The speed s to move the mouse (optional)
nGetMyMouseMove.invoke();
return;
}
}
I will work on more functions and hope they may help my WebDriver automation tests soon :) Enjoy!
Update: The source code has been uploaded to my github, check it out if you like : https://github.com/joychester/AutoIT-in-Java
Tuesday, March 01, 2011
Profiling OSGi project with Btrace
I met "java.lang.NoClassDefFoundError" when i did profiling with my OSGi project:
So two things need to be modified from my side:
1. add package to btrace code , for example "package com.sun.btrace.samples;"
2. add OSGI config.properties in felix/conf/ to include org.osgi.framework.bootdelegation=com.sun.btrace,com.sun.btrace.*
Then start your application, enjoy profiling with Btrace:)
Thanks for @yardus great help and also good post from this: http://blogs.sun.com/binublog/entry/glassfish_v3_profiling
Error com.myapp.template.TemplateServlet - TemplateServlet.doGet() exception
java.lang.NoClassDefFoundError: CodeLineTiming at com.myapp.service.proxy.abc.impl.ServiceProxyImpl.$btrace$CodeLineTiming$onCall(ServiceProxyImpl.java) at com.myapp.service.proxy.abc.impl.ServiceProxyImpl.getRfpWithChangeLog(ServiceProxyImpl.java:467) at
...
So two things need to be modified from my side:
1. add package to btrace code , for example "package com.sun.btrace.samples;"
package com.sun.btrace.samples;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.aggregation.*;
@BTrace
public class MethodResponseTime {
...
}
2. add OSGI config.properties in felix/conf/ to include org.osgi.framework.bootdelegation=com.sun.btrace,com.sun.btrace.*
Then start your application, enjoy profiling with Btrace:)
Thanks for @yardus great help and also good post from this: http://blogs.sun.com/binublog/entry/glassfish_v3_profiling
Tuesday, February 22, 2011
Making VisualVM as a Windows service on remote server
I am often Adding a remote JMX connection to the VisualVM to do monitoring work to capture JVM performance status. however, some of application are running as a windows service remotely, so i can not use Btrace Workbench then. if you do not want to change the Windows service back to console mode, then here is what I solved mine:
PS:Making sure Latest JDK1.6 installed for getting jVisualVM and Btrace, more info please refer to https://visualvm.dev.java.net/pluginscenters.html, your JAVA_HOME can be a separate one for your java application.
Step1: Remote to the application server using a console mode: mstsc /console /v: (For Winows server 2003 or winXP sp2) or admin mode:mstsc /admin /v: (Windows XP Service Pack 3, Windows Vista Service Pack 1 and Windows Server 2008 or later), why? please see this link
Step2: Use AppToService.exe to create VisualVM as a Windows service
Type such command line in cmd:
Step3: Start the "VisualVM" in Services
So you can see the VisualVM will launch on your remote desktop, then the Java process on that server running as a service can be monitoring as a local process.
Some Useful References:
http://blogs.sun.com/nbprofiler/entry/monitoring_java_processes_running_as
http://vicevoice.blogspot.com/2009/09/vaas-visualvm-as-service.html
http://www.microsoftnow.com/2008/01/no-more-mstscexe-console.html
More update from Sun blog: https://blogs.oracle.com/nbprofiler/entry/monitoring_java_processes_running_as My Friend Roy and Rudy's help as well:)
PS:Making sure Latest JDK1.6 installed for getting jVisualVM and Btrace, more info please refer to https://visualvm.dev.java.net/pluginscenters.html, your JAVA_HOME can be a separate one for your java application.
Step1: Remote to the application server using a console mode: mstsc /console /v:
Step2: Use AppToService.exe to create VisualVM as a Windows service
Type such command line in cmd:
AppToService.exe /Install "C:\Program Files\Java\jdk1.6.0_24\bin\jvisualvm.exe" /AbsName:"VisualVM" /Interact:1
Step3: Start the "VisualVM" in Services
So you can see the VisualVM will launch on your remote desktop, then the Java process on that server running as a service can be monitoring as a local process.
Some Useful References:
http://blogs.sun.com/nbprofiler/entry/monitoring_java_processes_running_as
http://vicevoice.blogspot.com/2009/09/vaas-visualvm-as-service.html
http://www.microsoftnow.com/2008/01/no-more-mstscexe-console.html
More update from Sun blog: https://blogs.oracle.com/nbprofiler/entry/monitoring_java_processes_running_as My Friend Roy and Rudy's help as well:)
Thursday, February 17, 2011
Wednesday, February 09, 2011
Monday, January 17, 2011
Little's Law on Performance Test
Little's Law, as a part of Queuing theory, which was introduced to me by Wilson Mar about 2 years ago. We can make use of it to help performance test planning and modeling.
I also would like to usually calculate the arrival rate of system :
After calculating the arrival rate λ , I will compare arrival rate λ with Throughput X to see if the system can catch up the incoming load, if not, then start tuning it!
One example:
Some Update after several years I met with such an elegant equation, following results are what i have worked with my perf team to prove the Little's law:
Little's Law for Finding Response Time:
MeanResponseTime(AVG) = MeanNumberInSystem(VUs) / MeanThroughput(TPS)
I also would like to usually calculate the arrival rate of system :
L = λW
λ = L/W
Where,
W = Average response time + Think time
L = Virtual Users we simulate in load generation tool
After calculating the arrival rate λ , I will compare arrival rate λ with Throughput X to see if the system can catch up the incoming load, if not, then start tuning it!
One example:
W =(0.352 + 0); -- which means no think time for test
L = 8;
then,
λ = L/W = 8/(0.352 + 0) = 22.73
Meanwhile, get Throughput measured by load generation tool
Throughput = 22
Not that bad currently :)
Some Update after several years I met with such an elegant equation, following results are what i have worked with my perf team to prove the Little's law:
Little's Law for Finding Response Time:
MeanResponseTime(AVG) = MeanNumberInSystem(VUs) / MeanThroughput(TPS)
Assumptions:
- Stable system, in the long terms
- No Obvious System Bottlenecks
- Similar Actions in the system
Test And Measurement -- Get XXX Pages:
VUs
|
AVG(ms)
|
90%(ms)
|
TPS
|
Calculated VUs using Little's Law
|
---|---|---|---|---|
1 | 58 | 72 | 16.98 | 0.99 |
12 | 74 | 108 | 161.63 | 11.96 |
25 | 83 | 121 | 297.99 | 24.73 |
50 | 138 | 209 | 360.67 | 49.77 |
75 | 197 | 349 | 379.59 | 74.78 |
100 | 261 | 492 | 381.21 | 99.50 |
125 | 326 | 636 | 381.80 | 124.71 |
Predicting and Modeling:
- Find relations between VU and Avg Response Time By Curve fitting:
y = 0.0067x2 + 1.3698x + 53.613 |
- Response Time Validation:
Monday, January 10, 2011
Simulate Moving your mouse by AutoIT and WebDriver
You can use AutoIT within WebDriver to move your mouse freely, Create your own APIs to simulate your mouse move and click very easily, enjoy it! :)
Reference for my previous post on WebDriver and AutoIT: http://joychester.blogspot.com/2011/01/deal-with-file-download-in-webdriver-by.html
autoitx ai = autoitx.INSTANCE;
WebDriver driver = new FirefoxDriver();
driver.get("http://www.autoitscript.com/autoit3/downloads.shtml");
FirefoxWebElement downloadpic = (FirefoxWebElement) driver.findElement(By.cssSelector("img[alt=\"Download AutoIt\"]"));
int X = (int) downloadpic.getLocationOnScreenOnceScrolledIntoView().getX();
int Y = (int) downloadpic.getLocationOnScreenOnceScrolledIntoView().getY();
int offsetX = (int) downloadpic.getSize().getWidth();
int offsetY = (int) downloadpic.getSize().getHeight();
int posx = X + offsetX/2;
int posy = Y + offsetY/2;
ai.AU3_MouseMove(posx, posy, 20);
ai.AU3_MouseClick("left", posx, posy, 1, 10);
Reference for my previous post on WebDriver and AutoIT: http://joychester.blogspot.com/2011/01/deal-with-file-download-in-webdriver-by.html
Friday, January 07, 2011
Set up Browser caching with Caution to speed up your website
"If you use tech improperly , things will be messed up!"
There are good start tips for Browser caching strategy posted by HttpWatch long time ago: http://blog.httpwatch.com/2007/12/10/two-simple-rules-for-http-caching/
It works great in most of situation.
However, if you have your website more complex, such as using ajax, the post above may not be sufficient.
I found interesting post from caching on IE for caching Ajax requests:
Detail info goes to Fact#2 of this post: http://blog.httpwatch.com/2009/08/07/ajax-caching-two-important-facts/
Another conclusion for browser caching:
Detail info goes to this post: http://blog.httpwatch.com/2008/10/15/two-important-differences-between-firefox-and-ie-caching/
How to set up Cache-control and Expire header on Apache web Server based on your derision and deep understanding of your application:
http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html
There are good start tips for Browser caching strategy posted by HttpWatch long time ago: http://blog.httpwatch.com/2007/12/10/two-simple-rules-for-http-caching/
It works great in most of situation.
However, if you have your website more complex, such as using ajax, the post above may not be sufficient.
I found interesting post from caching on IE for caching Ajax requests:
This means that any Ajax derived content in IE is never updated before its expiration date – even if you use a forced refresh (Ctrl+F5)—which means even you add “Pragma: no-cache” header with your request.
The only way to ensure you get an update is to manually remove the content from the cache.
Detail info goes to Fact#2 of this post: http://blog.httpwatch.com/2009/08/07/ajax-caching-two-important-facts/
Another conclusion for browser caching:
“In order to ensure consistent caching behaviour with IE and Firefox you should:
Always specify an Expires header. It will normally be set to -1 for immediate expiration of HTML pages or a date well into the future for other resources such as images, CSS and Javascript;
If you want to force a page to be reloaded, even with the Back button, then use Cache-Control: no-cache, no-store”
Detail info goes to this post: http://blog.httpwatch.com/2008/10/15/two-important-differences-between-firefox-and-ie-caching/
How to set up Cache-control and Expire header on Apache web Server based on your derision and deep understanding of your application:
http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html
Wednesday, January 05, 2011
Deal with File download in WebDriver by AutoIT
"This is annoying , but you have to face it sometimes"
Solution:
1> Install AutoIT V3.2, not the latest version, like V3.3.6, BTW, you had better install AutoIT to its default folder:"C:\Program Files\AutoIt3"
2> Download jWinAuto
3> Add all .jars to your libs, including jna.jar and jAutoIt.jar within jWinAuto
4> Write your testing code
I put the Watir scripts in comments for each steps, FYI:
BTW, just realize WebDriver is implementing a batch of GUI event driven APIs, Cool!
Solution:
1> Install AutoIT V3.2, not the latest version, like V3.3.6, BTW, you had better install AutoIT to its default folder:"C:\Program Files\AutoIt3"
2> Download jWinAuto
3> Add all .jars to your libs, including jna.jar and jAutoIt.jar within jWinAuto
4> Write your testing code
I put the Watir scripts in comments for each steps, FYI:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.compdev.jautoit.autoitx.autoitx;
public class AutoIT {
public static void main(String[] args) throws InterruptedException {
//ai = WIN32OLE.new("AutoItX3.Control")
autoitx ai = autoitx.INSTANCE;
//ie=FireWatir::Firefox.new
WebDriver driver = new FirefoxDriver();
//ie.goto("http://www.autoitscript.com/autoit3/downloads.shtml")
driver.get("http://www.autoitscript.com/autoit3/downloads.shtml");
//ie.image(:alt,'Download AutoIt').click
driver.findElement(By.cssSelector("img[alt=\"Download AutoIt\"]")).click();
//res=ai.WinWait("Opening autoit-v3-setup.exe","",10)
int res = ai.AU3_WinWait("Opening autoit-v3-setup.exe","",10);
// if res = 1, then it shows you find the window with proper title
System.out.print("res" + res);
Thread.sleep(3000);
//res=ai.WinActivate("Opening autoit-v3-setup.exe")
ai.AU3_WinActivate("Opening autoit-v3-setup.exe","");
ai.AU3_Send("{TAB}",0);
Thread.sleep(3000);
ai.AU3_Send("{TAB}",0);
Thread.sleep(3000);
ai.AU3_Send("{ENTER}",0);
//Start file downloading...
}
}
So you can use AutoIT in WebDriver to deal with your Win32(disgusting) pop-ups or other situations, easily! Want to know how powerful the AutoIT is, please refer to its function reference :)BTW, just realize WebDriver is implementing a batch of GUI event driven APIs, Cool!
Subscribe to:
Posts (Atom)