Äú¿ÉÒÔ¾èÖú£¬Ö§³ÖÎÒÃǵĹ«ÒæÊÂÒµ¡£

1Ôª 10Ôª 50Ôª





ÈÏÖ¤Â룺  ÑéÖ¤Âë,¿´²»Çå³þ?Çëµã»÷Ë¢ÐÂÑéÖ¤Âë ±ØÌî



  ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓÆµ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Model Center   Code  
»áÔ±   
   
 
     
   
 ¶©ÔÄ
  ¾èÖú
ÊÖ°ÑÊÖ½ÌÄã´î½¨Êý¾ÝÇý¶¯²âÊÔ¿ò¼Ü¹¹
 
  4276  次浏览      31
 2019-2-27
 

 

±à¼­ÍƼö:

±¾ÎÄÀ´×ÔÓÚtesterhome£¬ÎÄÕ½éÉÜÁËÈçºÎ´î½¨»ùÓÚSelenium WebDriverµÄÊý¾ÝÇý¶¯²âÊÔ¿ò¼ÜµÄÏà¹ØÄÚÈÝ¡£

ǰÑÔ

ÔÚ×Ô¶¯»¯²âÊÔ¿ò¼ÜÖУ¬Êý¾ÝÇý¶¯µÄÒâ˼ָ¶¨µÄÊDzâÊÔÓÃÀý»òÕß˵²âÊÔÌ×¼þÊÇÓÉÍⲿÊý¾Ý¼¯ºÏÀ´Çý¶¯µÄ¿ò¼Ü¡£ÕâÀï˵µÄÊý¾Ý¼¯¿ÉÒÔÊÇÈκÎÀàÐ͵ÄÊý¾ÝÎļþ±ÈÈçxls£¬xlsx£¬csvµÈµÈ¡£ËüµÄºËÐĵÄ˼Ïë¾ÍÊÇÊý¾ÝºÍ²âÊÔ´úÂë·ÖÀ룬¼°Ê±µ±²âÊÔÊý¾Ý·¢Éú´óÁ¿±ä»¯µÄÇé¿öϲâÊÔ´úÂ루»òÕß˵²âÊÔÓÃÀý£©¿ÉÒÔ±£³Ö²»±ä¡£Êý¾Ý¼¯ºÏÀïÓÐ1ÌõÊý¾ÝºÍ100ÌõÉõÖÁ¸ü¶à£¬ÊDz»»áÓ°Ïìµ½²âÊÔÓÃÀýµÄÖ´ÐС£Èç¹ûÏëʹÓÃÒ»×鲻ͬµÄÊý¾ÝÀ´Ö´ÐеÄÏàͬµÄ²Ù×÷ûÄÇôÄã¾Í¿ÉÒÔÑ¡ÔñÊý¾ÝÇý¶¯¡£

±ÈÈ磬ÔÚÕâôһÖÖ³¡¾°Ï£¬ÀýÈçÄãÐèÒªÓöà¸ö²»Í¬µÄÕ˺źÍÃÜÂëÀ´µÇ½ij¸öÓÊÏ䣬À´ÑéÖ¤ÄÄЩÊÇÓÐЧµÄÖµ£¬ÄÄЩÊÇ´íÎóµÄÖµ£¬»òÕßÄÄЩֵ¿ÉÒÔµ¼Ö³ö´í£¬ÕâÖ»ÊÇÒ»¸ö¼òµ¥µÄÀý×Ó¡£ÁíÍâÒ»¸ö¼òµ¥µÄÀý×Ó¾ÍÊÇÍøÂçµç»°µÄ²âÊÔ£¬µ±ÎÒÃÇÄ£ÄⲦºÅ¡¢¹Ò¶Ï¡¢»Ø²¦µÈµÈ²Ù×÷ʱÎÒÃÇÏ£ÍûÑé֤ÿ¸ö°´Å¥ÊÇ·ñÄÜÕý³£¹¤×÷²¢Äܵõ½ÕýÈ·µÄ½á¹û¡£

±¾ÆªÎÄÕÂÊÇ»ùÓÚSelenium WebDriverµÄÊý¾ÝÇý¶¯²âÊÔ¿ò¼Ü£¬Èç¹û´ó¼Ò¸ú×ÅÒ»²½Ò»²½´î½¨ÏÂÀ´£¬×îÖյĿò¼Ü½«×îÖÕʵÏÖÏÂÃæµÄÕâЩ¹¦ÄÜ£º

¿ÉÒÔÔÚ²âÊÔÌ×¼þÁбíÀïÉèÖÃÖ¸¶¨µÄ²âÊÔÌ×¼þÊÇ·ñÖ´ÐÐ

¿ÉÒÔÔÚ²âÊÔÓÃÀýÁбíÀïÉèÖÃÖ¸¶¨µÄ²âÊÔÓÃÀýÊÇ·ñÖ´ÐÐ

¿ÉÒÔÔÚ²âÊÔÊý¾Ý±íÀïÉèÖÃijÐвâÊÔÊý¾ÝÊÇ·ñ±»¶ÁȡִÐÐ

Ò»¸ö²âÊÔÓÃÀý¿ÉÒÔÓɶà¸ö²âÊÔÊý¾ÝÇý¶¯ÔËÐÐ

