2017-10-29 3 views
0

CSVデータセットの設定を使用して、複数のユーザーでテストアプリケーションにログインするためにJunit Requestサンプラーを使用しようとしました。例:スレッド数を2に設定し、2つのユーザーログインの詳細を.csvファイルに設定してテストを実行します。その結果、2つのFirefoxブラウザと1つのブラウザが正常にログオンし、他のブラウザはログインページのユーザー名とパスワードフィールドにユーザー名とパスワードを取得しませんでした。これは私のセレンのスクリプトコードです。誰でもこの問題の理由を提案できますか?JUnitサンプラーがCSVデータセットで正常に動作しない複数のスレッド用の構成Jmeter

import org.apache.jmeter.protocol.java.sampler.JUnitSampler; 
import org.junit.Assert; 
import org.junit.BeforeClass; 
import org.junit.Test; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class testClass { 

    static WebDriver driver; 
    JUnitSampler sampler = new JUnitSampler(); 
    String userName = sampler.getThreadContext().getVariables().get("username"); 
    String password = sampler.getThreadContext().getVariables().get("password"); 
    String Empnamecsv = sampler.getThreadContext().getVariables().get("Empname"); 

    @BeforeClass 
    public static void setUpBeforeClass() throws Exception 
    { 
     System.setProperty("webdriver.gecko.driver", "D:\\Automation\\Geckodriver\\V0.19.0\\geckodriver.exe"); 
     driver = new FirefoxDriver(); 
    } 

    @Test 
    public void loadHomePage() throws InterruptedException 
    { 
     driver.get("http://localhost/testWeb"); 
     Thread.sleep(1000); 
    } 

    @Test 
    public void login() throws InterruptedException 
    { 
     driver.findElement(By.id("txtusername")).sendKeys(userName); 
     driver.findElement(By.id("txtpassword")).sendKeys(password); 
     driver.findElement(By.id("btnsubmit")).click(); 
     Thread.sleep(1000); 
     String name = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div[3]/span[1]/span[1]")).getText(); 
     Assert.assertEquals(name,namecsv); 
    } 
} 
+0

あなたはエラーの原因を教えてください。 –

+0

2つのjunitリクエストサンプラーを使用しました。最初のjunitリクエストサンプラーでクラス名をtestClass、setUpBeforeClassメソッドをTest Methodとして設定します。 2番目のjunitリクエストサンプラーでは、クラス名をtestClassに設定し、ログインメソッドをテストメソッドとして設定し、スレッドグループを実行します。その結果、2つのFirefoxブラウザが開かれ、URLが正常に読み込まれました。しかし、1つのブラウザだけがアプリケーションの成功に完全にログオンし、他のブラウザはログインデータがユーザー名とパスワードフィールドに挿入されずにログインできません。それが問題です。 –

答えて

0

見えるように、あなたの "ログイン" 方法を更新してみてください。

@Test 
public void login() throws InterruptedException { 
    org.apache.jmeter.threads.JMeterVariables vars = org.apache.jmeter.threads.JMeterContextService.getContext().getVariables(); 
    driver.findElement(By.id("txtusername")).sendKeys(vars.get(userName)); 
    driver.findElement(By.id("txtpassword")).sendKeys(vars.get(password)); 
    driver.findElement(By.id("btnsubmit")).click(); 
    Thread.sleep(1000); 
    String name = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div[3]/span[1]/span[1]")).getText(); 
    Assert.assertEquals(name, vars.get("Empnamecsv")); 
} 

参考文献:


またJMeterのとSelenium統合する別の方法に注意してください。

  1. WebDriver Sampler - セットアップするセレンクライアントライブラリと構成要素が付属していますブラウザインスタンス。マルチスレッド実行を自動的に処理します。
  2. JSR223 Sampler - これをJUnitの代わりに使用することができます。この方法で、コードを再コンパイルして変更を加える必要はありません。 Groovy言語を選択すると、パフォーマンスはJavaの場合とほぼ同じになります
+0

こんにちは、あなたの答えをありがとう。私は、上記のように "login"メソッドを更新してみました。しかし、同じ問題が再び発生しました。 CSVファイルの異なるユーザー名が同じ時間に同じブラウザで貼り付けられることがあります。 –

0

あなたの問題は、一度ユーザ名とパスワードを初期化しているということです:あなたはJUnitのクラスをテストすることができるのJMeterで

String userName = sampler.getThreadContext().getVariables().get("username"); 
String password = sampler.getThreadContext().getVariables().get("password"); 
String Empnamecsv = sampler.getThreadContext().getVariables().get("Empname"); 

が、ここで、あなたがJUnitテストでそれを作成しているようですクラス:

JUnitSampler sampler = new JUnitSampler();

したがって、受胎上の問題があります。

CSVを使用する場合は、Webdriver Samplerを使用するテスト計画を作成し、確認のためにJMeter assertionsを使用します。

はこちらの例を参照してください:

+0

ありがとうございました。 –

+0

答えがOKならば、それを受け入れ、upvoteする必要があります。ありがとう –