comparison SimoleonUITests/SimoleonUITests.swift @ 106:599fe95307f6

Fixes minor bugs
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Wed, 04 Aug 2021 21:33:52 +0100
parents e3e6dfd7fdbf
children 587924519d3b
comparison
equal deleted inserted replaced
105:5c7b675ede8f 106:599fe95307f6
6 // 6 //
7 7
8 import XCTest 8 import XCTest
9 9
10 class SimoleonUITests: XCTestCase { 10 class SimoleonUITests: XCTestCase {
11 var screnshotEndingName = ""
11 12
12 override func setUpWithError() throws { 13 override func setUpWithError() throws {
13 // Put setup code here. This method is called before the invocation of each test method in the class. 14 // Put setup code here. This method is called before the invocation of each test method in the class.
15 if UIDevice.current.userInterfaceIdiom == .pad {
16 XCUIDevice.shared.orientation = .landscapeLeft
17 screnshotEndingName = "-force_landscapeleft"
18 }
19
20 let app = XCUIApplication()
21 setupSnapshot(app)
22 app.launch()
14 23
15 // In UI tests it is usually best to stop immediately when a failure occurs. 24 // In UI tests it is usually best to stop immediately when a failure occurs.
16 continueAfterFailure = false 25 continueAfterFailure = false
17 26
18 // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 27 // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
21 override func tearDownWithError() throws { 30 override func tearDownWithError() throws {
22 // Put teardown code here. This method is called after the invocation of each test method in the class. 31 // Put teardown code here. This method is called after the invocation of each test method in the class.
23 } 32 }
24 33
25 // MARK: - Automate screenshots 34 // MARK: - Automate screenshots
26 func testLaunchScreenshots() { 35 func testLaunch() {
27 let app = XCUIApplication() 36 if UIDevice.current.userInterfaceIdiom == .pad {
28 setupSnapshot(app) 37 XCUIApplication().tables.buttons.firstMatch.tap()
29 app.launch() 38 }
30 snapshot("0-Launch") 39
31 40 snapshot("1Launch\(screnshotEndingName)")
32 // Remove 100 from conversion textfield and type custom amount 41 }
33 let conversionTextfield = app.textFields["ConversionTextfield"] 42
43 func testCurrencySelector() {
44 if UIDevice.current.userInterfaceIdiom == .pad {
45 XCUIApplication().tables.buttons.firstMatch.tap()
46 }
47
48 XCUIApplication().scrollViews.buttons.firstMatch.tap()
49 snapshot("2CurrencySelector\(screnshotEndingName)")
50
51 XCUIApplication().tables.buttons.element(boundBy: 6).tap()
52 let conversionTextfield = XCUIApplication().textFields.firstMatch
34 conversionTextfield.tap() 53 conversionTextfield.tap()
35 for _ in (0..<4) { 54 for _ in (0..<4) {
36 conversionTextfield.typeText(XCUIKeyboardKey.delete.rawValue) 55 conversionTextfield.typeText(XCUIKeyboardKey.delete.rawValue)
37 } 56 }
38 conversionTextfield.typeText("1470.10") 57
39 snapshot("1-Convert") 58 conversionTextfield.typeText("\n")
40 59
41 // Remove custom amount and type again 1000 60 snapshot("3Amount\(screnshotEndingName)")
42 for _ in (0..<7) {
43 conversionTextfield.typeText(XCUIKeyboardKey.delete.rawValue)
44 }
45 conversionTextfield.typeText("1000\n")
46 }
47
48 func testCurrencySelectorScreenshots() throws {
49 let app = XCUIApplication()
50 setupSnapshot(app)
51 app.launch()
52
53 // Open currency selector, search BTC, and select first row
54 app.buttons["CurrencySelector"].tap()
55 snapshot("2-CurrencySelector")
56
57 let searchBar = app.textFields["SearchBar"]
58 searchBar.tap()
59 searchBar.typeText("BTC")
60 app.buttons["CurrencyRow"].firstMatch.tap()
61 snapshot("3-Bitcoin")
62 } 61 }
63 62
64 func testFavorites() throws { 63 func testFavorites() throws {
65 let app = XCUIApplication()
66 setupSnapshot(app)
67 app.launch()
68
69 // Go to favorites 64 // Go to favorites
70 if UIDevice.current.userInterfaceIdiom == .pad { 65 if UIDevice.current.userInterfaceIdiom == .pad {
71 app.navigationBars.buttons.element(boundBy: 0).tap() 66 XCUIApplication().tables.buttons.element(boundBy: 1).tap()
72 app.buttons["Favorites"].tap()
73 } else { 67 } else {
74 app.tabBars.buttons.element(boundBy: 1).tap() 68 XCUIApplication().tabBars.buttons.element(boundBy: 1).tap()
75 } 69 }
76 70
77 snapshot("4-Favorites") 71 snapshot("4Favorites\(screnshotEndingName)")
78 } 72 }
79 73
80 func testLaunchPerformance() throws { 74 // func testLaunchPerformance() throws {
81 if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { 75 // if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
82 // This measures how long it takes to launch your application. 76 // // This measures how long it takes to launch your application.
83 measure(metrics: [XCTApplicationLaunchMetric()]) { 77 // measure(metrics: [XCTApplicationLaunchMetric()]) {
84 XCUIApplication().launch() 78 // XCUIApplication().launch()
85 } 79 // }
86 } 80 // }
87 } 81 // }
88 } 82 }