ContributionsMost RecentMost LikesSolutionsHow to select an option from selectBox Hi I can't select one of the options of the select box. Actually, the select box opens when I run the test. But it doesn't select the option I want. This is the function that I use in my stepDefinition: @Throws(Throwable::class) fun selectGender(gender: String?): UserProfileCompletionPage { clickOnTextFromDropdownList(selectBoxGender!!, gender!!) return UserProfileCompletionPage() } And this is the content of clickOnTextFromDropdownList function: @Throws(Exception::class) fun clickOnTextFromDropdownList(list: WebElement, textToSearchFor: String) { val tempWait: Wait<WebDriver> = WebDriverWait(DriverFactory.driver, 30) try { tempWait.until(ExpectedConditions.elementToBeClickable(list)).click() list.sendKeys(textToSearchFor) list.sendKeys(Keys.ENTER) println("Successfully sent the following keys: $textToSearchFor, to the following WebElement: <$list>") } catch (e: Exception) { println("Unable to send the following keys: $textToSearchFor, to the following WebElement: <$list>") Assert.fail("Unable to select the required text from the dropdown menu, Exception: " + e.message) } } I'll be grateful if you guide me. Thanks in advance. Re: how to use a feature file within another aurelien-reeves Hi again I created this feature file for the login: Scenario Outline: Login into account with correct credentials And User clicks on the login button on homepage And User enters a valid username "<username>" And User enters a valid password "<password>" When User clicks on the login button Examples: | username | password | | user1 | 123456 | And this is the step definition for the login: @Given("User clicks on the login button on homepage$") @Throws(Throwable::class) fun user_clicks_on_the_login_button_on_homepage() { loginPage!!.clickOnSignInButton() } @Given("^User enters a valid username \"([^\"]*)\"$") @Throws(Throwable::class) fun user_enters_a_valid_username(username: String?) { loginPage!!.enterUserName(username) } @Given("^User enters a valid password \"([^\"]*)\"$") @Throws(Throwable::class) fun user_enters_a_valid_password(password: String?) { loginPage!!.enterPassword(password) } @When("User clicks on the login button$") @Throws(Throwable::class) fun user_clicks_on_the_login_button() { loginPage!!.clickOnSubmitButton() } I used the login functions inside the step definition of the form, in this way: @Given("^User logged in with valid username and password$") @Throws(Throwable::class) fun user_logged_in_with_valid_and() { LoginSteps().user_clicks_on_the_login_button_on_homepage() LoginSteps().user_enters_a_valid_username() LoginSteps().user_enters_a_valid_password() LoginSteps().user_clicks_on_the_login_button() } @Then("^User clicks on the processes page$") @Throws(Throwable::class) fun user_clicks_on_the_processes_page() { fillingFormPage!!.clickOnProcessesPage() } But I have a problem that says no value passed for parameter username and password, which is right. So, I changed the step definition for the form like this: @Given("^User logged in with valid username and password$") @Throws(Throwable::class) fun user_logged_in_with_valid_and(username: String?, password: String?) { LoginSteps().user_clicks_on_the_login_button_on_homepage() LoginSteps().user_enters_a_valid_username(username) LoginSteps().user_enters_a_valid_password(password) LoginSteps().user_clicks_on_the_login_button() } @Then("^User clicks on the processes page$") @Throws(Throwable::class) fun user_clicks_on_the_processes_page() { fillingFormPage!!.clickOnProcessesPage() } But also when I run the test, I face this problem: feature (Fill the form) cucumber.runtime.CucumberException: cucumber.runtime.CucumberException: Arity mismatch: Step Definition 'void stepDefinitions.FillingFormSteps.user_logged_in(String,String) in file:/###/target/classes/' with pattern [^User logged in$] is declared with 2 parameters. However, the gherkin step has 0 arguments []. Step: Given User logged in with valid username and password at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:69) at cucumber.api.testng.AbstractTestNGCucumberTests.feature(AbstractTestNGCucumberTests.java:21) Caused by: cucumber.runtime.CucumberException: Arity mismatch: Step Definition 'void stepDefinitions.FillingFormSteps.user_logged_in(String,String) in file:/###/target/classes/' with pattern [^User logged in$] is declared with 2 parameters. However, the gherkin step has 0 arguments []. Step: Given User logged in with valid username and password at cucumber.runtime.StepDefinitionMatch.arityMismatch(StepDefinitionMatch.java:102) at cucumber.runtime.StepDefinitionMatch.transformedArgs(StepDefinitionMatch.java:60) at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37) at cucumber.runtime.Runtime.runStep(Runtime.java:300) at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44) at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39) at cucumber.runtime.model.CucumberScenario.runBackground(CucumberScenario.java:59) at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:42) at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165) at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:63) ... 29 more So, I had to change the feature file of the form from this: Feature: Fill the form Existing user should be able to log in using correct credentials and fill the form Background: : logged in user Given User logged in with valid username and password Scenario: Login into account with correct credentials and fill the form And User clicks on the processes page to this: Feature: Fill the form Existing user should be able to log in using correct credentials and fill the form Background: : logged in user Given User logged in with valid "<username>" and "<password>" Scenario: Login into account with correct credentials and fill the form And User clicks on the processes page also, I had to change the step definition of the form from this: @Given("^User logged in with valid username and password$") @Throws(Throwable::class) fun user_logged_in_with_valid_and(username: String?, password: String?) { LoginSteps().user_clicks_on_the_login_button_on_homepage() LoginSteps().user_enters_a_valid_username(username) LoginSteps().user_enters_a_valid_password(password) LoginSteps().user_clicks_on_the_login_button() } @Then("^User clicks on the processes page$") @Throws(Throwable::class) fun user_clicks_on_the_processes_page() { fillingFormPage!!.clickOnProcessesPage() } to this: @Given("^User logged in with valid \"([^\"]*)\" and \"([^\"]*)\"$") @Throws(Throwable::class) fun user_logged_in_with_valid_and(username: String?, password: String?) { LoginSteps().user_clicks_on_the_login_button_on_homepage() LoginSteps().user_enters_a_valid_username(username) LoginSteps().user_enters_a_valid_password(password) LoginSteps().user_clicks_on_the_login_button() } @Then("^User clicks on the processes page$") @Throws(Throwable::class) fun user_clicks_on_the_processes_page() { fillingFormPage!!.clickOnProcessesPage() } But, when I run the test, the username and password fields, filled with these values: username: <username> password: <password> But I want them to be filled with these values: username: user1 password: 123456 Which I defined in the feature file of the login. What can I do to pass the correct values??? Re: using tag in FindBy annotation aslakhellesoy Sorry I didn't get it exactly. Shouldn't I use the selenium WebDriver? What should I do? Re: using tag in FindBy annotation there is no solution? Re: how to use a feature file within another please guide me. what can I do? how to use a feature file within another Hi I want to create a complete login feature file and write its unit tests. And I could run that unit tests, whenever I want. After, I want to create another feature file (let's call it filling a form) and write its unit test. But in my case, only logged-in users can fill out that form. So I want to use the login feature file inside the filling form feature file. Of course, both feature files must be complete and separate from each other, and I could run them simultaneously. using tag in FindBy annotation Hi I've created a complete test case using the cucumber and everything is fine. I've used the XPath for targeting the elements. And using the XPath was a little messy. I want to add a new property in all the elements for making it easier to targeting elements. Should I add the "tag" property in elements? And also for using that, Should I use the "tagName" in the @FindBy? If so, what name would you suggest for the tag property? Something like "ui_testing_button" is good? Re: run cucumber selenium tests in gitlab-ci Hi aurelien-reeves Testing Github is a sample test. I wanted to run a test completely and then go to my main test. I added options.addArguments("window-size=1920,1080") and I run the test and everything worked fine and tests run in the console. Then I pushed my changes and the pipeline passed correctly. THANK you a lot, my friend. 🙂 another question. It seems the pipeline's output is similar in the build stage and the test stage. this is my gitlab-ci: image: markhobson/maven-chrome:jdk-11 stages: - build - test variables: MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" cache: paths: - .m2/repository/ - target/ build: stage: build script: - mvn $MAVEN_OPTS clean package - mvn compile test: stage: test script: - mvn test Should I remove one of them and let one of them stay?? I do forget all about the driver.manage().window().maximize() in headLess mode. Re: run cucumber selenium tests in gitlab-ci aurelien-reeves oh, you mentioned checking screenshot before, but I did not notice at all. (sorry) yes, I configured the taking screenshot in the step that the problem happens. And as you know I have the same problem in headLess mode even the IDE mode. so, I run the test again in IDE in headLess mode and face that error and checked the screenshot and I noticed that the browser window zooms in on the screen and the link that I need to click on that is disappear!!! Please Look: the page that I expect: and I want to click on "Sign In". but the page that taken screenshot: which the sign-in link is gone... so, I added this maximization option that you mentioned before: options.addArguments("start-maximized"); And it made no difference. so, I replaced it with this: driver.manage().window().maximize(); And the error is gone. but now, I face this error again: Unable to load browser: null Failure in before hook:MasterHooks.setup() Message: java.lang.AssertionError at utils.DriverFactory.getDriver(DriverFactory.java:38) at stepDefinitions.MasterHooks.setup(MasterHooks.java:15) this is the DriverFactorry file: package utils; import io.github.bonigarcia.wdm.WebDriverManager; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.PageFactory; import pageObjects.Login_page; import java.io.FileInputStream; import java.util.Properties; import java.util.concurrent.TimeUnit; public class DriverFactory { public static WebDriver driver; public static Login_page loginPage; public WebDriver getDriver() { try { // Read Config Properties p = new Properties(); FileInputStream fi = new FileInputStream(System.getProperty("user.dir") + "/src/main/java/properties/config.properties"); p.load(fi); String browserName = p.getProperty("browser"); if ("chrome".equals(browserName)) { if (null == driver) { WebDriverManager.chromedriver().setup(); ChromeOptions options = new ChromeOptions(); options.setHeadless(true); driver.manage().window().maximize(); driver = new ChromeDriver(options); } } } catch (Exception e) { System.out.println("Unable to load browser: " + e.getMessage()); } finally { assert driver != null; driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); loginPage = PageFactory.initElements(driver, Login_page.class); } return driver; } } and this is the MasterHooks file: package stepDefinitions; import cucumber.api.Scenario; import cucumber.api.java.After; import cucumber.api.java.Before; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import pageObjects.BasePage; import utils.DriverFactory; public class MasterHooks extends DriverFactory { @Before public void setup() { driver = getDriver(); } @After public void tearDownAndScreenshotOnFailure(Scenario scenario) { try { if(driver != null && scenario.isFailed()) { scenario.embed(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES), "image/png"); BasePage.captureScreenshot(); driver.manage().deleteAllCookies(); driver.quit(); driver = null; } if(driver != null) { driver.manage().deleteAllCookies(); driver.quit(); driver = null; } } catch (Exception e) { System.out.println("Methods failed: tearDownAndScreenshotOnFailure, Exception: " + e.getMessage()); } } } Re: run cucumber selenium tests in gitlab-ci aurelien-reeves Thanks again for guiding. In IDE: without headLess mode: tests work fine without any error. with headLess mode: I have the "Unable to wait and click" error. In gitlab: without headLess mode: I have the "Unable to load browser" with headLess mode: I have the "Unable to wait and click" error. My test is including the login to Github site. And I defined my feature file like this: Scenario: Login into account with correct credentials Given User navigates to github website And User clicks on the login button on homepage And User enters a valid username And User enters a valid password When User clicks on the login button Then User should be taken to the successful login page which in the build stage (in GitLab and with headLess) I have the "Unable to wait and click" error. I deleted all the additional steps and I let the navigate step remain (which looks like "Hello World"). and when I run the pipeLine all the stages passed and the tests run. but I didn't see the chromeDriver be launched!! I think I should add chromeDriver in my gitlab-ci. What's your opinion?