how run cucumber with jenkins
Bu Öğretici, Cucumber Jenkins Entegrasyonunu Açıklamak için Jenkins ve Excel ile Salatalığa Genel Bir Bakış :
Bu eğitimde, Hıyar'ı Jenkins ve Excel sayfasıyla tartışacağız. Bu eğitimin size yardımcı olacağını umuyoruz.
Ne öğreneceksin:
- Jenkins ile Salatalık
- Jenkins Yapılandırması
- Salatalık Jenkins Raporu
- Salatalık Excel
- Gözlem
- Sonuç
- Önerilen Kaynaklar
Jenkins ile Salatalık
Test Komut Dosyası Otomasyonu
Aşağıdaki konfigürasyonun yapılması gerekiyor.
Özellik dosyası
Özellik:
Bir kullanıcı olarak
Sisteme yeni müşteriler ekleyebilmek istiyorum.
Böylece o müşteri için muhasebe verilerini ekleyebilirim.
Arka fon:
Github ana sayfasındayım.
Kullanıcı adını 'xxxxxxxxxx' ve Parolayı 'xxxxxxx' olarak belirttiğimde.
Ve Oturum Aç düğmesine tıklayın.
@Sigara içmek
Senaryo: Profilin düzenlenmesi.
Profilinize tıkladığım için.
Profili düzenle düğmesine tıkladığımda.
Ve yeni bir resim yükledi.
O halde yeni profil resmi görmeliyim.
@Everytime @egresyon
Senaryo: Yeni özet oluşturun.
Sizin Gists seçeneğine tıkladığım için.
Dosya adını verdiğimde, açıklama.
Ve Genel hedef yöntemi oluştur'a tıklayın.
O zaman yeni özü görmeliyim.
Stepdef dosyası
ba mülakat soruları ve cevapları pdf
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 dosyası
Runner Dosyası
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 Yapılandırması
Giriş Jenkins URL'si .
Git Jenkins'i Yönet> Eklentiyi Yönet .
Aşağıdaki eklentileri kurun:
- Salatalık Test Sonuçları eklentisi
- Salatalık Raporları
- Cucumber perf eklentisi
Tüm bağımlı eklentilerin başarıyla kurulduğundan emin olun, aksi takdirde raporlama eklentileri çalışmayabilir.
Şimdi gidin Yönet -> Global Araç Yapılandırması.
Yı kur JDK yolu.
Yı kur Maven için yol.
Oluşturmak yeni öğe Maven Projesi olarak.
İş oluşturulduktan sonra, sol taraftaki panelde bulunan yapılandırma bağlantısına tıklayın.
Aşağı kaydır sayfa.
yeni başlayanlar için bilgisayarlar nasıl programlanır
Pom.xml'nin tam yolunu, hedefi 'test' olarak ayarlayın ve kayıt etmek yapılandırma.
Yukarıdaki adımlar tamamlandıktan sonra, Şimdi İnşa Edin Maven Projesi'nin sol tarafındaki panelde bulunan bağlantı.
Yapı yürütülecek ve karşılık gelen test.xml dosyası (pom.xml üzerinde belirtilen) çalıştırılacaktır.
Konsolda görüntülenen çıktı burada.
Konsol Çıkışı
(BİLGİ) T E S T S
(BİLGİ) ——————————————————-
(INFO) TestSuite Çalıştırılıyor
Yeni senaryo başlıyor
27348 numaralı bağlantı noktasından ChromeDriver 2.33.506120'yi (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) başlatma
Yalnızca yerel bağlantılara izin verilir.
log4j: WARN Logger için ek bulunamadı
(org.apache.http.client.protocol.RequestAddCookies).
log4j: WARN Lütfen log4j sistemini doğru şekilde başlatın.
log4j: WARN Daha fazla bilgi için http://logging.apache.org/log4j/1.2/faq.html#noconfig adresine bakın.
25 Kasım 2017 12:56:41 org.openqa.selenium.remote.ProtocolHandshake createSession
BİLGİ: Algılanan lehçe: 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
Senaryo biter
Yeni senaryo başlıyor
ChromeDriver 2.33.506120'yi (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) 24866 numaralı bağlantı noktasından başlatma
Yalnızca yerel bağlantılara izin verilir.
25 Kasım 2017 12:57:45 org.openqa.selenium.remote.ProtocolHandshake createSession
BİLGİ: Algılanan lehçe: OSS
Senaryo biter
2 Senaryo (2 başarılı)
14 Adım (14 geçti)
2m2.677s
Windows 10'da .jar dosyaları nasıl açılır
(BİLGİ) Çalıştırılan testler: 1, Başarısızlıklar: 0, Hatalar: 0, Atlanan: 0, Geçen süre: 128,513 sn - TestSuite'te
(BİLGİ)
(INFO) Sonuçlar:
(BİLGİ)
(BİLGİ) Çalıştırılan testler: 1, Başarısızlıklar: 0, Hatalar: 0, Atlanan: 0
(BİLGİ)
(JENKINS) Test sonuçlarını kaydetme
(BİLGİ) ———————————————————————
(BİLGİ) BAŞARI OLUŞTURUN
(BİLGİ) ———————————————————————
(BİLGİ) Toplam süre: 02:51 dk
(BİLGİ) Bitiş: 2017-11-25T12: 58: 45 + 05: 30
(BİLGİ) Nihai Bellek: 12M / 28M
(BİLGİ) ———————————————————————
Jenkins'in veri toplamayı bitirmesi bekleniyor
(JENKINS) D: cucumberFinal multiple pom.xml dosyasını com / cucumber.example / 0.0.1-SNAPSHOT / cucumber.example-0.0.1-SNAPSHOT.pom olarak arşivliyor
kanal durdu
Tamamlandı: BAŞARI
Salatalık Jenkins Raporu
Salatalık Excel
Test Komut Dosyası Otomasyonu
Aşağıdaki konfigürasyonun yapılması gerekiyor.
Test Tasarım Stratejisi:
- Girdi parametresi olarak bir Excel sayfasının 'sütun adını' alma yeteneğine sahip olan ve karşılığında, bu 'sütun biçimi' için Excel sayfasının 'sütun değerini' veren bir excel okuyucu yardımcı programı oluşturun.
- Excel sayfasının sütun adının herhangi bir adımında çift tırnak içinde belirtildiği bir özellik dosyası oluşturun.
- Şimdi, özellik dosyası için karşılık gelen bir Stepdef dosyası oluşturun ve parametreleri (arg1, arg2 vb., Kelimeyi özellik dosyası üzerinde çift tırnak içinde belirlediysek oluşturulan) excel okuyucu (1. adımda oluşturulmuş) için girdi olarak kullanın.
- Artık, Stepdef dosyasına girdi olarak kullanılabilecek excel sayfasının sütun değerine sahibiz.
- Unsur dosyasını yukarıdaki adımda oluşturulan şekilde çalıştırın.
Özellik dosyası
Özellik: Özelliğinizin başlığı
Özellik dosyam için bu şablonu kullanmak istiyorum
Arka fon:
Gmail’de olduğum ve 'ekrana' eriştiğim için.
Kullanıcı adını 'Kullanıcı Adı' ve Parolayı 'Şifre' olarak belirledim.
SignIn düğmesine tıklayın.
Senaryo: Veri tablosundan yeni mesaj oluştur
Açılır 'açılır pencereye' eriştiğimde.
Ben de 'Kime' ve konuyu 'Konu' ayrıntıları olarak belirleyip gönder butonuna tıklıyorum.
O zaman başarı mesajını görmeliyim.
Excel dosyası
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 dosyası
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 dosyası
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
Yukarıdaki yapılandırma tamamlandığında, sadece özellik dosyasını çalıştırın.
Gözlem
Stepdef dosyası, verileri excel sayfasından alır ve özellik dosyasında belirtilen test adımlarını yürütür.
İşte Eclipse konsolunda belirtildiği gibi test durumu yürütme sonucu.

