GithubHelp home page GithubHelp logo

selenide / selenide Goto Github PK

View Code? Open in Web Editor NEW
1.8K 1.8K 562.0 14.38 MB

Concise UI Tests with Java!

Home Page: http://selenide.org

License: MIT License

Java 95.71% HTML 3.10% JavaScript 1.15% Shell 0.04%

selenide's Introduction

Selenide = UI Testing Framework powered by Selenium WebDriver

Build Status Maven Central MIT License Free

Join the chat at https://gitter.im/codeborne/selenide Присоединяйся к чату https://gitter.im/codeborne/selenide-ru Follow Telegram channel Telegram чат

What is Selenide?

Selenide is a framework for writing easy-to-read and easy-to-maintain automated tests in Java. It defines concise fluent API, natural language assertions and does some magic for ajax-based applications to let you focus entirely on the business logic of your tests.

Selenide is based on and is compatible to Selenium WebDriver 4.0+

@Test
public void login() {
  open("/login");
  $(By.name("user.name")).setValue("johny");
  $("#submit").click();
  $("#username").shouldHave(text("Hello, Johny!"));
}

Look for detailed comparison of Selenide and Selenium WebDriver API.

Selenide for mobile apps

You can use Selenide for testing mobile applications. See plugin selenide-appium.

Selenide with Selenoid

You can use Selenide for running tests in Selenoid containers. See plugin selenide-selenoid.

Selenide with Selenium Grid

You can use Selenide for running tests in Selenium Grid. See plugin selenide-grid.

Changelog

Here is CHANGELOG

How to start?

Just put selenide.jar to your project and import the following methods: import static com.codeborne.selenide.Selenide.*;

Look for Quick Start for details.

Resources

FAQ

See Frequently asked questions

Posts

Contributing

Contributions to Selenide are both welcomed and appreciated. See CONTRIBUTING.md for specific guidelines.

Feel free to fork, clone, build, run tests and contribute pull requests for Selenide!

Authors

Selenide was originally designed and developed by Andrei Solntsev in 2011-2021 and is maintained by a group of enthusiast.

Thanks

Many thanks to these incredible tools that help us create open-source software:

Intellij IDEA BrowserStack LambdaTest

License

Selenide is open-source project, and distributed under the MIT license

selenide's People

Contributors

amuthan-sakthivel avatar amuthansakthivel avatar angryziber avatar anilreddy avatar armanayvazyan avatar asolntsev avatar au6ojlut avatar azakordonets avatar bereg2k avatar borisosipov avatar britka avatar dbudim avatar dependabot-preview[bot] avatar dependabot[bot] avatar dstekanov avatar evpl avatar fokinp avatar jane-ryabchenko avatar jreznot avatar kumarunster avatar ostap-oleksyn avatar petroov-pdffiller avatar plagov avatar rosolko avatar sbritprovectus avatar seleniumtestab avatar shimkiv avatar tsukakei avatar vadger avatar vinogradoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

selenide's Issues

Support for phantomjs?

The API docs list ie, chrome, htmlunit, and firefox as valid browser values. Since WebDriver also supports phantomjs, are there plans to enable this in Selenide? HTMLUnit has so many problems as a headless browser that using Selenide in a headless environment is difficult/impossible.

Add support for all drivers

Currently only IEDriver, FirefoxDriver, ChromeDriver and HtmlUnitDriver are supported.
Other drivers should be added:

  • AndroidDriver
  • IPhoneDriver
  • OperaDriver

what else?

Run Chrome in incognito mode

I am not sure if it should be default or configurable behavior.

Code sample:

ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
driver =  new ChromeDriver(options); 

Error message says `Expected: visible` for `shouldNotBe(visible)` check

The following test:

$(".validation-message[data-parameter-name='ssid']").shouldNotBe(visible);

Results in the following error message:

