title: How to use REST API mark tests as fail?
body: <p>I use this <a href="https://www.browserstack.com/docs/automate/selenium/view-test-results/mark-tests-as-pass-fail" rel="nofollow noreferrer">https://www.browserstack.com/docs/automate/selenium/view-test-results/mark-tests-as-pass-fail</a> as reference.
  But I not able to let the REST API shows 'fail'. May I know what is my problem? I also attached the text logs, it shows 'Run JavaScript......'
  , is it correct?</p>
  <pre><code>import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.remote.DesiredCapabilities;
  import org.openqa.selenium.remote.RemoteWebDriver;
  import org.testng.Assert;
  import org.testng.annotations.AfterClass;
  import org.testng.annotations.BeforeClass;
  import org.testng.annotations.Test;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import org.openqa.selenium.JavascriptExecutor;  
  
  public class test1 {
  
      public WebDriver driver = null;
  
      public static final String USERNAME = &quot;&quot;;
      public static final String AUTOMATE_KEY = &quot;&quot;;
      public static final String URL = &quot;https://&quot; + USERNAME + &quot;:&quot; + AUTOMATE_KEY + &quot;@hub-cloud.browserstack.com/wd/hub&quot;;
  
      @BeforeClass
      public void setup() throws MalformedURLException {
  
          DesiredCapabilities caps = new DesiredCapabilities();
  
          caps.setCapability(&quot;os&quot;, &quot;Windows&quot;);
          caps.setCapability(&quot;os_version&quot;, &quot;10&quot;);
          caps.setCapability(&quot;browser&quot;, &quot;Chrome&quot;);
          caps.setCapability(&quot;browser_version&quot;, &quot;80&quot;);
  
          caps.setCapability(&quot;name&quot;, &quot;Test1&quot;);
  
          driver = new RemoteWebDriver(new URL(URL), caps);
      }
  
      @Test (priority = 1)
      public void test_1() {
          driver.get(&quot;https://youtube.com&quot;);
  
          String actualUrl = &quot;https://www.youtube.com/&quot;;
          String expectedUrl = &quot;https://www.youtube.com/&quot;;
          Assert.assertEquals(actualUrl, expectedUrl);
          
          JavascriptExecutor jse = (JavascriptExecutor)driver;
          
          if (actualUrl.equals(expectedUrl)) {
            jse.executeScript(&quot;browserstack_executor: {\&quot;action\&quot;: \&quot;setSessionStatus\&quot;, \&quot;arguments\&quot;: {\&quot;status\&quot;: \&quot;passed\&quot;, \&quot;reason\&quot;: \&quot;Url matched!\&quot;}}&quot;);
          }
          else {
            jse.executeScript(&quot;browserstack_executor: {\&quot;action\&quot;: \&quot;setSessionStatus\&quot;, \&quot;arguments\&quot;: {\&quot;status\&quot;:\&quot;failed\&quot;, \&quot;reason\&quot;: \&quot;Url not matched\&quot;}}&quot;);
          }
      }
  
      @Test (priority = 2)
      public void test_2() {
          driver.get(&quot;https://google.com&quot;);
  
          String actualUrl = &quot;https://www.google.com/&quot;;
          String expectedUrl = &quot;https://www.youtube1.com/&quot;;
          Assert.assertEquals(actualUrl, expectedUrl);
          
          JavascriptExecutor jse = (JavascriptExecutor)driver;
          
          if (actualUrl.equals(expectedUrl)) {
            jse.executeScript(&quot;browserstack_executor: {\&quot;action\&quot;: \&quot;setSessionStatus\&quot;, \&quot;arguments\&quot;: {\&quot;status\&quot;: \&quot;passed\&quot;, \&quot;reason\&quot;: \&quot;Url matched!\&quot;}}&quot;);
          }
          else {
            jse.executeScript(&quot;browserstack_executor: {\&quot;action\&quot;: \&quot;setSessionStatus\&quot;, \&quot;arguments\&quot;: {\&quot;status\&quot;:\&quot;failed\&quot;, \&quot;reason\&quot;: \&quot;Url not matched\&quot;}}&quot;);
          }
      }
  
      @AfterClass
      public void tearDown() {
          driver.quit();
      }
  }
  </code></pre>
  <p>I tested with youtube and google url.</p>