bdd cucumber tutorial with examples
この詳細なキュウリのチュートリアルでは、BDDとその利点、キュウリのフレームワーク、環境設定、テストスクリプトの作成、キュウリの機能、レポートなどについて説明します。
キュウリは非常に人気があり、今ではソフトウェアテスト業界で広く使用されています。
前提条件 –対象となる受信者は、スクラム、Maven、TestNGなどの知識を持っている必要があります。
学習内容:
- BDDの背景
- ビヘイビア駆動開発(BDD)の利点
- BDDツール
- なぜキュウリ?
- きゅうりはどのように機能しますか?
- 環境設定
- きゅうりを使ったテストケースの作成
- きゅうりのファイルを作成する
- きゅうりの特徴
- キュウリを使ったTestNG
- 結論
- 推奨読書
BDDの背景
アジャイル手法のTDDフレームワークでは、通常、最初にテストケースを作成してから、それらを実行します。これは、テストカバレッジを達成し、ビルドが本番環境の準備ができていることを確認するのに適しています。
ただし、動作や機能などをテストに導入して実行することで、TDDフレームワークを拡張できます。このTDDの機能強化は、BDD(Behavior Driven Development)と呼ばれます。
ビヘイビア駆動開発(BDD)の利点
BDDを使用する利点は次のとおりです。
#1) 共通のプラットフォームを通じて、ビジネスの利害関係者と技術チームの間のギャップを埋めます。したがって、チーム間のコミュニケーションはより透明になります。
#二) シナリオは、クライアント側の人、ビジネスチームのメンバー、経営陣など、誰でも作成できます。したがって、要件、シナリオがカバーされています。
#3) 開発者は、理解したとおりにコードを記述/開発するのではなく、BDDフレームワークで記述されたシナリオに準拠したコードを記述します。
#4) テストがよりシャープになり、テストの作成とその後の実行に費やされる時間が節約されます。特にビジネスに影響を与える可能性のある重大な欠陥は、フロントエンド自体にあります。
#5) BDDに関連するコード、ドキュメントは、ドキュメントとそれに対応するコードがすでに関連しているため、コードを維持するために他の努力が必要ないため、簡単に理解でき、保守できます。したがって、ドキュメントに記載されているもの、つまりシナリオには、対応するコードがあります。
#6) 非常にわかりやすいシナリオがあるため、論理的な方法でタスクやサブタスクなどに簡単に分割できます。
# 7) シナリオ、受け入れ基準、およびほぼ正確なテスト見積もりについて事前に明確になっているため、チームはよりダイナミックで機敏になります。
#8) ドキュメントとコードの両方の点で、その単純さのために、既存のチームと一緒にグルーミングするための新規参加者にとって非常に優れたプラットフォーム。
#9) シナリオ(主にUI、動作関連)の検証に役立つだけでなく、ユニットレベルのテストケースにも役立ちます。
#10) また、要件とシナリオが明確に定義されているため、チームの進捗状況を最初から追跡することも役立ちます(開発者がTDDで収集するのに通常苦労していること)。
したがって、BDDの実装により、「エンドクライアントはテストの重要性について考えていない」、「クライアントはテスト活動に関与したくない」などの前提がなくなります。
BDDツール
BDDアプローチの実装を可能にするいくつかのテストツールがあります。
といった:
- きゅうり
- SpecFlow
- Jbehave
- レタス
- コンコーディオン
- FitNesse
- BeanSpec
- イージーB
- Jdave
- Givwenzen-flex
- GivWenZen
- 本能
- タンブラーガラス
- Gospecify
- 壮観
- dSpec
- スペック
- ステーキ
- JSSpec
上記のツールの中で、JbehaveはCucumberと非常によく似ていますが、実装の点で少し異なります。
JBEHAVE | きゅうり |
---|---|
外部データソースをサポート | 外部データソースをサポートしていません |
ストーリーをサポート | 機能をサポート |
非常に優れたドキュメント | 標準のドキュメントはありません |
複合ステップをサポート | 複合ステップをサポートしていません |
それほど柔軟ではない | パラメータの受け渡しに柔軟性 |
背景をサポートしていません | 背景をサポート |
それほど広範囲なレポートではありません | 書式設定の柔軟性の向上、組み込みのレポート |
Javaを使用して開発 | Rubyを使用して開発 |
なぜキュウリ?
Cucumberは、あらゆる種類のテストケース、特にビヘイビア駆動開発スタイルで記述された受け入れレベルのテストケース(エンドユーザーがより懸念している)の記述に使用されます。 Gherkinなどの言語パーサーの使用をサポートします。
もともと、CucumberはRubyプログラミング言語を使用して作成され、Rubyテスト用に特別に開発されました。しかし現在、Javaなどの他のプログラミング言語でサポートされています。
Gherkinは、テストケースが単純な形式で記述され、技術者以外のユーザーでも読み取ったり変更したりできる言語として使用されています。
英語の他に、Cucumberは他の言語もサポートしています。
きゅうりはどのように機能しますか?
その動作メカニズムについては、まず、ユーザー(テクニカル/非テクニカル)にGherkin構文を使用して(機能として)目的のテストケースを記述させます。完了したら、ユーザーがにアクセスできるように承認されていることを確認する必要があります。次のレベル。
その後、機能ファイルに記載されているように、(stepdefファイルを使用して)各行にスクリプトを作成する必要があります。コードが実装されたら、次はスクリプトを実行します(ランナーファイルを使用)。
環境設定
Cucumberの環境設定は、Eclipseや他のIDEなどの他のツールを使用する場合に比べて少し複雑です。
課題
Cucumber jarのバージョンが、インストールされているJavaバージョン、および現在作業しているIDEと一致していることを確認する必要があります。
環境設定
#1)EclipseCucumberプラグイン :EclipseがGherkin構文を理解するのに役立ち、プレーンテキストではなく機能ファイルの構文を強調表示します。
私たちは行く必要があります Eclipse >>ヘルプ>>新しいソフトウェアのインストール>> (追加)ボタンをクリック>>場所を指定 なので この 。名前には「キュウリ」と表示されているので、(OK)をクリックして、残りのインストールプロセスに従います。
最後に、IDE、つまりEclipseを再起動します。
#二) 以下に説明するように、Mavenを使用して、すべてのjar(依存関係、プラグインなど)を取得します。
4.0.0 com cucumber.example 0.0.1-SNAPSHOT jar cucumber.example 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 org.apache.maven.plugins maven-surefire-plugin 2.18 org.apache.maven.surefire surefire-junit47 2.18
#3) Ctrl +を実行するか、Mavenインストールを実行するかを確認してください。
#4) その後、依存関係に関連するエラーを回避するためにMavenビルドを実行して、後で依存関係、プラグイン、バージョンの不一致エラーが発生しないようにしてください。
Javaでarrays.sortを使用する方法
#5) 上記の手順が完了すると、環境の準備が整います。
きゅうりを使ったテストケースの作成
Cucumberには、次の3つのファイルが含まれています。
- フィーチャーファイル: ここでは、テストする機能をGherkin形式で記述します。つまり、Given WhenThenです。機能ファイルを実行して、Stepdefファイルに記述されたテストスクリプトを実行することもできます。
- Stepdefファイル: 機能ファイルの準備ができたら、機能ファイルの各文をStepdefファイルにさらに実装できます。
- ランナーファイル: これは、機能ファイルを参照して、Stepdefファイルに書き込まれた実際のテストスクリプトを実行するためだけのものです。それとは別に、カスタマイズ、レポート、選択的実行などのための他の多くのオプションがあります。
これはランナーファイルの簡単な例です
package runner; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; @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, monochrome = true, tags={'@Smoke,@Regression'} ) public class Runner { }
きゅうりのファイルを作成する
- Stepdefファイル – Src / test / java >>新規>>その他>> Cucumber >> StepDefクラス。
- フィーチャーファイル –プロジェクト>>新規>>ファイル>>拡張子が「.feature」のファイルの名前を指定します。
- ランナーファイル –他のJavaクラスの作成と似ていますが、ここで何らかのメソッドを実装する必要がある場合があります。
きゅうりの特徴
これがCucumberの基本機能の一部であり、テストスクリプトで実装します。
#1)キュウリフック
これらは、各シナリオの前後に実行されるコードのブロックです。これにより、プロジェクトのどこでもこれらを定義できます。 例えば、 ステップ定義。
定義によると、これらは@Afterと@Beforeの2つのアノテーションにすぎません。コンソールでは、ブロックが実行され、明確な出力が得られていることがわかります。特定のタグのフックを実行することもできます。
#2)キュウリのタグ
これらは通常、機能ファイルで使用され、指定されたタグ名に従って機能ファイルでシナリオを分類します。機能ファイルには、特定のシナリオに対して複数のタグを含めることができます。
タグはユーザー定義であり、@ Smoke、@ Regressionなどの任意の名前を付けることができます。
#3)キュウリの注釈
これらはキュウリに組み込まれています。通常、タグは@ Given、@ When、@ Thenです。
ただし、後で必要になった場合は、独自の注釈を作成して、プログラムで使用できます。実行中に、一致するグルーコード、つまり関数が@ Given、@ When、@ Thenを持つStepdefファイルに書き込まれます。
#4)キュウリの背景
これらは、機能ファイル内のすべてのシナリオに共通するステップまたは一連のステップです。
これにより、定義されている機能のシナリオにコンテキストを追加できます。定義されている機能のすべてのシナリオの前に実行されます。
#5)キュウリのデータテーブル
Cucumberには、データ駆動型テストをサポートする機能があります。これにより、特定のスクリプトに対して異なる入力値と検証値を使用して、テストケースを複数回自動的に実行できます。
Cucumberはデータテーブルをサポートしています。最初の行は列と見なされ、その隣の行はスクリプトのデータです。
#6)キュウリの転置
これは、Cucumberデータテーブルのわずかな変更です。ここでは、最初の列が列と見なされ、次の列がスクリプトのデータと見なされます。
#7)キュウリのマルチシナリオ
Cucumberを使用すると、1つの機能ファイルで複数のシナリオのテストを実行できます。
#8)キュウリの報告
レポートやその他のサードパーティツールとは異なり、レポートを表示するためにいくつかの構成を行う必要があります。
ここCucumberには、pretty、JSON、HTML、XMLなどの組み込みプラグインがあり、テスト実行の包括的なレポートを提供します。
キュウリを使ったTestNG
TestNGを使用してCucumberで記述されたJUnitテストケースを引き続き実行できます 以下のように:
- Mavenプロジェクトに依存関係を追加する必要があります。
- RunnerクラスのクラスをAbstractTestNGCucumberTestsパッケージランナーとして拡張します。
- Mavenプロジェクトを変換し、パッケージを追加します(ランナークラスが存在する場合)。
その後、Cucumberテストケース全体をTestNGとして実行し、それに関連するレポートを生成できます(リスナーがある場合)。
このチュートリアルでは、上記の概念をカバーする3つの異なるキュウリの例について説明します。
例1
フック、タグ、注釈、背景、複数のシナリオ、およびCucumberを使用したTestNGについて説明します。
テスト環境がセットアップされたら:
- EclipseにEclipseCucumberプラグインを追加します。
- Mavenプロジェクトを作成し、それに必要なすべての依存関係を追加し、MavenにTestNG関連の依存関係も追加します。
- 新しいフィーチャファイルを作成します。
- それに必要な実装をStepdefファイルに追加します。
- 次に、extendsAbstractTestNGCucumberTestsを使用してランナーファイルを作成します。
- MavenプロジェクトをTestNGに変換し、testng.xmlにCucumberランナークラスのパッケージパスを追加します。
- TestNG.xmlファイルを実行します。
フィーチャーファイル
特徴:
ユーザーとして
システムに新しいクライアントを追加できるようにしたい
そのクライアントのアカウンティングデータを追加できるように
バックグラウンド:
私がGithubのホームページにいることを考えると
ユーザー名を「xxxxxxxxxxxxxxxxxxxx」、パスワードを「xxx」と指定した場合
そして、サインインボタンをクリックします
@煙
シナリオ: プロファイルの編集
あなたのプロフィールオプションをクリックすると、
プロファイルの編集ボタンをクリックすると
そしてアップロードされた新しい写真
その後、新しいプロフィール写真が表示されるはずです
@Regression @Everytime
シナリオ: 新しい要点を作成する
あなたの要点オプションをクリックすると、
ファイル名、説明を入力すると
そして、(パブリック要点メソッドの作成)をクリックします
それから私は新しい要点を見るべきです
Stepdefファイル
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 scenario begins'); } @After('@Smoke,@Regression') public void afterScenario(){ System.out.println('Scenario 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 } }
これがTestNGXMLのテスト結果です
デフォルトのTestNGレポートは、次のようになります。
例2
データテーブルと転置について説明します。
環境がセットアップされたら:
- EclipseにEclipseCucumberプラグインを追加します。
- Mavenプロジェクトを作成し、必要なすべての依存関係をプロジェクトに追加します。
- 新しいフィーチャファイルを作成します。
- それに必要な実装をstepdefファイルに追加します。
- ファイルを右クリックして機能ファイルから直接実行する>>実行>> Cucumber.feature
フィーチャーファイル
特徴: 機能のタイトル
このテンプレートを機能ファイルに使用したい
バックグラウンド:
Gmailのログインページを表示している場合
ユーザー名とパスワードを指定すると
そして、サインインボタンをクリックします
シナリオ: データテーブルから新しいメッセージを作成する
新しいメールページを表示しているとき
そして、私は以下の詳細を指定します
| To1 |件名|
| Person1@email.com | Person1件名|
| Person2@email.com | Person2件名|
シナリオ: 転置されたデータテーブルから新しいメッセージを作成する
新しいメールページを表示しているとき
そして、転置テーブルから以下の詳細を指定します
| To1 | Person1@email.com | Person2@email.com |
|件名| Person1件名| Person2件名|
Stepdefファイル
package com.datatable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.time.*; import org.openqa.selenium.By; import org.openqa.selenium.Keys; 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.DataTable; import cucumber.api.Transpose; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; import gherkin.formatter.model.Examples; import cucumber.runtime.CucumberException; import cucumber.runtime.ParameterInfo; import cucumber.runtime.xstream.LocalizedXStreams; public class Step3 { static public WebDriver driver; @Given('^I am on Gmail login page$') public void i_am_on_Gmail_login_page() throws InterruptedException{ System.setProperty('webdriver.chrome.driver', 'Executables/chromedriver.exe'); driver= new ChromeDriver(); Actions act = new Actions(driver); driver.manage().window().maximize(); driver.navigate().to('https://www.google.com/gmail/about'); driver.findElement(By.xpath('//nav/div/a(2)')).click(); Thread.sleep(3000); } @When('^I specify Username and Password$') public void i_specify_Username_and_Password() throws InterruptedException{ driver.findElement(By.xpath('//input(@type='email')')).sendKeys('xxxxxx@xxx. com'); driver.findElement(By.xpath('//*(@id='identifierNext')/content/span')).click(); Thread.sleep(3000); driver.findElement(By.xpath('//input(@type='password')')).sendKeys('xxxxxxxx xxx'); } @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 on New Email Page$') public void i_am_on_New_Email_Page(){ } @When('^I specify following details$') public void i_specify_following_details(DataTable tables)throws Throwable{ for (Map row : tables.asMaps(String.class, String.class)) { driver.findElement(By.xpath('//*(@id=':x4')/div/div')).click(); //driver.switchTo(). System.out.println(row.get('To1')); System.out.println(row.get('Subject')); String whandle = driver.getWindowHandle(); driver.switchTo().window(whandle); driver.findElement(By.xpath('//td(@class='eV')/div(1)/div/textarea')).sendKeys (row.get('To1')); driver.findElement(By.xpath('//table(@class='aoP aoC bvf')/tbody/tr/td/form/div(3)/input')).sendKeys(row.get('Subject')); driver.findElement(By.xpath('//table(@class='IZ')/tbody/tr/td/div')).click(); Thread.sleep(3000); } } @When('^I specify following details from transpose table$') public void i_specify_following_details_from_transpose_table(DataTable tables) throws InterruptedException { // DataTable tables = null; for (Map row : tables.transpose().asMaps(String.class, String.class)) { driver.findElement(By.xpath('//*(@id=':x4')/div/div')).click(); //driver.switchTo(). Thread.sleep(2000); System.out.println(row.get('To1')); System.out.println(row.get('Subject')); String whandle = driver.getWindowHandle(); driver.switchTo().window(whandle); driver.findElement(By.xpath('//td(@class='eV')/div(1)/div/textarea')).sendKeys (row.get('To1')); Thread.sleep(3000); driver.findElement(By.xpath('//table(@class='aoP aoC bvf')/tbody/tr/td/form/div(3)/input')).click(); driver.findElement(By.xpath('//table(@class='aoP aoC bvf')/tbody/tr/td/form/div(3)/input')).sendKeys(row.get('Subject')); Thread.sleep(3000); driver.findElement(By.xpath('//table(@class='IZ')/tbody/tr/td/div')).click(); Thread.sleep(3000); } } @When('^then click on Send button$') public void then_click_on_Send_button(){ // Write code here that turns the phrase above into concrete actions } @Then('^I should be able to send the email successfully$') public void i_should_be_able_to_send_the_email_successfully() { // Write code here that turns the phrase above into concrete actions }
出力 :したがって、上記の例では、Gmailにログインし、データテーブルと転置データテーブルのシナリオごとに2つのメールを送信します。
例3
レポートについて説明します。
環境がセットアップされたら:
- EclipseにEclipseCucumberプラグインを追加します。
- Mavenプロジェクトを作成し、必要なすべての依存関係をプロジェクトに追加します。
- 新しいフィーチャファイルを作成します。
- それに必要な実装をStepdefファイルに追加します。
- ランナークラスを作成し、ランナークラスを実行します。
- すべてのタイプのレポートを表示します。
フィーチャーファイル
特徴: 機能のタイトル
このテンプレートを機能ファイルに使用したい
@ tag1
シナリオ: シナリオのタイトル
私がGithubのホームページにいることを考えると
ユーザー名とパスワードを指定すると
そして、サインインボタンをクリックします
その後、ログアウトオプションが表示されるはずです
Stepdefファイル
package com.cucumber; 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.en.But; import java.util.List; import cucumber.api.PendingException; import cucumber.api.java.it.Data; import cucumber.api.DataTable; 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 cucumber.api.cli.Main; public class Step1 { static WebDriver driver = null; @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 and Password$') public void i_specify_Username_and_Password() { driver.findElement(By.cssSelector('input#login_field')).sendKeys('chintamoni .patra@gmail.com'); driver.findElement(By.cssSelector('input#password')).sendKeys('Test@123'); // 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 } @Then('^I should be able to see logout option$') public void I_should_be_able_to_see_logout_option() throws InterruptedException{ driver.findElement(By.xpath('//*(@id='user -links')/li(3)/details/summary/img')).click(); WebElement opt = driver.findElement(By.xpath('//*(@id='user- links')/li(3)/details/ul/li')); List olist = opt.findElements(By.xpath('//li/form/button')); for(WebElement o : olist) { System.out.println(o); } //int a = olist.size(); System.out.println(olist.get(0).getText()); olist.get(0).click(); Thread.sleep(2000); // Write code here that turns the phrase above into concrete actions } }
Cucumberによって生成されるさまざまなタイプのレポートは次のとおりです。
HTMLレポート
可愛い
JUnit
結論
オープンソースツールであるCucumberは、BDDで広く使用されています。また、非常に理解しやすく、新機能に関して多くの範囲があり、CucumberをSeleniumやその他のサードパーティのツール/ jarなどと統合することは事実上可能です。
アクティブなヘルプグループ/メンバーがいるので、キュウリを学び始めたばかりの人や、キュウリ/ BDDの中間知識を持っている人にとっては本当に簡単になります。
Cucumberは、ExcelシートおよびJenkinsとの統合もサポートします。
推奨読書
- Cucumber Seleniumチュートリアル:Cucumber Java SeleniumWebDriverの統合
- 例を含むPythonDateTimeチュートリアル
- BDDアプローチを使用したキュウリによるRESTAPIテスト
- Cucumber ToolとSeleniumを使用した自動化テスト– Seleniumチュートリアル#30
- Cucumber Gherkinチュートリアル:Gherkinを使用した自動化テスト
- 例を含むUnixシェルスクリプトチュートリアル
- Seleniumは例を含むテキストチュートリアルで要素を検索します
- Java'this 'キーワード:コード例を含むチュートリアル