ElementMatches {By.selector: .validation-message[data-parameter-name='ssid']}
Expected: visible
Element: '<div class=validation-message>The WLAN name cannot contain special characters .</div>'
Timeout: 4 s.

It says: Expected: visible, thought shouldNotBe(visible); was requested.

Selenide could log every step in debug mode

It is useful in case of any mysterious behavior.
For example, for line

$(languageDrpdwn).shouldHave(text("Java"))

it should write a log message Element <option>Javascript</option> contains text "Java".

How to run

Option 1: from command line

-Dselenide.debug=true

Option 2: by test annotation

@Test @Debug
public void myTest() {...} 

both JUnit and TestNG could be supported

Create BrowserStrategy for TestNG

It would be convenient to declare one of "browser per test", "browser per class" strategy as an annotation to tests.

Now we have such an annotation only for JUnit. Need the same for TestNG.

Searching with $() returns different element if the initial one has changed

For example, clicking the button will change it's class from 'btn btn-primary btn-save' to 'btn btn-save'.

I'm storing the button as SelenideElement to make checks later:

    SelenideElement bSave = $(".btn-primary.btn-save");

Now, following code

    SelenideElement bSave = $(".btn-primary.btn-save");
    System.out.println(bSave.getLocation());

    bSave.click();
    System.out.println(bSave.getLocation());

    Thread.sleep(5000);

    System.out.println(bSave.getLocation());

will return

    (1373, 365)
    (1373, 365)
    (1373, 549)

So "bSave" appears to be another button now. And the final check will fail:

    bSave.should(hasNotClass("btn-primary"));

PS: I was able to write the same without using $() in pure Selenium and WebElement and it worked.

Add support for PageObject concept

Not sure we really need it, but why not.

If somebody wants to use PageObject, we could allow it by using
"return org.openqa.selenium.support.PageFactory.initElements(driver, MyPageObject.class)"

Create readable error message for element initialized by PageFactory

Having an element:

@FindBy(id  = "invalid_id")
private WebElement categoryDropdown;
  1. Trying to select an option: $(categoryDropdown).selectOption("SomeOption");
    produces the following error message: ElementNotFound {By.selector: option, in: NoSuchElementException: Unable to locate element: {"method":"id","selector":"invalid_id"}}
  2. Trying to click the element: $(categoryDropdown).click() produces the following error message: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"invalid_id"}

$.shouldHave(text("John McClain")) should ignore whitespaces

Different browsers treat spaces differently. For this row JohnMcClain some browsers think that text is "JohnMcClain", but others think that text is "John McClain".

It would be universal approach if text() condition would ignore whitespaces.

getElement() and shouldXXX() methods should wait for a few seconds

Many events happen after few seconds (because of heavy usage of Ajax in modern web applications).
Currently it's possible to implicitly call waitUntil("#messages div", hasText("John")), but in most cases user does not even know about Ajax, so Selenide should wait automatically - as naturally as user does wait.

For example, method
$("#messages div").shouldHave(text("John")) should wait for few seconds until the "div" actually gets text "John" loaded.

Add method $.scrollTo

Selenide has method scrollTo, but it uses jQuery plugin "scroll".
The same effect could be achieved without using jQuery:

public static void scrollTo(WebElement element) {
        int elementPosition = element.getLocation().getY();
        String js = String.format("window.scrollTo(0, %s)", elementPosition);
        JavascriptExecutor jsx = (JavascriptExecutor) getWebDriver();
        jsx.executeScript(js, "");
}

Fix byText() and withText() xpaths

By.xpath(".//*[contains(normalize-space(text()), "" + elementText + "")]")

По спецификации: http://www.w3.org/TR/xpath/#node-tests. text() - в действительности это не текст элемента, а функция, которая возвращает все текстовые ноды данного элемента. Т.е. в случае

div_text
имеется две текстовых ноды: //div/text()[1] == ' ', //div/text()[2] == ' div_text '; а //div[contains(text(),'div_text')] ==//div[contains(text()[1],' div_text ')] == NoSuchElement