¿ÉÒÔ´òÓ¡²âÊÔ½á¹û±¨¸æ£¬ÏÔʾָ¶¨Êý¾ÝÐÐÖ´ÐÐÖ®ºóµÄ½á¹û

¿ÉÒÔ´òÓ¡ÕûÌå²âÊÔ½á¹û±¨¸æ£¬ÏÔʾÄÄЩÓÃÀýÖ´ÐÐͨ¹ý£¬ÄÄЩִÐÐʧ°Ü¡¢ÄÄÐ©Ìø¹ýûִÐÐ

±¨¸æ¿ÉÒÔÊÇtestngµÄÐÎʽ»òÕßÊÇXSLT

½ÓÏÂÀ´µÄ¹ý³ÌÖв»»á½²Ì«¶àÀíÂ۵Ķ«Î÷£¬¸ü×¢ÖØÓÚʵ¼ùµÄ²½Ö裬ÎÒ½«Ò»²½Ò»²½µÄ½éÉÜÈçºÎ´î½¨Õâ¸ö¿ò¼Ü£¬ÑÝʾ×ܸö¹ý³Ì¡£

ÔÚ¿ªÊ¼Ö®Ç°»¹ÊÇÒª†ªàÂһϣ¬´ó¼ÒÒª×ö×Ô¶¯»¯²âÊÔ£¬¿ª·¢ÄÜÁ¦ÊDZØÐëµÄ¡£ËùÒÔÏÂÃæËùÓйý³Ì¶¼ÊǼٶ¨Ò»¸öǰÌᣬÄǾÍÊÇÄã±ØÐëÊìϤjava£¬eclipse£¬TestNg£¬ant£¬POIµÈµÈ¹¤¾ß£¬Èç¹û»¹²»Çå³þµÄͬѧ¿ÉÒÔÏÈÊìϤһÏÂÕâ

´î½¨

´´½¨¹¤×÷¿Õ¼ä

°´ÕÕÏÂÃæ²½ÖèÔÚ´´½¨ ÏîÄ¿¹¤×÷¿Õ¼ä

ÔÚFÅÌÏ´´½¨Îļþ¼Ðbackup

ÔÚbackupÎļþ¼ÐÏ´´½¨TrainingÎļþ¼Ð

´´½¨Íê±Ï¾ÍÓÐÕâÑùµÄĿ¼½á¹¹F:\backup\Training¡£È»ºó´ò¿ªeclipse£¬Ñ¡ÔñÉÏÃæ´´½¨µÄÎļþ¼ÐΪ¹¤×÷¿Õ¼ä£¬ÈçÏÂͼËùʾ£º

###´´½¨ÏîÄ¿####

´´½¨Ò»¸öÃûΪWDDFµÄÏîÄ¿£¬ÎÒÃǽ«Ê¹ÓÃÕâ¸öÏîÄ¿À´´î½¨ÎÒÃǵIJâÊÔ¿ò¼Ü£¬´´½¨Íê±Ï£¬°ü½á¹¹ÈçͼËùʾ£º

´´½¨ÏîÄ¿µÄĿ¼½á¹¹

´´½¨ÏîĿĿ¼½á¹¹Ò²¾ÍÊÇÔÚÏîĿϴ´½¨ÐèÒªµÄ°üºÍÎļþ¼Ð½á¹¹¡£°ü½á¹¹ºÏÀí¾ÍºÜÈÝÒ×¶ÔÏîÄ¿µÄ×ÊÔ´½øÐйÜÀí¶ø²»ºúÂÒ¡£ÔÚ¡°WDDF¡±ÏîĿϴ´½¨Èçϰü£º

com.stta.ExcelFiles£º --´æ·Å.xslÎļþ

com.stta.Logging£º --´æ·Å.logÎļþ

com.stta.property£º --´æ·Å.propertyÎļþ

com.stta.SuiteOne£º --´æ·Å²âÊÔÌ×¼þÒ»Ïà¹ØÎļþ

com.stta.SuiteTwo£º --´æ·Å²âÊÔÌ×¼þ¶þÏà¹ØÎļþ

com.stta.TestSuiteBase£º --´æ·Å»ù±¾ÀàÎļþ

com.stta.utility£º --´æ·Å¹¤¾ßÀàÎļþ

com.stta.xslt: --´æ·Åtestng-results.xslÎļþ

ͬʱ´´½¨Îļþ¼Ð£º

1.JarFiles£º --´æ·ÅËùÓÐÐèÒªµÄÏà¹ØµÄjarÎļþ

µ½´Ë£¬ÏîÄ¿½á¹¹¾ÍÈçÏÂͼËùʾ£º

Õë¶Ô²»Í¬µÄÎļþÀàÐÍ´´½¨·ÖÀëµÄ°üµÄÊÇÓɺô¦µÄ£¬ÕâÑù×Ó¿ÉÒÔÔÚÎÒÃDzéÕÒ¡¢ÐÞ¸ÄÎļþµÄʱºòºÜ±ãÀû£¬ÀýÈçÄãÒªÐÞ¸å.xlsÎļþµÄÊý¾Ý£¬ÄÇôÄ㼸¿ÉÒÔÖ±½ÓÔÚcom.stta.ExcelFiles°üÀïÃæÕÒ£¬Í¬ÑùµÄÄãÏë²é¿´Ö´ÐеÄÈÕÖ¾£¬¾Í¿ÉÒÔÖ±½ÓÔÚcom.stta.LoggingÀïÃæ²é¿´£¬·Ç³£Ö±¹Û¡£

