Monday, February 2, 2015

Selenium in C# - Browser Automation

OpenQA.Selenium:
Start: http://docs.seleniumhq.org/docs/03_webdriver.jsp
SetPreference: http://seleniumeasy.com/selenium-tutorials/firefox-profile-preferences-using-selenium-webdriver

FindElement(By): http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/By.html?_sm_au_=iVVsMF35HZfF7QWj

FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.proxy.http", "1234");
FirefoxDriver browser = new FirefoxDriver(profile);
browser.PageSource.Contains("abcd");
IWebElement total = browser.FindElement(By.ClassName("ddd"));//css class
String totalStr = total.Text;

ReadOnlyCollection<IWebElement> children = total.FindElements(By.ClassName("eee")).FindElement(By.ClassName("fff"));
foreach (IWebElement product in children){}
String innerHtml = total.GetAttribute("innerHTML");
total.Click();

//selelium's approach: scroll an element into view
browser.ExecuteJavaScript("arguments[0].scrollIntoView(true);", total);

xpath
("//div[@class='abc']")[1]
("//div[contains(@class, 'abc']")//h4[contains(text(), 'bb')]


KB: C#

AppSettingsReader:
Read app.config file

XmlDocument & XmlNode (Read XML file):
XmlDocument configDoc = new XmlDocument();
configDoc.Load(fileName);
XmlNode oneNode = configDoc.SelectSingleNode("//config/");
String abc = botNode.Attributes["proxy"];

Attribute & CustomAttributeData:
FieldInfo[] fs = obj.GetType().GetFields();
foreach (FieldInfo f in fs)
{
IList<CustomAttributeData> attributes = CustomAttributeData.GetCustomAttributes(f);
        foreach (CustomAttributeData attribute in attributes)
        {
             //check if the field was marked as [ConfigValue]
             if (attribute.Constructor.DeclaringType.Equals(typeof(ConfigValue)))
    {}
}
}



    [AttributeUsage(AttributeTargets.Field)]
    public class ConfigValue : Attribute
    {
        private String prameName;
        public ConfigValue(String name)
        {
            prameName = name;
        }

    }

    [AttributeUsage(AttributeTargets.Field)]
    public class RegexFile : Attribute
    {
        private String fileName;
        public RegexFile(String name)
        {
            fileName = name;
        }
    }


Use:
        [ConfigValue]
        String proxy;

        [RegexFile("rabc.regex")]
        private Regex rabc;

Friday, January 16, 2015

KB: VB

VBScript:
aa.bat:
rem wscript abc.vbs male
cscript abc.vbs male

abc.vbs:
set wnet =CreateObject("WScript.Network")
uname=wnet.UserName
uage = InputBox("Please enter your age")
gender = WScript.Arguments(0)
MsgBox "Your user name is " & uname & "," & uage & "," & gender

Friday, January 2, 2015

Publish your Android app


1. Generate key
     http://www.apkbus.com/android-44559-1-1.html





















2. Go to Google Play Developer page to publish the app (registration fee $25 for lifetime)

Ref:
http://developer.android.com/distribute/index.html
http://mobile.51cto.com/android-228966_all.htm

Wednesday, November 19, 2014

LISP

How to run LISP:
http://www.cs.columbia.edu/~sal/notes/lisp-running.txt

1. http://www.sbcl.org/ 运行效果最好,可以用(load "c:\\game\\test.lisp")
2. gnu clisp: http://reflection.oss.ou.edu/gnu/gnu/gcl/binaries/stable/ 可以运行load, 但是会出现Error in COND
3. Lispworks最差,连Load都运行不了

Saturday, November 8, 2014

在Eclipse配置UML

name: UML (objectAid) to write class & sequence diagram
序列图需要注册账号,可以免费用一个月
link: http://www.objectaid.com/

其他use case, architecture diagram可以用visio 来画