Hi I have a selenium cucumber project with some tests. The tests worked and the chromeDriver had launch when I run the -mvn clean compile test in my IDE. I created this .gitlab-ci.yml in my projec...
If I understand well, now, your tests are working well in your IDE, in both windowed and headless mode?
And in gitlab-ci, you do not have a "Unable to load browser" error anymore, but the "Unable to wait and click" one?
If so, I can see two reason for that:
- your test is not idempotent: the state of your page changes over time. To debug this, try to take a screenshot and to retrieve it as an artifact in gitlab-ci
- your app needs more time to properly load its content, and in gitlab-ci, docker images are not powerfull enough to process it in time. Try to globally increase the timeouts before a test is considered failing
To make sure the whole thing is properly working and to distinguish issues in tests from issues while trying to execute the tests, you can try to add a really simple "Hello world" test in your test-suite, which load the simplest possible page and check it is displayed by the browser.
If that test pass, you know that Selenium is properly set-up in the CI.
If not, you can continue working on setting it up.
> 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:
It looks like this is a responsive issue. Chrome headless seems to have a lower definition than regular, so it apply css breakpoints to github.
Testing github is part of your test-suite? Or is it a "Hello world" test to setting things up?
To fix this, in the chrome options, try adding something like this: `options.addArguments("window-size=1920,1080")`. I'll let you look for some documentation if you need to.
Forget about driver.manage().window().maximize(): in headless mode, you won't have any window at all, so it won't ever work.
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.
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;
}
}
It seems like you managed to fix the issue. I have the same problem you did face. I do however, use gitpod for my project, with maven, gitlab and monocle.
Could you post a link of the final project for me to use as guidance?