Implement ScreenShots for RemoteWebDriver

For RemoteWebDriver, screenshots should be taken differently from usual webdriver:

File scrFile;

        if (driver.getClass().equals(RemoteWebDriver.class)) {
            scrFile = ((TakesScreenshot) new Augmenter().augment(driver)).getScreenshotAs(OutputType.FILE);
        } else {
            scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        }

Add selector By.text

Currently Selenium API doesn't provide method to find element by text. But we believe that Acceptance Tests must use visible text where possible. So, we should add several selectors:

  • By.text
  • By.partialText
  • By.regex

ElementsCollection#size() causes NoClassDefFoundError

I assume that issue is caused by incorrect import statement in FilteringCollection.

java.lang.NoClassDefFoundError: com/beust/jcommander/internal/Lists
at com.codeborne.selenide.impl.FilteringCollection.getActualElements(FilteringCollection.java:21)
at com.codeborne.selenide.ElementsCollection.getActualElements(ElementsCollection.java:79)
at com.codeborne.selenide.ElementsCollection.size(ElementsCollection.java:104)

I have added jcommander to dependencies of my project as a temporary workaround.

Chaining of ElementsCollection methods

Some ElementsCollection methods (shouldHaveSize, shouldBe and shouldHave) do not support chaining, i.e. not possible to write such expressions:
$$("table tr").shouldHaveSize(10).filterBy(text("aaa"));

It would be nice if those can be chained the same way as other methods.

Bug in documentation for Condition

  1. "You can easily add your own conditions by implementing interface com.codeborne.selenide.Condition" - actually Condition is abstract class.
  2. Add an example of custom Condition into documentation.
    @Override
    public String actualValue(WebElement element) {
        return element.getCssValue(propName);
    }

    @Override
    public String toString(){
        return String.format("'%s' css property of '%s' value", propName, propValue);
    }
};

Exception should contain URL if browser failed to open page

Currently trying to execute open("www.yandex.ru"); causes quite unreadable error message:

org.openqa.selenium.WebDriverException: Component returned failure
code: 0x804b000a (NS_ERROR_MALFORMED_URI) [nsIIOService.newURI]
Command duration or timeout: 44 milliseconds
Build info: version: '2.31.0', revision:
'1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27
13:51:26'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1',
java.version: '1.7.0_07'
Session ID: e697e9e5-1d3e-4f15-8855-196d02670da8
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true,
cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true,
handlesAlerts=true, browserName=firefox,
browserConnectionEnabled=true, nativeEvents=true,
webStorageEnabled=true, rotatable=false, locationContextEnabled=true,
applicationCacheEnabled=true, takesScreenshot=true, version=23.0.1}]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Unclear error message in case of mismatching text

Code:
$(".alert-success").shouldHave(text(message));

Result:
junit.framework.AssertionFailedError: {By.selector: .alert-success}
Expected: got text 'Deposit has been created. The amount will be transferred to it in a few moments. You can check the status of transfer in payment history.'
Timeout: 4 s.

Enable using multiple WebDriver instances in the same process

It can be useful for running tests in multiple parallel threads (for example, TestNG allows it).

An example of TestNG configuration provided by Sergey Kuts:

<test name="IE 10 Test">
    <parameter name="browser"  value="internet explorer"/>
    <parameter name="version"  value="10"/>
    <parameter name="platform"  value="WINDOWS"/>

    <classes>
        <class name="class1">
            <methods>
                <include name = "method1"/>
                <include name = "method2"/>
            </methods>
        </class>
    </classes>
</test>

 <test name="FF 10 Test">
     <parameter name="browser"  value="firefox"/>
     <parameter name="version"  value="10"/>
     <parameter name="platform"  value="WINDOWS"/>

     <classes>
         <class name="class1">
             <methods>
                 <include name="method1" />
                 <include name="method2" />
             </methods>
         </class>
     </classes>
 </test>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.