目前ui框架会做一个更新,把原有的Jenkins分布式方式换成grid方式,换成grid方式有两个好处,1.grid的资源占用比Jenkins的jnlp占用资源少 2.grid可控制不同浏览器同时跑
看很多网上跑自己的案例都很顺,想直接拿过来用,中间遇到很多问题,发现自己的电脑,启动多个浏览器后,只会执行1个浏览器,读取数据库中的控件,报空指针问题等,类似并发的问题,最开始怀疑testng多线程问题,折腾了一天,发现是因为我们设计模式问题,并发中driver被覆盖了,哎,,,之后并发有遇到很多问题,为了不耽误项目进度,目前不考虑并发了,记录我最开始使用的demo
public class login { private WebDriver dr; DesiredCapabilities test; String baseUrl; String testExpectedStr; String requestId; String domainName = "https://www.rosewholesale.com/"; String getkeys = "ths#^$%^sdaf%T#$%^fasdbhf&U*$%%$^#"; @Parameters({ "browser", "nodeUrl", "webSite" }) @BeforeClass public void BeforeClass(String browser, String nodeUrl, String webSite) { baseUrl = webSite; if (browser.equals("ie")) { test = DesiredCapabilities.internetExplorer(); } else if (browser.equals("ff")) { test = DesiredCapabilities.firefox(); } else if (browser.equals("chrome")) { String url = nodeUrl + "/wd/hub"; URL urlInstance = null; try { urlInstance = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); System.out.println("实例化url出错,检查一下url格式是否正确,格式为:http://192.168.40.67:5555"); } System.out.println(test); System.out.println("使用的平台进行启动的浏览器"); String platform_name = "win7"; DesiredCapabilities capabilities = new DesiredCapabilities(); if (platform_name.equalsIgnoreCase("win7")) { capabilities.setPlatform(Platform.VISTA); } if (platform_name.equalsIgnoreCase("win8")) { capabilities.setPlatform(Platform.WIN8); } if (platform_name.equalsIgnoreCase("win8_1")) { capabilities.setPlatform(Platform.WIN8_1); } if (platform_name.equalsIgnoreCase("win10")) { capabilities.setPlatform(Platform.WIN10); } if (platform_name.equalsIgnoreCase("linux")) { capabilities.setPlatform(Platform.LINUX); } capabilities.setBrowserName(browser); capabilities.setVersion(browser); ChromeOptions options = new ChromeOptions(); options.addArguments("disable-infobars"); if (platform_name.equalsIgnoreCase("linux")) { options.addArguments(Arrays.asList("--window-position=0,0")); options.addArguments(Arrays.asList("--window-size=1920,1080")); } else { options.addArguments(Arrays.asList("--start-maximized")); } capabilities.setCapability("chrome.switches", Arrays.asList("--incognito")); options.addArguments("--test-type"); options.addArguments("start-maximized"); options.addArguments("chrome.switches", "--disable-extensions"); capabilities.setCapability(ChromeOptions.CAPABILITY, options); try { dr = new RemoteWebDriver(new URL(url), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } } else { System.out.println("browser参数有误,只能为ie、 ff、chrome"); } dr.get(webSite); } @Test public void signin_wrongemail() { Pub.checkStatusBrowser(); 以下是测试方法 }
以下是xml配置文件,并发方式以tests方式运行,class就是类名,以下包含一个登录一个注册
<suite name="template" parallel="tests" thread-count="5" > <test name="FirstTest" > <parameter name="browser" value="chrome"/> <parameter name="nodeUrl" value="http://10.33.6.230:5555"/> <parameter name="webSite" value="http://login.rosewholesale.com.trunk.s1.egomsl.com/m-users-a-sign.htm"/> <classes> <class name="com.globalegrow.login.login"> </class> </classes> </test> <test name="FirstTest2" > <parameter name="browser" value="chrome"/> <parameter name="nodeUrl" value="http://10.40.2.113:5555"/> <parameter name="webSite" value="http://login.rosewholesale.com.trunk.s1.egomsl.com/m-users-a-sign.htm"/> <classes> <class name="com.globalegrow.login.registered"> </class> </classes> </test> </suite>