Sonuç
BDD, tüm paydaşların, özellikle de Özellik dosyası üzerinden girdilerini sağlamak için Test Komut Dosyası oluşturmaya katılmalarını sağladığı için test otomasyonunun geleceğidir.
Salatalık, yaygın olarak kullanılan bir BDD aracıdır ve test otomasyonunda henüz uygulanmamış birçok entegrasyon ve özelliğe sahiptir. Hıyar üzerinde aktif olarak çalışan birkaç grup / topluluk var.
Cucumber konusunda bilgiliyseniz, aletlerin çoğu Cucumber ile benzer şekilde çalıştığı için piyasada bulunan herhangi bir BDD aleti üzerinde çalışabilirsiniz.
Bu ayrıntılı eğitim aracılığıyla Jenkins ile Cucumber hakkında bilgi sahibi olduğunuzu umuyoruz.
Önerilen Kaynaklar
- Örneklerle Python DateTime Eğitimi
- Salatalık Selenium Eğitimi: Salatalık Java Selenium WebDriver Entegrasyonu
- Örneklerle Unix Shell Komut Dosyası Oluşturma Eğitimi
- Selenyum Örneklerle Metin Öğreticisine Göre Eleman Bul
- Java 'bu' Anahtar Kelime: Kod Örnekleriyle Eğitim
- Örneklerle BDD ve Salatalık Eğitimi
- Kod Örnekleriyle C # İstisna İşleme Eğitimi
- Salatalık Aracı ve Selenyum Kullanarak Otomasyon Testi - Selenyum Eğitimi # 30