ºÃÁË£¬µ½´ËΪֹ£¬¿ÉÒÔ˵ÎÒÃÇÏîÄ¿µÄ»ù±¾³õʼ»¯¹¤×÷»ù±¾Íê³É¡£ºóÐø£¬ÔÚÐèÒªµÄʱºò£¬ÎÒÃÇ»¹»áÌí¼ÓеĵİüºÍÎļþµ½ÏîÄ¿ÖÐÈ¥¡£

ÏÂÔØÐèÒªµÄJar°ü

ÏÖÔÚÏîÄ¿½á¹¹¶¼´´½¨ºÃ£¬½ÓÏÂÀ´Òª×öµÄ¾ÍÊÇÏÂÔØËùÓÐÓõ½µÄJar°ü¡£ÕâÀïÎÒ»áÂÞÁÐËùÓÐÐèÒªÏÂÔØjar°ü¡£²¢Ò»¸ö¸öÏÂÔØÏÂÀ´±£´æµ½JarFilesÎļþ¼ÐÏ¡£

####Apache POI API####

Apache POI APIÊÇÓÃÀ´´Ó.xlsÎļþÖÐдÈë»òÕß¶ÁÈ¡Êý¾ÝÓõģ¬ËùÒÔ±ØÐëÏÂÔØApache POI APIºÍËüÒÀÀµÏà¹ØµÄjar°ü£¬²¢ÉèÖÃËüÃÅÔÚbuild pathÖУ¬ÎÒÃDzÅÄÜʹÓÃËü¡£

Apache POI API¿ÉÒÔÔÚËüµÄ¹ÙÍøÖ±½ÓÏÂÔØ¡£½øÈ¥ºóµã»÷¡°poi-bin-3.10-FINAL-20140208.tar.gz¡±¡£ÏÂÔØÍê±Ïºó½âѹ£¬½âѹĿ¼ÏºÍ×ÓĿ¼ÀïÃæµÄÏÂÁÐÎļþ¿½±´µ½¡°WDDF"ÏîÄ¿µÄJarFilesÎļþ¼ÐÏ£º

poi-3.10-FINAL-20140208.jar

poi-ooxml-3.10-FINAL-20140208.jar

poi-ooxml-schemas-3.10-FINAL-20140208.jar

xmlbeans-2.3.0.jar (ÔÚ×ÓĿ¼ ooxml-lib ÏÂ)

dom4j-1.6.1.jar (ÔÚ×ÓĿ¼ ooxml-lib ÏÂ)

×¢£ºÉÏÊöjar°üÔÚÒÔºó¿ÉÄÜ»á±ä£¬ÒòΪ°æ±¾»áÒ»Ö±¸üÐÂÂï¡£ÓÃ×îеľÍÊÇÁË£¬ÏÂÃæÌáµ½µÄjar°üÇé¿öºÍ´Ë´¦Ò»Ñù

Apache log4j

Apache log4j ÊÇÓÃÀ´¼Ç¼²âÊÔÖ´ÐÐÆÚ¼ä²úÉúµÄÈÕÖ¾µÄ£¬ÎÒÃÇÒ²ÐèÒª°ÑËü¼Óµ½build pathÖС£´ÓApache log4jÖ÷Ò³ÏÂÔØApache log4j jarÎļþ£¬²¢¿½±´µ½¡°WDDF"ÏîÄ¿µÄJarFilesÎļþ¼ÐÏ£º

log4j-1.2.17.jar

Selenium WebDriver

Èç¹ûÄãʹÓùýSelenium WebDriver£¬¹À¼Æ¾ÍÖªµÀʹÓÃselenium webdriverÐèÒªÏÂÔØÄÇЩjar°üÁË¡£´ÓSelenium WebDriverÖ÷Ò³ÏÂÔØSelenium WebDriverµÄzip°ü£¬½âѹ£¬²¢°Ñ"selenium-x.xx.x"Ŀ¼ºÍËüµÄ×ÓĿ¼¡°libs¡±ÏµÄËùÓÐjarÎļþ¿½±´µ½¡°WDDF"ÏîÄ¿µÄJarFilesÎļþ¼ÐÏ¡£

ÓëÉú³ÉXSLT±¨¸æÏà¹ØµÄjar

ΪÁËÄܹ»²úÉú½»»¥Ê½µÄ²âÊÔ±¨¸æ£¬ÎÒÃÇ»¹ÐèҪһЩ¹¤¾ßµÄÖ§³Ö¡£µ½Õâ¸öÒ³ÃæÏÂÔØÒ»¸özip°ü¡£½âѹ£¬²¢°Ñ"testng-xslt-1.1.2-master" -> "lib" ϵÄÏÂÁÐÎļþ¿½±´µ½¡°WDDF"ÏîÄ¿µÄJarFilesÎļþ¼ÐÏ£º

saxon-8.7.jar

SaxonLiaison.jar

¿½±´ ¡°testng-xslt-1.1.2-master\src\main\resources"Ŀ¼ÏµÄtestng-results.xslÎļþµ½°ücom.stta.xsltÏÂÃæ¡£

testng-results.xsl

