3

i am new to all of this coding experience. i have been a manual qa for several years and now i am starting to get my hands on selenium

i have worked out a very simple test case to submit a registration form, and i would like to get the result for that test case and post it on my testing tool "Test Rail". i have been doing it with soapui while testing endpoints so i know how to do it but not how to associate the result of the test case to trigger the post condition.

now i am using selenium with eclipse and Junit and this is my simple code:

package com.example.tests;

import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class createLead {
private WebDriver driver;
private Select dropdown;

  @Before
  public void setUp() throws Exception { 
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\Agustin Barcia\\driver\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  }

  @Test
  public void testUntitledTestCase() throws Exception {
    driver.get("www.randomform.com");    
    driver.findElement(By.id("firstname-input")).sendKeys("agustin");
    driver.findElement(By.id("lastname-input")).sendKeys("placement");
    driver.findElement(By.id("emailaddress-input")).clear();
    driver.findElement(By.id("emailaddress-input")).sendKeys("random@email.com");
    driver.findElement(By.id("country-select"));
    dropdown = new Select(driver.findElement(By.id("country-select")));
    dropdown.selectByValue("ar");
    driver.findElement(By.id("state-select"));
    dropdown = new Select(driver.findElement(By.id("state-select")));
    dropdown.selectByValue("178");
    driver.findElement(By.id("city-select"));
    dropdown = new Select(driver.findElement(By.id("city-select")));
    dropdown.selectByValue("245");
    driver.findElement(By.id("submit-button")).click();    
    } 
}

When i run this code in Junit the window shows "Success" and the registration is made.

Well now i have the code to post the resul in testrail, i would like to make a conditional if, the test case above returns "success" post in testrail a testcase ok, and if the test case returns "failure" post in test rail the test case failed. i know how to post the result but not how to obtain the "success" or "Fail" from the test run

any help?

  • You should check out JUnit's [TestWatchman/TestWatcher Rules](https://github.com/junit-team/junit4/wiki/Rules#testwatchmantestwatcher-rules) – Jakub Ch. Sep 04 '18 at 14:03
  • @JakubCh. thanks! ihave checked testwachman, but since i am not a developer i dont wheater if a have to create a new class for the rules or justa add up the portion code to my test class above – Agustín Barcia Sep 04 '18 at 14:50
  • _i dont wheater if a have to create a new class for the rules or justa add up the portion code to my test class above_ - it depends on you. If you'd like to reuse the rule for many test classes/suites then you should provide a new class for the rule (to avoid code duplication). Otherwise it can stay within `createLead` class (e.g. if you do this just to learn stuff or if it's a single case of posting the result to testrail) – Jakub Ch. Sep 04 '18 at 15:22
  • Possible duplicate of [JUnit 4.11 get test result in @After](https://stackoverflow.com/questions/22773590/junit-4-11-get-test-result-in-after) – JeffC Sep 04 '18 at 16:15

1 Answers1

0

I have done this -

"i would like to make a conditional if, the test case above returns "success" post in testrail a testcase ok, and if the test case returns "failure" post in test rail the test case failed.i know how to post the result but not how to obtain the "success" or "Fail" from the test run"

by making a reporting class which implements ITTestListner and captures the result of test case as below:-

 public void onTestSuccess(ITestResult tr) {

System.out.println("onTestSuccess");

String screenshotPath = ".//" + screenshotName + ".png";
File screenshotTRPath = new File(System.getProperty("user.dir") + "/Reports/" + 
     screenshotName + ".png");

System.out.println("screenshotPath-->" + screenshotPath);
System.out.println("screenshotTRPath-->" + screenshotTRPath.toString());
///TestRail API
try {
    addResultForTestCase(currentTestCaseId, TEST_CASE_PASSED_STATUS, 
 screenshotTRPath.toString());
} catch (IOException | APIException | ParseException e) {  e.printStackTrace();

}
Atul KS
  • 908
  • 11
  • 21