Category Archives: javascript

使用Protractor 做终端测试

什么?为什么要做终端测试? 其实你可以不做,如果你的网站只是一次开发的话。 你如果看到10多页的电子表格回归测试,然后让你做10次…. 想想都会哭。在09年刚做开发的时候我竟然做的很开心,被虐的不够啊…. 我是被虐了近6年之后才接触自动化测试的 😭

由于是java程序员,刚开始做终端测试自然就想到用java的框架。感觉学习过程累,不容易掌握,跑起来有点慢,占用资源多。哇,好多缺点。

直到有一天听了一个特别无聊的分享之后,偶尔从中间听到了nodejs 的protractor 做终端测试,尝试了一下,确实挺容易。

到底有多容易呢? 看代码吧。

首先是配置文件

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    // seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['HomePageSpec.js'],
    onPrepare: function () {
        browser.driver.manage().window().setSize(1680, 1050);
    },
}

然后是测试用例

var HomePage = function() {
    this.centerStageButtons = element(by.css(".announcement-bar"));

    this.viewOnGitHubButton = this.centerStageButtons.all(by.css(".button.button-small")).get(0);
    // this.downloadButton = this.centerStageButtons.element(by.css(".btn-primary"));
    // this.designDocsButton = this.centerStageButtons.element(by.css(".btn-warning"));
};


describe('haha', function() {
    var homePage = new HomePage();

    beforeEach(function() {
        browser.get('https://angularjs.org/');
    });

    it('should have a three buttons', function() {
        expect(homePage.viewOnGitHubButton.isDisplayed()).toBe(true);
    });
});

 

这个例子测试在angularjs.org 的网站上要有一个github的链接,如果有测试就通过。

运行测试用例

$ protractor protractorConf.js

 

因为protractor 是专门用来测试angularjs 的网站的,假如不是angularjs 也没有关系,配置一下就可以了

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    // seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['HomePageSpec.js'],
    onPrepare: function () {
        browser.driver.manage().window().setSize(1680, 1050);
        browser.ignoreSynchronization = true;
    },
}

完整的代码可以在这里找到:https://github.com/yhjhoo/protractorTest.git

参考链接:http://blog.scottlogic.com/2015/11/06/ProtractorForBeginnersPart1.html

http://www.protractortest.org/#/tutorial

Openlayer 保存错误 – outside of (-180.0,180.0)

先给出错误信息

An error occured while operating the transaction,detail: org.geotools.referencing.operation.projection.PointOutsideEnvelopeException: 229.37199228042 outside of (-180.0,180.0)
Parsing failed for LineString: org.geoserver.wfs.WFSException: org.geotools.referencing.operation.projection.PointOutsideEnvelopeException: 229.37199228042 outside of (-180.0,180.0)
org.geotools.referencing.operation.projection.PointOutsideEnvelopeException: 229.37199228042 outside of (-180.0,180.0)
229.37199228042 outside of (-180.0,180.0)

解决方法:
给你的地图加一个界限

layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                        "http://map.local:28080/geoserver/Test/wms", {layers: 'Test:Test'} );
    
                vlayer = new OpenLayers.Layer.Vector( "Editable" );
                graticuleCtl = new OpenLayers.Control.Graticule({
                    numPoints: 2, 
                    labelled: true
                });
                map = new OpenLayers.Map( 'map', {
                    controls: [
						graticuleCtl,
                        new OpenLayers.Control.PanZoom(),
                        new OpenLayers.Control.EditingToolbar(vlayer)
                    ],
                    zoomOffset:14,
                    maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
					restrictedExtent: new OpenLayers.Bounds(-180, -90, 180, 90)
                });
                
                var nav = new OpenLayers.Control.NavigationHistory();
                // parent control must be added to the map
                map.addControl(nav);

                
                map.events.register('zoomend', map, function(e){
					if(map.getZoom()<3){
						//map.zoomTo(3);
						nav.previousTrigger();
					}
				});
                
                
                
                
                map.addLayers([layer, vlayer]);
    
                //map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
                map.zoomToMaxExtent();
				map.setCenter(new OpenLayers.LonLat(110, 0), 5);