»¹ÒªÔÚÏÂÔØtestng-xslt-maven-plugin-test-0.0.jar£¬²¢¿½±´µ½JarFilesÎļþ¼ÐÏ¡£ºóÐøÈç¹ûÐèÒª£¬ÎÒÃÇÔÙÏÂÔØÆäËûjar°ü¡£

µ½´ËΪֹ£¬ÎÒÃǵÄJarFileĿ¼ºÍcom.stta.xslt°ü¿´ÆðÀ´ÈçÏÂͼËùʾ£º

ÅäÖû·¾³

±¾¿ò¼ÜÖУ¬ÎÒÃÇʹÓÃApache POI API À´´Ó.xls ÖжÁÈ¡Êý¾Ý£¬Apache log4jÀ´¼Ç¼²âÊÔÖ´Ðйý³ÌÖвúÉúµÄÈÕÖ¾£¬¶øxslt ±¨¸æÓÃÀ´²úÉú½»»¥Ê½HTML±¨¸æ¡£ÏÂÔØÍêÏà¹ØµÄjar°üºó£¬ÎÒÃǾÍÐèÒª°ÑËûÃǼӵ½ ÏîÄ¿µÄbuild pathÖС£

Ñ¡ÔñÓʼþµã»÷ÏîÄ¿ WDDF£¬Ñ¡Ôñ "Build Path" -> "Configure Build Path"

µã»÷Libraries->Add external JARs

Ñ¡ÔñÉÏÊöÏÂÔØµÄËùÓÐjar°ü£¬µãÌí¼Ó->OK

ÕâÑùËùÓÐjar¾ÍÌí¼Óµ½build pathÖÐÁË¡£²é¿´Ò»ÏÂeclipse£¬»á¶àÁËÒ»¸ö¡°Referenced Libraries¡±£¬Referenced Librariesϰüº¬ËùÓÐËùÐè µÄjar°ü£º

´´½¨ÀàÎļþ

####´´½¨»ùÀà####

com.stta.TestSuiteBaseÏ´´½¨SuiteBase.java£¬Õâ¸öÀàÓÃÓÚ×ܸö¿ò¼Ü²âÊÔÌ×¼þµÄ»ùÀà

1.SuiteBase.java

com.stta.SuiteOneÕâ¸ö°üÓÃÀ´´æ·Å²âÊÔÌ×¼þÒ»µÄÏà¹ØµÄÀ࣬´´½¨ÈçÏÂÀࣺ

SuiteOneBase.java ---Õâ¸öÀàÓÃÓÚ²âÊÔÌ×¼þÒ»µÄ»ùÀà

SuiteOneCaseOne.java ---Õâ¸öΪ²âÊÔÌ×¼þÒ»µÄÓÃÀýÒ»

SuiteOneCaseOne.java ---Õâ¸öΪ²âÊÔÌ×¼þ¶þµÄÓÃÀý¶þ

com.stta.SuiteTwo Õâ¸ö°üÓÃÀ´´æ·Å²âÊÔÌ×¼þ¶þÏà¹ØµÄÀ࣬´´½¨ÈçÏÂÀࣺ

SuiteTwoBase.java

SuiteTwoCaseOne.java

SuiteTwoCaseTwo.java

com.stta.utility °ü×÷Ϊ²âÊÔ¿ò¼ÜµÄ»ù±¾¹¤¾ß°ü£¬´´½¨ÈçÏÂÁ½¸öÀࣺ

Read_XLS.java ---¶ÁÈ¡.xlsÎļþÏà¹Ø¸üÄܵÄÀà

SuiteUtility.java ---¹¤¾ßÀà

´´½¨Íê±Ï£¬Ä¿Â¼½á¹¹ÈçͼËùʾ£º

´´½¨xlsÎļþ

ΪÁ˼òµ¥Æð¼û£¬Õâ´Î´î½¨µÄ²âÊÔ¿ò¼ÜÖ»Ö§³Ö.xlsÎļþ£¬Í¨¹ý¼ìË÷.xlsÎļþ£¬²âÊÔ¿ò¼Ü¿ÉÒÔ»ñȡҪ²âÊÔÌ×¼þÃû³Æ¡¢ÊÇ·ñÖ´ÐеıêÖ¾£¬²âÊÔÓÃÀýµÄÃû³ÆÒÔ¼°ÊÇ·ñÖ´ÐÐÓÃÀýµÄ±ê־룬¶øÇҵȲâÊÔÖ´ÐÐÍê±Ï£¬¿ÉÒ԰ѲâÊÔ½á¹û.xlsÎļþµÄĩβ¡£ÏÖÔÚÏÈ´´½¨ÈçÈý¸ö.xlsÎļþ£º

TestSuiteList.xls

SuiteOne.xls

SuiteTwo.xls

´´½¨Í꣬com.stta.ExcelFiles¿´ÆðÀ´ÏñÏÂÃæµÄÑù×Ó£º

ÏÂÃæ½²ÏÂÕâÈý¸ö.xlsÎļþÔõô´´½¨£º

TestSuiteList.xls TestSuiteList.xlsÎļþÖ»ÓеÚÒ»¸ösheetÓÐÊý¾Ý£¬°ÑµÚÒ»¸ösheetÃüÃûΪSuitesList,SuitesListlÀïÃæÓÐÈýÁзֱðÊÇSuiteName¡¢SuiteToRun¡¢Skipped/Executed Èçͼ£º

