自动化测试尝试

 

1、

Selenium IDE

Selenium IDE is a Chrome and Firefox plugin which records and plays back user interactions with the browser. Use this to either create simple scripts or assist in exploratory testing.

Selenium IDE是一个Chrome 和火狐的插件,用于记录和播放用户操作。可以用于常规性功能测试。

介绍地址:https://www.seleniumhq.org/download/

Google浏览器自动化测试插件下载地址:https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd/related

2、安装后,可看到插件显示在浏览器的图标,单击打开

3、选择记录一个新的测试:Record a new test in a new project 链接

4、输入项目名称

5、输入项目进入的根网站路径,比如百度首页,

点击Start Recording开始记录

6、在打开的百度输入框里面输入自动化测试

7、点击插件可以看到已经记录下了刚才我的操作:

8、点击Stop Recording 按钮停止记录,输入测试名称,点击ok,后一个简单的测试实现了

9、测试回放:点击Run current test 按钮运行当前测试。

动态Linq表达式生成

 

动态构建 WHERE(C=>C.Id=Value):

public static IQueryable<T> WhereEqual<T>(this IQueryable<T> q, string fieldName, string fieldValue)
        {
            Type t = typeof(T);
            ParameterExpression param = Expression.Parameter(t, "c");
            Expression left = Expression.Property(param, t.GetProperty(fieldName));
            Expression right = Expression.Constant(fieldValue);
            Expression filter = Expression.Equal(left, right);
            Expression pred = Expression.Lambda(filter, param);
            Expression expr = Expression.Call(typeof(Queryable), "Where", new Type[] { t }, Expression.Constant(q), pred);
            return q.Provider.CreateQuery<T>(expr);

        }

动态构建List的Contains表达式:

        public static Expression<Func<TEntity, bool>> ContainsPredicate<TEntity, T>(T[] arr, string fieldname) where TEntity : class
        {
            ParameterExpression entity = Expression.Parameter(typeof(TEntity), "entity");
            MemberExpression member = Expression.Property(entity, fieldname);

            var containsMethods = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public)
            .Where(m => m.Name == "Contains");
            MethodInfo method = null;
            foreach (var m in containsMethods)
            {
                if (m.GetParameters().Count() == 2)
                {
                    method = m;
                    break;
                }
            }
            method = method.MakeGenericMethod(member.Type);
            var exprContains = Expression.Call(method, new Expression[] { Expression.Constant(arr), member });
            return Expression.Lambda<Func<TEntity, bool>>(exprContains, entity);
        }

参考地址:https://stackoverflow.com/questions/278684/how-do-i-create-an-expression-tree-to-represent-string-containsterm-in-c

感想dudu 大佬 :https://q.cnblogs.com/q/111853/

ftp上传

 
public class FtpUtil
    {
        string ftpServerIP;
        string ftpRemotePath;
        string ftpUserID;
        string ftpPassword;
        string ftpURI;

        /// <summary>
        /// 连接FTP
        /// </summary>
        /// <param name="FtpServerIP">FTP连接地址</param>
        /// <param name="FtpRemotePath">指定FTP连接成功后的当前目录, 如果不指定即默认为根目录</param>
        /// <param name="FtpUserID">用户名</param>
        /// <param name="FtpPassword">密码</param>
        public FtpUtil(string FtpServerIP, string FtpRemotePath, string FtpUserID, string FtpPassword)
        {
            ftpServerIP = FtpServerIP;
            ftpRemotePath = FtpRemotePath;
            ftpUserID = FtpUserID;
            ftpPassword = FtpPassword;
            ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";
        }

        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="filename"></param>
        public void Upload(string filename)
        {
            FileInfo fileInf = new FileInfo(filename);
            string uri = ftpURI + fileInf.Name;
            FtpWebRequest reqFTP;

            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
            reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
            reqFTP.KeepAlive = false;
            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
            reqFTP.UseBinary = true;
            reqFTP.UsePassive = false;
            reqFTP.ContentLength = fileInf.Length;
            int buffLength = 2048;
            byte[] buff = new byte[buffLength];
            int contentLen;
            FileStream fs = fileInf.OpenRead();
            try
            {
                Stream strm = reqFTP.GetRequestStream();
                contentLen = fs.Read(buff, 0, buffLength);
                while (contentLen != 0)
                {
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }
                strm.Close();
                fs.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Ftphelper Upload Error --> " + ex.Message);
            }
        }

    }

最新文章

  1. 利用JDBC连接MySQL并使用MySQL
  2. Android控件开发之Chronometer(转)
  3. LintCode Count 1 in Binary
  4. (easy)LeetCode 258.Add Digits
  5. Android图片缩放方法
  6. Remove “System Program Problem Detected” Messages From Ubuntu
  7. java实现二维码
  8. warshall、
  9. Promise原理与实现探究的一种思路
  10. vue学习之ajax 简单快速使用axios
  11. [Swift]LeetCode529. 扫雷游戏 | Minesweeper
  12. 和初学者交流学习java语言一些体会。
  13. angular 定时函数
  14. 【CF446D】DZY Loves Games 高斯消元+矩阵乘法
  15. nodejs xpath
  16. PHP百分号转小数,php 小数转换百分数函数
  17. C/C++中的static关键字详解
  18. LoadRunner--Analysis各项指标详解
  19. java中守护线程的一些概念和用法
  20. C/C++入门易错点及常用小技巧

热门文章

  1. SSM(SpringMVC+Spring+Mybatis)框架程序on IDEA
  2. 实用的表格内省略号和换行(兼容IE6)
  3. Android -- ShortCut
  4. JS中关于in运算符的问题
  5. 免费的HTML模板引导 - lonely
  6. C++ Linux 多线程之创建、管理线程
  7. Android控件之HorizontalScrollView 去掉滚动栏
  8. Cocos2d-x Touch事件处理机制
  9. IOS企业开发者帐号申请
  10. 微信小程序 - 生命周期