AppcircleUITests.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // AppcircleUITests.swift
  3. // AppcircleUITests
  4. //
  5. // Created by Mustafa on 29.12.2021.
  6. //
  7. import XCTest
  8. extension XCUIElement {
  9. func clearAndEnterText(_ text: String) {
  10. guard let stringValue = self.value as? String else {
  11. XCTFail("Tried to clear and enter text into a non string value")
  12. return
  13. }
  14. self.tap()
  15. let deleteString = stringValue.map { _ in "\u{8}" }.joined(separator: "")
  16. self.typeText(deleteString)
  17. self.typeText(text)
  18. }
  19. }
  20. class AppcircleUITests: XCTestCase {
  21. override func setUpWithError() throws {
  22. // Put setup code here. This method is called before the invocation of each test method in the class.
  23. // In UI tests it is usually best to stop immediately when a failure occurs.
  24. continueAfterFailure = false
  25. }
  26. override func tearDownWithError() throws {
  27. // Put teardown code here. This method is called after the invocation of each test method in the class.
  28. }
  29. func testFizz() throws {
  30. // UI tests must launch the application that they test.
  31. let app = XCUIApplication()
  32. app.launch()
  33. let numberCell = app.textFields["Enter a number"]
  34. let resultText = app.staticTexts["result"]
  35. numberCell.tap()
  36. numberCell.typeText("3")
  37. XCTAssertEqual(resultText.label,"Fizz")
  38. }
  39. func testBuzz() throws {
  40. // UI tests must launch the application that they test.
  41. let app = XCUIApplication()
  42. app.launch()
  43. let numberCell = app.textFields["Enter a number"]
  44. let resultText = app.staticTexts["result"]
  45. numberCell.tap()
  46. numberCell.clearAndEnterText("15")
  47. XCTAssertEqual(resultText.label,"FizzBuzz")
  48. }
  49. func testOthers() throws {
  50. // UI tests must launch the application that they test.
  51. let app = XCUIApplication()
  52. app.launch()
  53. let numberCell = app.textFields["Enter a number"]
  54. let resultText = app.staticTexts["result"]
  55. numberCell.tap()
  56. numberCell.clearAndEnterText("4")
  57. XCTAssertEqual(resultText.label,"4")
  58. }
  59. func testFail() throws {
  60. // UI tests must launch the application that they test.
  61. let app = XCUIApplication()
  62. app.launch()
  63. let numberCell = app.textFields["Enter a number"]
  64. let resultText = app.staticTexts["result"]
  65. numberCell.tap()
  66. numberCell.clearAndEnterText("7")
  67. XCTAssertEqual(resultText.label,"Fizz")
  68. }
  69. func testDataAttachment() throws {
  70. let app = XCUIApplication()
  71. app.launch()
  72. let text = "Appcircle"
  73. let attachment = XCTAttachment(data: Data(text.utf8))
  74. attachment.lifetime = .keepAlways
  75. add(attachment)
  76. }
  77. func testJsonAttachment() throws {
  78. let app = XCUIApplication()
  79. app.launch()
  80. let json = "{\"hello\":\"world\"}"
  81. let attachment = XCTAttachment(data: Data(json.utf8),uniformTypeIdentifier: "public.json")
  82. attachment.lifetime = .keepAlways
  83. add(attachment)
  84. }
  85. }