SuiteOne.xlsÓëSuiteTwo.xls

ÕâÁ½ÎļþÀïÃæµÄ±í¸ñÊÇÒ»Öµģ¬¾Í·ÅÔÚÒ»Æð˵Ã÷£¬ÕâÁ½¸ö.xlsÎļþÓÐÈý¸ösheet£¬µÚÒ»¸öÊÇTestCasesList£¬²âÊÔÓÃÀýÁÐ±í£¬Ö¸Ã÷±¾²âÊÔÌ×Óм¸¸ö²âÊÔÓÃÀý¡£µÚ¶þºÍµÚÈý¸ösheetÃû³Æ·Ö±ðÊÇSuiteOneCaseOneºÍSuiteOneCaseTwo£¬·Ö±ðÊDzâÊÔÓÃÀýÒ»¸ö²âÊÔÓÃÀý¶þµÄ²âÊÔÊý¾Ý¡£TestCasesListÈçÏÂͼËùʾ£¬±í¸ñÒ²ÊÇÓÐÈýÁУ¬·Ö±ð±íʾ²âÊÔÓÃÀýÃû³Æ¡¢ÊÇ·ñÖ´ÐС¢ºÍÖ´Ðнá¹û Èý¸ö¡£

SuiteOneCaseOneºÍSuiteOneCaseTwoµÄ±í¸ñ½á¹¹ÈçÏÂͼËùʾ£º

¼Çסһ¸öÔ­Ôò£¬ÈçÏÂͼËùʾ£¬¼´eclipseÀï´Ó²âÊÔÀàµÄÃû³Æ¡¢TestCasesList±íµÄ²âÊÔÓÃÀýÃû³ÆºÍ²âÊÔÓÃÀýÊý¾ÝµÄsheetÃû³ÆÕâ¸öÈý¸öÒª±£³ÖÒ»Ö¡£ºóÐøÔö¼ÓÈκεIJâÊÔÓÃÀý¶¼Òª×ñÑ­Õâ¸öÔ­Ôò¡£

¿ªÊ¼Ð´´úÂë

Ç°Ãæ°ÑÒªÓõôµÄÀàÎļþÏÈ´´½¨ÆðÀ´ÁË£¬ÐèÒªµÄÓõ½µÄÎļþÒ²¶¼×¼±¸ºÃÁË£¬¿ÉÒÔ¿ªÊ¼Ð´´úÂëÁË¡£Ê×ÏÈÏÈд¿ò¼ÜµÄ¹¤¾ßÀàÀ´¶ÁÈ¡Êý¾Ý£¬ÒòΪÕâЩ¹¤¾ßÀàÔÚÆäËûÀàÖÐÆµ·±Óõ½ÏÈд¡£

Read_XLS.java´úÂëÈçÏÂ

package com.stta.utility;
import java.io.FileInputStream;
import java.io.FileOutputStream;
//import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;



