简体   繁体   中英

Execute conditional logic based on the result of previous assertion in OpenTest

I need to validate if an element is on the screen using a function. If not, it performs another function. eg:

      - description: validation function
        script: |
            $runAction("org.getopentest.selenium.NavigateTo", {
              url: "https://translate.google.com/"
            }),;
            if((
              $runAction('org.getopentest.selenium.AssertElementVisible',
              {
              "locator": {css: "[id='sugg-item-en']"},
              })
              ) == 'true'){
              } else {
              $runAction('org.getopentest.selenium.AssertElementVisible',
              {
              "locator": {css: "[id='sugg-item-pt']"}
              });
              }

You can use a try...catch statement:

- description: Validation function
  script: |
      try {
        $runAction('org.getopentest.selenium.AssertElementVisible', {
            "locator": {css: "[id='sugg-item-en']"},
        });

        // If element was found (the assert succeeded), execution continues here
      } catch {
        // If element was NOT found (the assertion failed), execution continues here
      }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM