Hot questions for Using Cucumber in appium

Question:

I am using cucumber-jvm with appium using eclipse and junit.

Some of my tests stop working halfway through. They do not overtly fail the junit tests but instead stop working and ignore the remaining steps.

When I look at these steps in junit (through eclipse) they appear to have passed, until I drill into them and see steps have been ignored.

Is there a way to mark any test scenarios with ignored steps as failures rather than as passes?


Answer:

I presume you have a JUnit test case with an @CucumberOptions annotation on it. If you have this, you should be able to make ignored tests fail the build by setting strict=true. e.g.

@RunWith(Cucumber.class)
@CucumberOptions(strict = true)
public class CucumberRunnerTest {
}

Question:

i am getting an error `cucumber.runtime.AmbiguousStepDefinitionsException: ✽.Then I should validate my username with expected value (features/sanity.feature:32) matches more than one step definition: ^I should validate ([^"]*) with expected value in UserSteps.iShouldValidateWithExpectedValue(String) ^I should validate my username with expected value$ in HomeSteps.iShouldValidateMyUsernameWithExpectedValue()

`

When i run with calabash i use to add "--guess" in the run command.

But Don't know how to resolve the same in CucumberJvm in Java.

Is there any possiblities to add this in @cucumberoptions ?

Am using the maven dependency

<dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
    </dependency>

Answer:

--guess is not an option that you can set in the command line runner. Recall that cucumber can always guess wrong. I recommend that you simply change a few words near the beginning of the failing statement to make sure that that statement is unique. Better safe than sorry.

Searching through the cucumber-jvm source, there is at least one reference to --guess being set by default.

Question:

I have an existing automated suite for web browser based application on cucumber framework using selenium and java. We are now planning to run the same test scripts for the mobile app of same application. 1. Is it possible to migrate or extend the existing web-based scripts to appium with limited code changes? 2. If option 1 is not possible, then will we have to right the entire scripts again using appium parameters or is it possible to use selenium parameters for identifying the elements of click, textbox etc.? 3. Any guidance or material on this enhancement/integration would be of much help.


Answer:

1. Is it possible to migrate or extend the existing web-based scripts to appium with limited code changes?

The Framework structure could be retained .However i suggest you to create separate suite and test cases to handle appium. Appium takes several parameter to start a session with a particular device and the session value is passed to the scripts , its like the driver being passed to Selenium scripts.

2. If option 1 is not possible, then will we have to right the entire scripts again using appium parameters or is it possible to use selenium parameters for identifying the elements of click, textbox etc.?

Appium is an extended version of selenium , so the command like Click element will work , However , i am not sure if the locator value will be same for Web element and App element. You can try to locate your APP locator using Appium Desktop Appium Desktop for locating Elements and verify its values with locators from Web elements .

Any guidance or material on this enhancement/integration would be of much help.

Here is a tutorial if you want to learn Appium Appium

Question:

I am trying to run our app tests in device farm but I am getting an error saying it cannot find the features. java.lang.IllegalArgumentException: Not a file or directory: /tmp/scratchktFI9V.scratch/test-packagehFUzci/src/test/resources/features

I have got the example repo and app running and passing as per this guide which is all great but when running our own I get this error.

I noticed the example tests uses classpath in the features path but when i try this i just get Not a file or directory: /tmp/scratchRlueAN.scratch/test-packageMMRQh4/classpath

These are my cucumber options:

@CucumberOptions(
        monochrome = true,
        tags = {"@Login"},
        features = "src/test/resources/features",
        glue = "steps"
)

What should I set this as in my own tests?

Thanks in advance


Answer:

Try using classpath:. Note the colon at the end.

Question:

I use cucumber JVM with mobile automation tests and it works fine but I need to run to my runner classes from command line for build server. When I use the

javac -cp .;C:\V3\YemeksepetiAndroid.v3.Tests\AndroidV3\src\test\java\com\cucumber\AndroidV3\junit-4.11.jar Galaxy_S4_Runner.java

for run as you can see the screenshot (http://prntscr.com/9mrr1i ) it gives error. Anyone help me ? :)

This is my runner class

package com.cucumber.AndroidV3;

import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
@RunWith(Cucumber.class)

@CucumberOptions(

format = { "pretty", "html:target/html/s4/" },

features = { "src/test/resource" }, tags = { "@s4" }

)

public class Galaxy_S4_Runner {

Answer:

You need the two Cucumber jars (cucumber-java.jar and cucumber-core.jar) on your classpath along with junit-4.11.jar. You should be able to find them in a Maven repository.

Question:

I use Appium along with JUnit. Also Cucumber, but his one shouldn't interfere here.

I need to have clear app installation every case to make them really independent. I use following IOSDriver settings:

    public static void initDriver(boolean noReset) throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "iPhone 4s");
        capabilities.setCapability("noReset", noReset);
        capabilities.setCapability("autoAcceptAlerts",true);
        driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

   public void quitDriver() {
        driver.executeScript("au.backgroundApp(0)");
        driver.quit();
        driver = null;
    }
@Before problem

What I do is I check if the app is installed before every case, and if it is, to reinstall it. Unfortunately, when I uninstall the app, session is broken and the test case fails.

EDIT: initDriver() method causes the driver to start and install the app automatically, so this if(isAppInstalled) part is executed even when the app is not installed on device previously.

     @Before
        public void beforeScenario() throws MalformedURLException {
            initDriver(false);
            if(IosConfig.getDriver().isAppInstalled(StringConfiguration.getiOSappBundleId())) {
                System.out.println("THE APP IS INSTALLED. UNINSTALLING...");
                IosConfig.getDriver().removeApp(StringConfiguration.getiOSappBundleId());
            }
       }
@After problem [solved]

Moreover, my @After part is not executed, so the app is not uninstalled after the case...

@After
    public void tearDown(Scenario scenario) {
        try {
            if(scenario.isFailed()) {
                final byte[] screenshot = IosConfig.getDriver().getScreenshotAs(OutputType.BYTES);
                scenario.embed(screenshot, "image/png");
                IosConfig.getDriver().closeApp();
          IosConfig.getDriver().removeApp(StringConfiguration.getiOSappBundleId());
            }
        } finally {
            IosConfig.getDriver().closeApp();
         IosConfig.getDriver().removeApp(StringConfiguration.getiOSappBundleId());
            quitDriver();

        }
    }

Please help!


Answer:

Problem with "After" part solved.

I use also Cucumber, and by mistake I imported org.junit.After instead of cucumber.api.java.After! That one was hard to find.