public class Read_XLS {
public String filelocation;
public FileInputStream ipstr = null;
public FileOutputStream opstr =null;
private HSSFWorkbook wb = null;
private HSSFSheet ws = null;

public Read_XLS(String filelocation) {
this.filelocation=filelocation;
try {
ipstr = new FileInputStream(filelocation);
wb = new HSSFWorkbook(ipstr);
ws = wb.getSheetAt(0);
ipstr.close();
} catch (Exception e) {
e.printStackTrace();
}

}

//¼ìË÷ .xls Îļþ sheetsµÄÐÐÊý.
public int retrieveNoOfRows(String wsName){
int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return 0;
else{
ws = wb.getSheetAt(sheetIndex);
int rowCount=ws.getLastRowNum()+1;
return rowCount;
}
}

//¼ìË÷.xlsÎļþsheetsµÄÁÐÊý
public int retrieveNoOfCols(String wsName){
int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return 0;
else{
ws = wb.getSheetAt(sheetIndex);
int colCount=ws.getRow(0).getLastCellNum();
return colCount;
}
}

//¶ÁÈ¡²âÊÔÌ×¼þºÍ²âÊÔÓÃÀýµÄSuiteToRun and CaseToRun±êÖ¾
public String retrieveToRunFlag(String wsName,
String colName, String rowName){

int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return null;
else{
int rowNum = retrieveNoOfRows(wsName);
int colNum = retrieveNoOfCols(wsName);
int colNumber=-1;
int rowNumber=-1;

HSSFRow Suiterow = ws.getRow(0);

for(int i=0; i<colNum; i++){
if(Suiterow.getCell(i).getStringCellValue()
.equals(colName.trim())){
colNumber=i;
}
}

if(colNumber==-1){
return "";
}


for(int j=0; j<rowNum; j++){
HSSFRow Suitecol = ws.getRow(j);
if(Suitecol.getCell(0).getStringCellValue()
.equals(rowName.trim())){
rowNumber=j;
}
}
if(rowNumber==-1){
return "";
}

HSSFRow row = ws.getRow(rowNumber);
HSSFCell cell = row.getCell(colNumber);
if(cell==null){
return "";
}
String value = cellToString(cell);
return value;
}
}

//¶ÁÈ¡²âÊÔÊý¾ÝµÄDataToRun±êÖ¾.
public String[] retrieveToRunFlagTestData(String
wsName, String colName){

int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return null;
else{
int rowNum = retrieveNoOfRows(wsName);
int colNum = retrieveNoOfCols(wsName);
int colNumber=-1;


HSSFRow Suiterow = ws.getRow(0);
String data[] = new String[rowNum-1];
for(int i=0; i<colNum; i++){
if(Suiterow.getCell(i).getStringCellValue()
.equals(colName.trim())){
colNumber=i;
}
}

if(colNumber==-1){
return null;
}

for(int j=0; j<rowNum-1; j++){
HSSFRow Row = ws.getRow(j+1);
if(Row==null){
data[j] = "";
}
else{
HSSFCell cell = Row.getCell(colNumber);
if(cell==null){
data[j] = "";
}
else{
String value = cellToString(cell);
data[j] = value;
}
}
}

return data;
}
}

//´Ó²âÊÔÓÃÀýÊý¾Ýsheets¶ÁÈ¡²âÊÔÊý¾Ý.
public Object[][] retrieveTestData(String wsName){
int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return null;
else{
int rowNum = retrieveNoOfRows(wsName);
int colNum = retrieveNoOfCols(wsName);

Object data[][] = new Object[rowNum-1][colNum-2];

for (int i=0; i<rowNum-1; i++){
HSSFRow row = ws.getRow(i+1);
for(int j=0; j< colNum-2; j++){
if(row==null){
data[i][j] = "";
}
else{
HSSFCell cell = row.getCell(j);

if(cell==null){
data[i][j] = "";
}
else{
cell.setCellType(Cell.CELL_TYPE_STRING);
String value = cellToString(cell);
data[i][j] = value;
}
}
}
}
return data;
}

}


public static String cellToString(HSSFCell cell){
int type;
Object result;
type = cell.getCellType();
switch (type){
case 0 :
result = cell.getNumericCellValue();
break;

case 1 :
result = cell.getStringCellValue();
break;

default :
throw new RuntimeException("Unsupportd cell.");
}
return result.toString();
}

//ÔÚ²âÊÔÊý¾ÝºÍ²âÊÔÓÃÀý±íÀïдÈë²âÊÔ½á¹û
public boolean writeResult(String wsName, String
colName, int rowNumber, String Result){
try{
int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return false;
int colNum = retrieveNoOfCols(wsName);
int colNumber=-1;


HSSFRow Suiterow = ws.getRow(0);
for(int i=0; i<colNum; i++){
if(Suiterow.getCell(i).getStringCellValue()
.equals(colName.trim())){
colNumber=i;
}
}

if(colNumber==-1){
return false;
}

HSSFRow Row = ws.getRow(rowNumber);
HSSFCell cell = Row.getCell(colNumber);
if (cell == null)
cell = Row.createCell(colNumber);

cell.setCellValue(Result);

opstr = new FileOutputStream(filelocation);
wb.write(opstr);
opstr.close();


}catch(Exception e){
e.printStackTrace();
return false;
}
return true;
}

//ÔÚ²âÊÔÌ×¼þ±íÀïдÈë²âÊÔ½á¹û.
public boolean writeResult(String wsName, String
colName, String rowName, String Result){
try{
int rowNum = retrieveNoOfRows(wsName);
int rowNumber=-1;
int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return false;
int colNum = retrieveNoOfCols(wsName);
int colNumber=-1;


HSSFRow Suiterow = ws.getRow(0);
for(int i=0; i<colNum; i++){
if(Suiterow.getCell(i).getStringCellValue()
.equals(colName.trim())){
colNumber=i;
}
}

if(colNumber==-1){
return false;
}

for (int i=0; i<rowNum-1; i++){
HSSFRow row = ws.getRow(i+1);
HSSFCell cell = row.getCell(0);
cell.setCellType(Cell.CELL_TYPE_STRING);
String value = cellToString(cell);
if(value.equals(rowName)){
rowNumber=i+1;
break;
}
}

HSSFRow Row = ws.getRow(rowNumber);
HSSFCell cell = Row.getCell(colNumber);
if (cell == null)
cell = Row.createCell(colNumber);

cell.setCellValue(Result);

opstr = new FileOutputStream(filelocation);
wb.write(opstr);
opstr.close();


}catch(Exception e){
e.printStackTrace();
return false;
}
return true;
}
}

SuiteUtility.java´úÂ룺

package com.stta.utility;
public class SuiteUtility {

public static boolean checkToRunUtility(Read_XLS
xls, String sheetName, String ToRun, String testSuite){

boolean Flag = false;
if(xls.retrieveToRunFlag(sheetName,ToRun,testSuite)
.equalsIgnoreCase("y")){
Flag = true;
}
else{
Flag = false;
}
return Flag;
}

public static String[] checkToRunUtilityOfData(Read_XLS
xls, String sheetName, String ColName){
return xls.retrieveToRunFlagTestData(sheetName,ColName);
}

public static Object[][] GetTestDataUtility(Read_XLS
xls, String sheetName){
return xls.retrieveTestData(sheetName);
}

public static boolean WriteResultUtility(Read_XLS
xls, String sheetName, String ColName, int rowNum,
String Result){
return xls.writeResult(sheetName, ColName, rowNum, Result);
}

public static boolean WriteResultUtility(Read_XLS
xls, String sheetName, String ColName, String
rowName, String Result){
return xls.writeResult(sheetName, ColName, rowName,
Result);
}

}

