网站layout的automation

研究这个问题的原因,是因为在我们site上,有很多的google ads,对于每个ads的显示位置有严格的requirement。为此,我也吃了几个priority比较高的ticket。

GALEN(http://galenframework.com/)就是这样一个framework,不得不说还是很好用的,也很方便。

首先在pom文件中加入galen dependency

     <dependency>
        <groupId>net.mindengine</groupId>
        <artifactId>galen</artifactId>
        <version>1.4.9</version>
     </dependency>

然后定义element的位置: SRP.spec

@@ import Header.spec

============================================================================================
srp-skyscraper-banner xpath        //iframe[@id='google_ads_iframe_/7917/srp_0']
srp-bottom-banner1    xpath        //iframe[@id='google_ads_iframe_/7917/srp_2']
# srp-bottom-banner2    xpath        //iframe[@id='google_ads_iframe_/7917/srp_3']

srp-featured-ads      xpath        //h3[contains(text(), 'Featured Ads')]
srp-refine-search     xpath        //div[@id='refine-search']//div[@class='module-content']
srp-paging-bar        xpath        //div[@class='rs-paginator c-margin-vertical1']
srp-user-activity     xpath        //div[@id='user-activity']

==============================================================================================
    
@ desktop, tablet-l
srp-skyscraper-banner
    width: 160 px
    height: 600 px
    below: srp-featured-ads 20 to 130 px
    inside: srp-refine-search 20 to 30 px right

@ desktop, tablet-l, tablet-p
srp-bottom-banner1
    width: 728 px
    height: 90 px
    below: srp-paging-bar 10 to 20 px
    above: srp-user-activity 20 to 30 px

# @ ^
# srp-bottom-banner2
#    width: 728 px
#   height: 90 px
#   below: srp-user-activity 20 to 30 px
    

@ mobile
srp-bottom-banner1
    width: 320 px
    height: 50 px
    below: srp-paging-bar 10 to 20 px
    above: srp-user-activity 20 to 30 px

#@ ^
#srp-bottom-banner2
#    width: 320 px
#    height: 50 px
#   below: srp-user-activity 20 to 30 px

最后code:

        @Then("I should see the banners on '$page' rendered on '$device' '$orientation' orientation")
	public void checkBannersOnHpOnTabletOrMobile(@Named("$page") String page, 
			@Named("$device") String device,
			@Named("$orientation") String orientation) throws Exception{
		
		Dimension dimension = DeviceSizes.getDeviceDimension(device, orientation);
		WebDriver driver = getWebDriver(page, dimension);
		
		String tag = DeviceSizes.getTag(device, orientation);
		
		LayoutReport layoutReport = 
	            Galen.checkLayout(driver, "src/main/resources/spec/" + page + ".spec", 
	            Arrays.asList(tag), null, null, null);
		
		// Creating a list of tests
        List<GalenTestInfo> tests = new LinkedList<GalenTestInfo>();

        // Creating an object that will contain the information about the test
        GalenTestInfo test = GalenTestInfo.fromString(device + "_" + orientation);

        // Adding layout report to the test report
        test.getReport().layout(layoutReport, "check layout on " + device + " " + orientation +" orientation");
        tests.add(test);


        // Exporting all test reports to html
        new HtmlReportBuilder().build(tests, "target/galen-html-reports");

	   if (layoutReport.errors() > 0) {
	        StringBuffer sb = new StringBuffer();
	        List<ValidationError> errorList = layoutReport.getValidationErrors();
	        Iterator<ValidationError> errorListIt = errorList.iterator();
	        	
	        while(errorListIt.hasNext()){
	        	ValidationError error = errorListIt.next();
	        	sb.append(error.toString());
	        }
	        Assertion.assertTrue(false, sb.toString());
	   }
		
	}

这个framework还有很多其他的强大之处,有兴趣的同学可以自己去研究研究。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值