how run cucumber with jenkins
이 자습서에서는 Cucumber Jenkins 통합을 설명하기 위해 Jenkins 및 Excel 시트가 포함 된 Cucumber의 전체 개요를 제공합니다. :
이 튜토리얼에서는 Jenkins 및 Excel 시트를 사용하여 Cucumber에 대해 설명합니다. 이 튜토리얼이 도움이되기를 바랍니다.
학습 내용 :
젠킨스와 오이
테스트 스크립트 자동화
다음 구성을 수행해야합니다.
기능 파일
특색:
사용자로서
시스템에 새 클라이언트를 추가하고 싶습니다.
그 클라이언트에 대한 회계 데이터를 추가 할 수 있습니다.
배경:
Github 홈페이지에 있습니다.
사용자 이름을 'xxxxxxxxxx'로 지정하고 암호를 'xxxxxxx'로 지정한 경우.
그리고 로그인 버튼을 클릭하십시오.
@연기
대본: 프로필 편집.
귀하의 프로필 옵션을 클릭하면.
프로필 편집 버튼을 클릭하면
그리고 새 사진을 업로드했습니다.
그러면 새 프로필 사진이 보여야합니다.
@Regression @ 매번
대본: 새로운 요점을 만듭니다.
귀하의 요점 옵션을 클릭하면.
파일 이름, 설명을 제공 할 때.
그리고 Create public gist method를 클릭합니다.
그렇다면 나는 새로운 요지를 봐야한다.
Stepdef 파일
xbox 360 용 가상 현실 고글
package com.Multi; import cucumber.api.PendingException; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; import cucumber.api.java.After; import cucumber.api.java.Before; import cucumber.api.java.en.But; import java.util.List; import cucumber.api.PendingException; import cucumber.api.java.it.Data; import cucumber.runtime.ScenarioImpl; import gherkin.formatter.model.Scenario; import gherkin.formatter.model.ScenarioOutline; import cucumber.api.DataTable; import org.junit.Assert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; import cucumber.api.cli.Main; public class Step2 { static public String sb; static public String sa; static WebDriver driver = null; @Before('@Smoke,@Regression') public void beforeScenario(){ System.out.println('New scenrio begins'); } @After('@Smoke,@Regression') public void afterScenario(){ System.out.println('Scenrio ends'); } @MyAnnotation public static void myanno() { System.out.println('my annot gets executed'); } @Given('^I am on Github home page$') public void i_am_on_Github_home_page(){ String site = 'https://www.github.com/login'; System.setProperty('webdriver.chrome.driver', 'Executables\chromedriver.exe'); driver = new ChromeDriver(); driver.navigate().to(site); //driver.findElement(By.cssSelector('a[contains[@href, 'login']]').click(); // Write code here that turns the phrase above into concrete actions } @When('^I specify Username as '([^']*)' and Password as '([^']*)'$') public void i_specify_Username_as_and_Password_as(String arg1, String arg2){ driver.findElement(By.cssSelector('input#login_field')).sendKeys(arg1); driver.findElement(By.cssSelector('input#password')).sendKeys(arg2); // Write code here that turns the phrase above into concrete actions } @When('^Click on SignIn button$') public void click_on_SignIn_button(){ driver.findElement(By.cssSelector('input.btn')).click(); // Write code here that turns the phrase above into concrete actions } @Given('^I click on Your Profile option$') public void i_click_on_Your_Profile_option(){ driver.findElement(By.xpath('//*[@id='user- links']/li[3]/details/summary/img')).click(); List olist = driver.findElements(By.xpath('//*[@id='user- links']/li[3]/details/ul/li/a[@class='dropdown-item']')); for(WebElement o:olist) { if(o.getText().equals('Your profile')) { o.click(); break; } } // Write code here that turns the phrase above into concrete actions } @When('^I click on edit profile button$') public void i_click_on_edit_profile_button(){ driver.findElement(By.xpath('//*[@id='js-pjax- container']/div/div[2]/div[1]/a')).click(); // Write code here that turns the phrase above into concrete actions } @When('^Uploaded new picture$') public void uploaded_new_picture() throws InterruptedException{ WebElement s1 = driver.findElement(By.xpath('//*[@class='avatar-upload- container clearfix']/Img')); sb=s1.getAttribute('src'); System.out.println(s1.getAttribute('src')); driver.findElement(By.id('upload-profile- picture')).sendKeys('D://cucumberFinal//multiple//Files//images.jpg'); Thread.sleep(10000); String wh = driver.getWindowHandle(); driver.switchTo().window(wh); Actions actions = new Actions(driver); WebElement element = driver.findElement(By.xpath('//div[@class='facebox -content']/form/div[3]/button')); Thread.sleep(10000); actions.moveToElement(element); //Thread.sleep(10000); actions.click(); //actions.sendKeys('GIST1 Description'); actions.build().perform(); // driver.findElement(By.xpath('//div[@class='facebox- content']/form/div[3]/button')).click(); Thread.sleep(3000); // Write code here that turns the phrase above into concrete actions } @Then('^I should be seeing new profile picture$') public void i_should_be_seeing_new_profile_picture(){ WebElement s1 = driver.findElement(By.xpath('//*[@class='avatar-upload- container clearfix']/Img')); sb=s1.getAttribute('src'); System.out.println(s1.getAttribute('src')); if(!(sb.equals(sa))) { Assert.assertTrue('File Upload successful', true); } // Write code here that turns the phrase above into concrete actions } @Given('^I click on Your Gists option$') public void i_click_on_Your_Gists_option(){ driver.findElement(By.xpath('//*[@id='user- links']/li[3]/details/summary/img')).click(); List olist = driver.findElements(By.xpath('//*[@id='user- links']/li[3]/details/ul/li/a[@class='dropdown-item']')); for(WebElement o:olist) { if(o.getText().equals('Your Gists')) { o.click(); break; } } // Write code here that turns the phrase above into concrete actions } @When('^I provide filename, description$') public void i_provide_filename_description() throws InterruptedException { // Write code here that turns the phrase above into concrete actions driver.findElement(By.xpath('//div[@class='edit container']/div[@id='gists']/input')).sendKeys('Gist1'); Thread.sleep(2000); Actions actions = new Actions(driver); WebElement element = driver.findElement(By.xpath('//*[@id='gists']/div[2]/div/div[2]/div/div[5]/div[1] /div/div/div/div[5]/div/pre/span')); actions.moveToElement(element); actions.click(); actions.sendKeys('GIST1 Description'); actions.build().perform(); // driver.findElement(By.xpath('//*[@id='gists']/div[2]/div/div[2]/div/div[5]/div[1] /div/div/div/div[5]/div/pre/span')).sendKeys('GIST1 Description'); Thread.sleep(2000); } @When('^click on Create public gist method$') public void click_on_Create_public_gist_method() { driver.findElement(By.xpath('//*[@id='new_gist']/div[2]/div[2]/button[1]')).click(); // Write code here that turns the phrase above into concrete actions } @Then('^i should be seeing the new gist$') public void i_should_be_seeing_the_new_gist(){ List glist = driver.findElements(By.xpath('//div[@class='container repohead-details -container']/ul[1]/li[@class='flex-auto']/div/a')); for(WebElement o:glist) { if(o.getText().equals('Gist1')) { System.out.println('Gist created successfully'); } } // Write code here that turns the phrase above into concrete actions } }
TestNG 파일
러너 파일
package runner; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import cucumber.api.testng.AbstractTestNGCucumberTests; import cucumber.api.SnippetType; @RunWith(Cucumber.class) @CucumberOptions( features='Features', glue='com.Multi', plugin={'html:target/cucumber-html-report', 'json:target/cucumber.json', 'pretty:target/cucumber-pretty.txt','usage:target/cucumber-usage.json', 'junit:target/cucumber-results.xml'}, dryRun = false, strict = true, tags={'@Smoke,@Regression'}, monochrome = true, snippets=SnippetType.CAMELCASE ) public class Runner extends AbstractTestNGCucumberTests{ }
Jenkins 구성
접속하다 Jenkins URL .
이동 Jenkins 관리> 플러그인 관리 .
다음 플러그인을 설치하십시오.
- 오이 테스트 결과 플러그인
- 오이 보고서
- Cucumber perf 플러그인
모든 종속 플러그인을 설치하는 동안 성공적으로 설치되었는지 확인하십시오. 그렇지 않으면보고 플러그인이 작동하지 않을 수 있습니다.
이제 다음으로 이동 관리-> 글로벌 도구 구성.
설정 JDK의 경로.
설정 Maven의 경로.
만들기 새로운 물품 Maven 프로젝트로.
작업이 생성되면 왼쪽 패널에있는 구성 링크를 클릭합니다.
아래로 스크롤 그 페이지.
mysql 대 SQL 서버 대 오라클
pom.xml의 전체 경로, 목표를 'test'로 설정하고 저장 구성.
위의 단계가 완료되면 지금 구축 Maven 프로젝트의 왼쪽 패널에있는 링크입니다.
빌드가 실행되고 해당 testing.xml 파일 (pom.xml에서 언급 됨)이 실행됩니다.
다음은 콘솔에 표시되는 출력입니다.
콘솔 출력
[정보] T E S T S
[정보] ——————————————————-
[정보] TestSuite 실행
새로운 시나리오 시작
27348 포트에서 ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) 시작
로컬 연결 만 허용됩니다.
log4j : WARN 로거에 대한 추가자를 찾을 수 없습니다.
(org.apache.http.client.protocol.RequestAddCookies).
log4j : WARN log4j 시스템을 올바르게 초기화하십시오.
log4j : WARN 자세한 내용은 http://logging.apache.org/log4j/1.2/faq.html#noconfig를 참조하십시오.
2017 년 11 월 25 일 오후 12:56:41 org.openqa.selenium.remote.ProtocolHandshake createSession
정보 : 감지 된 방언 : OSS
https://avatars3.githubusercontent.com/u/31874017?s=400&u=c41bfae0fa6b9325fb4f209885b51bd02c7d897d&v=4
https://avatars3.githubusercontent.com/u/31874017?s=400&u=c41bfae0fa6b9325fb4f209885b51bd02c7d897d&v=4
시나리오 종료
새로운 시나리오 시작
포트 24866에서 ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) 시작
로컬 연결 만 허용됩니다.
2017 년 11 월 25 일 오후 12:57:45 org.openqa.selenium.remote.ProtocolHandshake createSession
정보 : 감지 된 방언 : OSS
시나리오 종료
시나리오 2 개 (2 개 통과)
14 단계 (14 개 통과)
2 : 2.677
최고의 드라이버 업데이트 프로그램은 무엇입니까
[정보] 테스트 실행 : 1, 실패 : 0, 오류 : 0, 건너 뜀 : 0, 경과 시간 : 128.513 초 – TestSuite에서
[정보]
[정보] 결과 :
[정보]
[정보] 테스트 실행 : 1, 실패 : 0, 오류 : 0, 건너 뛰기 : 0
[정보]
[JENKINS] 테스트 결과 기록
[정보] ————————————————————————
[정보] 빌드 성공
[정보] ————————————————————————
[정보] 총 시간 : 02:51 분
[정보] 종료일 : 2017-11-25T12 : 58 : 45 + 05 : 30
[정보] 최종 메모리 : 12M / 28M
[정보] ————————————————————————
Jenkins가 데이터 수집을 완료하기를 기다리는 중
[JENKINS] D : cucumberFinal multiple pom.xml을 com / cucumber.example / 0.0.1-SNAPSHOT / cucumber.example-0.0.1-SNAPSHOT.pom에 보관
채널이 중지되었습니다.
완료 : 성공
오이 젠킨스 보고서
오이 엑셀
테스트 스크립트 자동화
다음 구성을 수행해야합니다.
테스트 설계 전략 :
- Excel 시트의 '열 이름'을 입력 매개 변수로 사용하고 그 대가로 해당 '열'에 대한 Excel 시트의 '열 값'을 제공하는 Excel 리더 유틸리티를 만듭니다.
- 모든 단계에서 큰 따옴표로 지정된 Excel 시트의 열 이름이있는 기능 파일을 만듭니다.
- 이제 기능 파일에 해당하는 Stepdef 파일을 만들고 매개 변수 (기능 파일 위에 큰 따옴표로 단어를 지정한 경우 생성 된 매개 변수 (arg1, arg2 등)를 엑셀 리더 (1 단계에서 생성됨)의 입력으로 사용합니다.
- 이제 Stepdef 파일에 대한 입력으로 사용할 수있는 Excel 시트의 열 값이 있습니다.
- 위 단계에서 생성 한 기능 파일을 실행합니다.
기능 파일
특색: 기능 제목
이 템플릿을 내 기능 파일에 사용하고 싶습니다.
배경:
내가 Gmail에 있고 화면 '화면'에 액세스하는 경우.
사용자 이름을 '사용자 이름'으로 지정하고 암호를 '암호'로 지정합니다.
로그인 버튼을 클릭하십시오.
대본: 데이터 테이블에서 새 메시지 만들기
팝업 '팝업'에 액세스 할 때.
그리고 'To'로 지정하고 제목을 'Subject'세부 사항으로 지정하고 제출 버튼을 클릭합니다.
그러면 성공 메시지를 보게 될 것입니다.
엑셀 파일
package com.cuexcel; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import com.google.common.collect.Maps; import gherkin.formatter.model.Row; public class Excel { private static String sheet = 'Sheet1'; private static String worksheet = 'D:\cucumberFinal\cuexcel\Files\tdata.xls'; static HashMap excelinfo = new HashMap(); public static String get(String ColName) throws IOException { FileInputStream fis; int k =0; String ColValue=null; fis = new FileInputStream(worksheet); HSSFWorkbook wb = new HSSFWorkbook(fis); HSSFSheet ws = wb.getSheet(sheet); int rows = ws.getPhysicalNumberOfRows(); HSSFRow HeaderRow = ws.getRow(0); for(Integer i=1;i Stepdef 파일
package com.cuexcel; import java.io.IOException; import java.util.ArrayList; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import cucumber.api.Scenario; import cucumber.api.java.Before; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; import cucumber.api.Scenario; import com.cuexcel.Excel; public class CExcel { static public WebDriver driver; Excel e; @Before public static void callexcel() throws IOException, InterruptedException { System.setProperty('webdriver.chrome.driver', 'Executables/chromedriver.exe'); driver= new ChromeDriver(); driver.manage().window().maximize(); driver.navigate().to('https://www.google.com/gmail/about'); } @Given('^I am on Gmail and accessing screen '([^']*)'$') public void i_am_on_Gmail_and_accessing_screen(String arg1) throws Throwable { // Write code here that turns the phrase above into concrete actions driver.findElement(By.xpath('//nav/div/a[2]')).click(); //arg1=Excel.get().get(0).toString(); System.out.println(e.get(arg1) + ' - is clicked'); Thread.sleep(3000); } @Given('^I specify Username as '([^']*)' and Password as '([^']*)'$') public void i_specify_Username_as_and_Password_as(String arg1, String arg2) throws Throwable { //arg1=Excel.get().get(1).toString(); //arg2=Excel.get().get(2).toString(); driver.findElement(By.xpath('//input[@type='email']')).sendKeys(e.get(arg1). toString()); driver.findElement(By.xpath('//*[@id='identifierNext']/content/span')).click(); Thread.sleep(3000); driver.findElement(By.xpath('//input[@type='password']')). sendKeys (e.get(arg2). toString()); } @When('^Click on SignIn button$') public void click_on_SignIn_button() throws InterruptedException{ driver.findElement(By.xpath('//*[@id='passwordNext']/content/span')).click(); Thread.sleep(5000); } @When('^I am accessing the popup '([^']*)'$') public void i_am_accessing_the_popup(String arg1) throws Throwable { // Write code here that turns the phrase above into concrete actions //arg1=Excel.get().get(3).toString(); driver.findElement(By.xpath('//*[@id=':x4']/div/div')).click(); System.out.println(e.get(arg1) + '- being clicked'); } @When('^I specify to as '([^']*)' and subject as '([^']*)' details and click on submit button$') public void i_specify_to_as_and_subject_as_details_and_click_on_submit_button(String arg1, String arg2) throws Throwable { // Write code here that turns the phrase above into concrete actions String whandle = driver.getWindowHandle(); driver.switchTo().window(whandle); //arg1=Excel.get().get(4).toString(); //arg2=Excel.get().get(5).toString(); driver.findElement(By.xpath('//td[@class='eV']/div[1]/div/textarea')).sendKeys (e.get(arg1)); driver.findElement(By.xpath('//table[@class='aoP aoC bvf']/tbody/tr/td/form/div[3]/input')).sendKeys(e.get(arg2)); driver.findElement(By.xpath('//table[@class='IZ']/tbody/tr/td/div')).click(); Thread.sleep(3000); } @Then('^i should be seeing the success message$') public void i_should_be_seeing_the_success_message() throws Throwable { // Write code here that turns the phrase above into concrete actions WebElement sent = driver.findElement(By.xpath('//*[@id='link_vsm']')); if(sent.isDisplayed()) { System.out.println('Message sent successfully'); } } }
POM 파일
4.0.0 com cuexcel 0.0.1-SNAPSHOT jar cuexcel http://maven.apache.org UTF-8 org.seleniumhq.selenium selenium-java 3.6.0 org.seleniumhq.selenium selenium-chrome-driver 3.6.0 info.cukes cucumber-core 1.2.5 info.cukes cucumber-java 1.2.5 test info.cukes cucumber-junit 1.2.5 test junit junit 4.11 test info.cukes cucumber-testng 1.2.0 info.cukes gherkin 2.12.2 provided log4j log4j 1.2.17 org.apache.poi poi-ooxml 3.9 org.apache.poi poi 3.11-beta3 xml-apis xml-apis 2.0.2 xerces xercesImpl 2.8.0 info.cukes cucumber-jvm-deps 1.0.5 provided net.masterthought cucumber-reporting 3.11.0 org.apache.maven.plugins maven-surefire-plugin 2.18 org.apache.maven.surefire surefire-junit47 2.18
위의 구성이 완료되면 기능 파일을 실행하기 만하면됩니다.
관측
Stepdef 파일은 Excel 시트에서 데이터를 가져와 기능 파일에 언급 된 테스트 단계를 실행합니다.
다음은 Eclipse 콘솔에서 언급 한 테스트 케이스 실행 결과입니다.
결론
BDD는 모든 이해 관계자가 테스트 스크립트 생성에 참여할 수있게하므로 특히 기능 파일에 대한 입력을 제공 할 수 있으므로 테스트 자동화의 미래입니다.
Cucumber는 널리 사용되는 BDD 도구이며 아직 테스트 자동화에 구현되지 않은 많은 통합 및 기능이 있습니다. Cucumber에 적극적으로 참여하는 여러 그룹 / 커뮤니티가 있습니다.
Cucumber에 정통한 경우 대부분의 도구가 Cucumber와 유사하게 작동하므로 시장에서 사용 가능한 모든 BDD 도구에서 작업 할 수 있습니다.
이 심층 자습서를 통해 Jenkins와 함께 Cucumber에 대해 배웠기를 바랍니다.
추천 도서