¼òµ¥Êý¾Ý¶ÁÈ¡²âÊÔ

²âÊÔ¿ò¼ÜµÄ.xlsÎļþ¶ÁÈ¡¹¤¾ßÒѾ­×¼±¸ºÃ£¬°´ÕÕÇ°Ãæ´´½¨µÄ²âÊÔÀ࣬ÎÒÃÇÒª´´½¨Á½¸ö²âÊÔÌ×¼þ£¬Ã¿¸ö²âÊÔÌ×¼þÓÐÁ½¸ö²âÊÔÓÃÀý£¬×ܹ²¾ÍÊÇ2¸ö²âÊÔÌ×¼þºÍ4¸ö²âÊÔÓÃÀý¡£¶ÔÓÚÿ¸ö²âÊÔÌ×¼þ·Ö±ð¶ÔÓ¦Á½¸ö²»Í¬.xlsÎļþ¡£²âÊÔÌ×¼þ¡¢²âÊÔÓÃÀýÓë.xlsÎļþÖ®¼äµÄÓ³Éä¹ØÏµÈçÏÂËùʾ£º

com.stta.SuiteOne -> SuiteOne.xls

SuiteOneCaseOne.java -> SuiteOneCaseOne Sheet

SuiteOneCaseTwo.java -> SuiteOneCaseTwo Sheet

com.stta.SuiteTwo -> SuiteTwo.xls

SuiteTwoCaseOne.java -> SuiteTwoCaseOne Sheet

SuiteTwoCaseTwo.java -> SuiteTwoCaseTwo Sheet

±àд²âÊÔ´úÂë

ÎÒÃÇÏȳ¢ÊÔ´ÓSuiteOne.xlsÎļþµÄSuiteOneCaseOne sheetÀï¶ÁÈ¡Êý¾Ý£¬²¢Çý¶¯²âÊÔÓÃÀýSuiteOneCaseOne.javaÖ´ÐС£Ê×ÏÈÏÈдSuiteBase.java¡£

SuiteBase.java

SuiteBaseÀàÖд´½¨Ò»¸ö³õʼ»¯·½·¨£¬ÓÃÀ´³õʼ»¯.xlsÎļþ·¾¶

package com.stta.TestSuiteBase;
import java.io.IOException;
import com.stta.utility.Read_XLS;

