{"id":21056017,"url":"https://github.com/xp-framework/webtest","last_synced_at":"2025-08-01T03:33:44.033Z","repository":{"id":35736897,"uuid":"40015637","full_name":"xp-framework/webtest","owner":"xp-framework","description":"Web tests for the XP Framework","archived":false,"fork":false,"pushed_at":"2022-03-04T09:05:01.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T19:22:27.363Z","etag":null,"topics":["unittest","xp-framework"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xp-framework.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-31T17:00:13.000Z","updated_at":"2022-03-04T08:59:24.000Z","dependencies_parsed_at":"2022-07-08T03:01:39.978Z","dependency_job_id":null,"html_url":"https://github.com/xp-framework/webtest","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fwebtest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fwebtest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fwebtest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fwebtest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-framework","download_url":"https://codeload.github.com/xp-framework/webtest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243500787,"owners_count":20300775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["unittest","xp-framework"],"created_at":"2024-11-19T16:48:19.725Z","updated_at":"2025-03-14T00:15:09.269Z","avatar_url":"https://github.com/xp-framework.png","language":"PHP","readme":"Webtest\n=======\n\n[![Build status on GitHub](https://github.com/xp-framework/webtest/workflows/Tests/badge.svg)](https://github.com/xp-framework/webtest/actions)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_0plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-framework/webtest/version.png)](https://packagist.org/packages/xp-framework/webtest)\n\nWeb tests for the XP Framework\n\nExample\n-------\nThe following web test case consists of opening GitHub's homepage and asserting the title to equal the company's name:\n\n```php\nuse unittest\\web\\{WebTestCase, Webtest};\nuse unittest\\Test;\n\n#[Webtest(url: 'https://github.com/')]\nclass GitHubTestCase extends WebTestCase {\n\n  #[Test]\n  public function home() {\n    $this-\u003ebeginAt('/');\n    $this-\u003eassertStatus(200);\n    $this-\u003eassertTitleEquals('GitHub: Where the world builds software · GitHub');\n  }\n}\n```\n\nRunning it works as with normal test cases:\n\n```sh\n$ xp test GitHubTestCase\n[.]\n\n✓: 1/1 run (0 skipped), 1 succeeded, 0 failed\nMemory used: 1861.12 kB (2474.66 kB peak)\nTime taken: 1.225 seconds\n```\n\nTo overwrite the default URL specified in the annotation, supply it as command line argument, e.g. `unittest GitHubTestCase -a https://github.staging.lan/`.\n\nAssertion methods\n-----------------\nOn top of the assertion methods provided by the unittest library, the following response-related assertions are available:\n\n```php\npublic void assertStatus(int $status)\npublic void assertUrlEquals(peer.URL $url)\npublic void assertContentType(string $ctype)\npublic void assertHeader(string $header, string $value)\npublic void assertElementPresent(string $id)\npublic void assertTextPresent(string $text)\npublic void assertImagePresent(string $src)\npublic void assertLinkPresent(string $url)\npublic void assertLinkPresentWithText(string $text)\npublic void assertFormPresent(string $name= null)\npublic void assertTitleEquals($title)\n```\n\nNavigation\n----------\nTo follow links inside a page, a web test can utilize the click methods:\n\n```php\nprotected void clickLink(string $id);\nprotected void clickLinkWithText(string $text);\n```\n\nForms\n-----\nTo work with forms, the `getForm()` method can be used:\n\n```php\nuse unittest\\web\\{WebTestCase, Webtest};\nuse unittest\\Test;\n\n#[Webtest(url: 'https://github.com/')]\nclass GitHubTestCase extends WebTestCase {\n\n  #[Test]\n  public function search_for() {\n    $this-\u003ebeginAt('/');\n    $form= $this-\u003egetForm();\n    $form-\u003egetField('q')-\u003esetValue('XP Framework');\n    $form-\u003esubmit();\n    $this-\u003eassertStatus(200);\n    $this-\u003eassertTitleEquals('Search · XP Framework · GitHub');\n  }\n}\n```\n\nSee also\n--------\nhttps://github.com/xp-framework/rfc/issues/169","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Fwebtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-framework%2Fwebtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Fwebtest/lists"}