SauceLabs + Selenium+ Nunit For Web Ui Test
来源:互联网 发布:java接口开发demo 编辑:程序博客网 时间:2024/05/22 09:42
Part I: about seting up the environment
1. I use C# language for writing test case.
2. Install Visual Studio 2015 like picture below:
3. Using NuGet on Visual Studio to install Nunit, selenium support and selenium webdriver three packages like picture below:
4. Until this step the environment is ok, you can start to write test cases.
5. If you do not know how to use selenium api and nunit . please buy related book or e-book to learn. no worry, it is easy to learn.
Part II : about using SauceLabs
1. SauceLabs instruction:
Saucelabs is a test platform it can support test moblie and Web UI and so on . it can support all kinds all language such as C# ,Java, Node.js, PHP, Python,Ruby.
2. Why we choose saucelabs to test ,the advantagesas below:
- Saucelabs has all kinds of browsers it support run against multiple
browers parallelly. - Saucelabs can run test cases fast only waste less time.
- Integrating a CI platform with Sauce Labs through sauce plugins and you can use jenkins or Bamboo CI platform and so on.
3.What are kinds of test can we use saucelabs
In all , saucelabs can support two kinds of test. one is manual test,the others is Auto test.
3.1 Maual test picture:
3.2 Auto test picture:
4. Using saucelabs to start auto test what things are you need to know?
- you need sig up a saucelab account. of course the free account what you sig up only have 90 minute to use.
- you should choose one of language for write test case. such as C# ,Java, Node.js, PHP, Python,Ruby. you can choose one of them what you like .
- write the username and accessKey of saucelabs account into your test code . I use C# language like below:
desiredCapabilites.SetCapability("accessKey", "2f11bc66-e756-4785-896b-4c6aba92e75c"); desiredCapabilites.SetCapability("username", "testlin_2016");
Part III : about run test case
1. Run test case throught jenkins
- Firstly, install jenkins and new jenkins job for test cases .
- Secondly install Sauce OnDemand Plugin on jenkins. about this you can follow the url below to install and configure on jenkins.
(https://wiki.saucelabs.com/display/DOCS/Installing+and+Configuring+the+Sauce+OnDemand+Plugin+for+Jenkins,
(https://wiki.saucelabs.com/display/DOCS/Configuring+Sauce+Connect+with+the+Jenkins+Plugin)
please feel free , it is easy to do . - If you install and configure succeed.you can see the picture on jenkins job Configure like picture below:
Util now you can click the button to run test case like picture below:
Of course, there is a good way that is set run time and use ant script to run your testcase on jenkins automatically.
set time like picture below:
use ant script like picture below:At last you can write the username and accessKey of saucelabs account into your test code like below instead of above.
desiredCapabilites.SetCapability("username",Environment.GetEnvironmentVariable("SAUCE_USER_NAME"));desiredCapabilites.SetCapability("accessKey", Environment.GetEnvironmentVariable("SAUCE_API_KEY"));
By the way if you do not know what are the SAUCE_USER_NAME and SAUCE_API_KEY .please go for this url below:
https://wiki.saucelabs.com/display/DOCS/Environment+Variables+Used+by+the+Jenkins+Plugin.
Part IV: Problems I meet
1. I can not access the svg element on web page.
solution: I use javascript in C#
public String GetEachAttributeName(IWebDriver driver, String objectString){ IWebElement svgObject = driver.FindElement(By.Id("svgobj"));IJavaScriptExecutor jsdriver = (IJavaScriptExecutor)driver;String result = jsdriver.ExecuteScript(objectString, svgObject).ToString(); return result; }public String GetNameJsString(String firstElement, String secondelement){ var getNameJsString = "var svg = arguments[0].contentDocument.getElementById('" + firstElement + "'),texts=svg.getElementsByTagName('" + secondelement + "');return texts[0].textContent;"; return getNameJsString;}
2. Sometimes selenium can not find the element.
solution: use try … catch to deal with exception.
public bool IsWebElementDisplayed(IWebElement driver, By selector){ bool isDisplayedFlag = false; int loopCount = 0; int maxLoopCount = 8; while (!isDisplayedFlag && loopCount< maxLoopCount) { loopCount++; try { IWebElement element = driver.FindElement(selector); isDisplayedFlag = element.Displayed; Console.WriteLine("IsWebElementDisplayed loopCount:{0},isDisplayedFlag: {1}", loopCount, isDisplayedFlag); return isDisplayedFlag; } catch (StaleElementReferenceException) { Thread.Sleep(1000); return false; } } Console.WriteLine("IsWebElementDisplayed loopCount:{0},isDisplayedFlag: {1}", loopCount, isDisplayedFlag); return isDisplayedFlag;}
In all , Web Ui test is easy to start. please no worry and you can follow this instruction step by step. good luck!
- SauceLabs + Selenium+ Nunit For Web Ui Test
- Lightweight UI Test Automation for ASP.NET Web Apps
- Selenium & Nunit GUI & WebDriver
- Creating configuration properties for Selenium Test Suite
- Python for Selenium: build test environment
- VS2010 web UI automation test
- Simple NUnit test
- Selenium中CSS定位Web UI元素
- 自动化测试开发实际应用系列(四)应用Selenium + NUNIT对动态WEB测试自动化
- 应用Selenium + NUNIT对动态WEB测试自动化(自动化测试开发实践系列)
- saucelabs + python +behave+ appium for android自动化测试
- selenium test
- 使用Watin做Web UI Automation Test
- 对比MS Test与NUnit Test框架
- 对比MS Test与NUnit Test框架
- for test test test
- Nunit + 任务计划 实现selenium测试自动化
- 使用NUnit来执行Selenium WebDriver测试
- 开启 C++ 学习之路
- DSHOW 显示视频
- 各种内排序算法源码汇总--c语言
- Rightmost Digit
- iOS-Xcode8之调用系统相册
- SauceLabs + Selenium+ Nunit For Web Ui Test
- 深度学习框架PaddlePdddle学习( 二)
- Zookeeper总概
- MultipartFile-使用策略模式实现可拓展文件分类上传
- 究竟怎样写代码才算是好代码[转载]
- centos7 mini rpm安装mysql5.6.31
- [乐意黎]开通CSDN 博客快七周年,访问量终于超4000000次
- c语言中static的用法详细示例分析
- 6.27