public class SuiteBase {

public static Read_XLS TestSuiteListExcel=null;
public static Read_XLS TestCaseListExcelOne=null;
public static Read_XLS TestCaseListExcelTwo=null;

public void init() throws IOException{
//´úÂëÖÐÎļþ·¾¶¸ù¾Ýʵ¼ÊÇé¿öÌîд
//ʹÓÃRead_XLS¹¤¾ßÀà³õʼ»¯²âÊÔ²âÊÔÌ×¼þÁбíTestSuiteList.xls
TestSuiteListExcel = new Read_XLS(System.getProperty("user.dir")+"\\src\\com
\\stta\\ExcelFiles\\TestSuiteList.xls");
//ʹÓÃRead_XLS¹¤¾ßÀà³õʼ»¯²âÊÔÌ×¼þÒ»SuiteOne.xls
TestCaseListExcelOne = new Read_XLS(System.getProperty("user.dir")+"\\src\\com
\\stta\\ExcelFiles\\SuiteOne.xls");
//ʹÓÃRead_XLS¹¤¾ßÀà³õʼ»¯²âÊÔÌ×¼þ¶þSuiteTwo.xls
TestCaseListExcelTwo = new Read_XLS(System.getProperty("user.dir")+"\\src\\com
\\stta\\ExcelFiles\\SuiteTwo.xls");
}
}

SuiteOneBase.java

SuiteOneBaseÀàÔÚÕâ¸ö²½ÖèÖÐÎÒÃÇ»¹²»ÊµÏÖÈκι¦ÄÜ£¬½ö½ö¼Ì³ÐÁËSuiteBaseÀà

ackage com.stta.SuiteOne;
import com.stta.TestSuiteBase.SuiteBase;

//SuiteOneBase Àà¼Ì³Ð SuiteBase Àà.
public class SuiteOneBase extends SuiteBase{

}

SuiteOneCaseOne.java

ÕâÊÇÎÒÃǵIJâÊÔÀ࣬ÔÚÕâ¸öÎļþÖÐÎÒÃÇ´Ó.xlsÎļþ¶ÁÈ¡Êý¾Ý²¢´òÓ¡³öÀ´¡£Õâ¸öÀà °üº¬ÁËÏÂÁÐÈý¸ö·½·¨:

checkCaseToRun()---ʹÓÃtestNGµÄ@BeforeTest±êÇ©£¬Ëü½«ÔÚËùÓÐ@Test·½·¨Ö®Ç°±»ÔËÐУ¬Õâ¸ö·½·¨Ö»Òª¾ÍÊǵ÷ÓÃSuiteBaseÀàµÄInit() À´³õʼ»¯.xlsÎļþ·¾¶£¬±£´æÔÚ±äÁ¿ FilePathÖС£

SuiteOneCaseOneTest()£ºÕâ¸öÊDzâÊÔ·½·¨£¬¸½´ø@Test±êÇ©£¬²¢Ê¹ÓÃdataProvider À´»ñÈ¡Êý¾Ý

SuiteOneCaseOneData()£º´Ó.xlsÎļþ¶ÁÈ¡Êý¾Ý²¢·µ»Ø¸øSuiteOneCaseOneTest()·½·¨

package com.stta.SuiteOne;
import java.io.IOException;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.stta.utility.Read_XLS;
import com.stta.utility.SuiteUtility;

//SuiteOneCaseOne Àà ¼Ì³Ð×Ô SuiteOneBase Àà.
public class SuiteOneCaseOne extends SuiteOneBase{
Read_XLS FilePath = null;
String TestCaseName = null;

@BeforeTest
public void checkCaseToRun() throws IOException{
//µ÷ÓÃSuiteBaseÀàµÄinit()À´³õʼ»¯.xlsÎļþ
init();
FilePath = TestCaseListExcelOne;
System.out.println("FilePath Is : "+FilePath);
TestCaseName = this.getClass().getSimpleName();
System.out.println("TestCaseName Is : "+TestCaseName);
}

//ÔÚÿ¸öµü´úÖнÓÊÕ4ÁеÄÊý¾Ý.
@Test(dataProvider="SuiteOneCaseOneData")
public void SuiteOneCaseOneTest(String DataCol1,String DataCol2,String DataCol3,String ExpectedResult){
System.out.println("Value Of DataCol1 = "+DataCol1);
System.out.println("Value Of DataCol2 = "+DataCol2);
System.out.println("Value Of DataCol3 = "+DataCol3);
System.out.println("Value Of ExpectedResult = "+ExpectedResult);
}

//data provider»ØÔÚÿ¸öµü´úÖÐÒ»¸öÒ»¸ö·µ»Ø4ÁÐÊý¾Ý
@DataProvider
public Object[][] SuiteOneCaseOneData(){
//To retrieve data from Data 1 Column,Data 2 Column,Data 3 Column and Expected Result column of SuiteOneCaseOne data Sheet.
//Last two columns (DataToRun and Pass/Fail/Skip) are Ignored programatically when reading test data.
return SuiteUtility.GetTestDataUtility(FilePath, TestCaseName);
}
}

ÔËÐÐÊý¾Ý¶ÁÈ¡²âÊÔ

µ½´ËΪֹ£¬ÎÒÃǼòµ¥µÄÊý¾Ý¶ÁÈ¡²âÊÔÒѾ­×¼±¸Íê±Ï£¬¿ÉÒÔÊÔÔËÐÐÒ»ÏÂÈ·±£Ã»ÎÊÌ⣬ÔÙ¼ÌÐøÍùÏ¡£ÔÚSuiteOneCaseOne.javaÎļþµã»÷ÓÒ¼üÑ¡Ôñ Run As -> TestNG ¡£Èç¹ûÄãÊǰ´ÕÕǰÊöµÄ²½ÖèÒ»²½Ò»²½À´µÄ»°£¬²âÊÔÔËÐÐʱûÎÊÌâµÄ¡£ÒòΪSuiteOneCaseOneÊý¾ÝsheetÀïÓÐÁ½ÐÐÊý¾Ý£¬ËùÒÔ@Test½«»á±»Ö´ÐÐÁ½´Î¡£Ö´ÐÐÍ꣬¾Í¿ÉÒÔÔÚ¿ØÖÆÌ¨¿´µ½ÈçÏÂÐÅÏ¢£º

Èç¹ûÄã¿´µ½ÉÏÊöÏûÏ¢£¬ËµÃ÷µ½Ä¿Ç°ÎªÖ¹ÎÒÃǴµÄ»ùÓÚÊý¾ÝÇý¶¯µÄ×Ô¶¯»¯ÊÇ¿ò¼ÜÔÝʱÊÇûÓÐÎÊÌâµÄ£¬ÒѾ­¿ÉÒԳɹ¦¼òµ¥µÄÊý¾Ý¶ÁÈë²âÊÔ¡£

 
   
4276 ´Îä¯ÀÀ       31
Ïà¹ØÎÄÕÂ

΢·þÎñ²âÊÔÖ®µ¥Ôª²âÊÔ
һƪͼÎÄ´øÄãÁ˽â°×ºÐ²âÊÔÓÃÀýÉè¼Æ·½·¨
È«ÃæµÄÖÊÁ¿±£ÕÏÌåϵ֮»Ø¹é²âÊÔ²ßÂÔ
È˹¤ÖÇÄÜ×Ô¶¯»¯²âÊÔ̽Ë÷
Ïà¹ØÎĵµ

×Ô¶¯»¯½Ó¿Ú²âÊÔʵ¼ù֮·
jenkins³ÖÐø¼¯³É²âÊÔ
ÐÔÄܲâÊÔÕï¶Ï·ÖÎöÓëÓÅ»¯
ÐÔÄܲâÊÔʵÀý
Ïà¹Ø¿Î³Ì

³ÖÐø¼¯³É²âÊÔ×î¼Ñʵ¼ù
×Ô¶¯»¯²âÊÔÌåϵ½¨ÉèÓë×î¼Ñʵ¼ù
²âÊԼܹ¹µÄ¹¹½¨ÓëÓ¦ÓÃʵ¼ù
DevOpsʱ´úµÄ²âÊÔ¼¼ÊõÓë×î¼Ñʵ¼ù