zoukankan      html  css  js  c++  java
  • 原创:分享一个selenium帮助类 -- seleniumHelper for .net

    原创:分享一个selenium帮助类 -- seleniumHelper for .net

    GUI自动化测试接触的不多,以前也就接触过QTP(现在叫UFT了),但都没深入过。

    这次正好有个WEB测试项目,就试了下selenium.

    废话不多说了,先上效果.

     视频看不到的戳这里

    这里就拿百度来做个DEMO

    先上测试代码,源码下周放出,DLL在这里

     static void testBaidu()
            {
                string i = string.Empty;
                RemoteWebDriver driver = new ChromeDriver();
                IOptions io = driver.Manage();
                io.Window.Maximize();
                
    
                string url = @"http://www.baidu.com";
                driver.Navigate().GoToUrl(url);
    
                IWebElement searchBox = driver.GetElementLazy(By.Id("kw"), 10);
                if (searchBox.Location.X < 200)
                {
                    i = "1";
                    searchBox = driver.GetElementLazy(By.Id("kw1"), 10);
                }
                driver.HighLight(searchBox,2);
                
                StepInfo si = new StepInfo();
                si.StepName = "step 1";
                si.StepAction = "Type HP in search box";
                si.StepExResult = "HP displayed in search box";
                si.StepStatus = StepStatus.process;
    
                driver.ShowStepAroundElement(si, searchBox, Align.auto);
                Thread.Sleep(2000);
    
                driver.RemoveHelper();
                
                while(searchBox.Displayed == false)
                {
                    Thread.Sleep(1000);
                }
                searchBox.SendKeys("HP");
    
                si.StepStatus = StepStatus.fail;
                driver.ShowStepAroundElement(si, searchBox, Align.bottom);
                Thread.Sleep(2000);
                driver.RemoveHelper();
    
                IWebElement button = driver.GetElementLazy(By.Id("su"+i), 10);
                driver.HighLight(button);
                button.Click();
    
                driver.SwitchTo().DefaultContent();
                searchBox = driver.GetElementLazy(By.Id("kw"), 10);
                driver.HighLight(searchBox);
                searchBox.Clear();
    
                si.StepAction = "Type HP in search box";
                si.StepStatus = StepStatus.pass;
    
                driver.ShowStepAroundElement(si, searchBox, Align.right);
                Thread.Sleep(2000);
                driver.RemoveHelper();
                searchBox.SendNewKeys("Keys");
    
    
                button = driver.GetElementLazy(By.Id("su"), 10);
                driver.HighLight(button);
                string source = driver.Title;
    
                button.Click();
    
                //WebDriverWait wait = new WebDriverWait(driver,TimeSpan.FromSeconds(10));
                //IWebElement num = driver.FindElement(By.ClassName("nums"));
                //IWebElement num = wait.Until<IWebElement>((d) => { return d.FindElement(By.ClassName("nums")); });
                IWebElement num = driver.GetElementUntil(() => { return driver.Title != source; }, By.ClassName("nums"), 10);
                
               
                driver.HighLight(num, 3);
                si.StepName = "Step2";
                si.StepAction = "Check whether the record number";
                si.StepExResult = "The number should bigger than 20W";
                si.StepStatus = StepStatus.pass;
                driver.ShowStepAroundElement(si, num, Align.top);
    
    
                driver.SaveScreenUntil(() => { return driver.GetElementLazy(By.Id(si.StepId),2)!=null; }, @"E:	est.png", 2);
                driver.RemoveHelper();
    
                searchBox = driver.GetElementLazy(By.Id("kw"), 10);
                driver.HighLight(searchBox,2);
                searchBox.SendNewKeys("豆瓣音乐");
    
    
                button = driver.GetElementLazy(By.Id("su"), 10);
                driver.HighLight(button);
    
                button.Click();
                string xPath = "//span[text()='进入应用']";
                button = driver.GetElementLazy(By.XPath(xPath),10);
                driver.HighLight(button, 2);
                button.Click();
                Thread.Sleep(5000);
                driver.Quit();
            }
    View Code

    这个类主要扩展了IWebdriver的方法.

  • 相关阅读:
    微信小程序开发--页面之间的跳转
    iOS基础UI控件介绍-Swift版
    iOS技术栈-Swift版
    SpringBoot实战(四)获取接口请求中的参数(@PathVariable,@RequestParam,@RequestBody)
    SpringBoot实战(三)代码热部署
    SpringBoot实战(二)Restful风格API接口
    SpringBoot实战(一)HelloWorld
    Spring Boot浅谈(是什么/能干什么/优点和不足)
    CentOS的基本设置界面
    虚拟机VM安装Linux系统CentOS7
  • 原文地址:https://www.cnblogs.com/young1985/p/3560178.html
Copyright © 2011-2022 走看看